full_circle 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +4 -0
  4. data/Guardfile +24 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +45 -0
  7. data/Rakefile +6 -0
  8. data/full_circle.gemspec +29 -0
  9. data/lib/full_circle/api.rb +34 -0
  10. data/lib/full_circle/connection.rb +18 -0
  11. data/lib/full_circle/object_builder.rb +31 -0
  12. data/lib/full_circle/response_parser.rb +44 -0
  13. data/lib/full_circle/version.rb +3 -0
  14. data/lib/full_circle.rb +12 -0
  15. data/spec/fixtures/vcr_cassettes/empty_event_area_response.yml +47 -0
  16. data/spec/fixtures/vcr_cassettes/empty_get_coupons_response.yml +47 -0
  17. data/spec/fixtures/vcr_cassettes/empty_get_events_response.yml +47 -0
  18. data/spec/fixtures/vcr_cassettes/empty_get_upcoming_events_response.yml +48 -0
  19. data/spec/fixtures/vcr_cassettes/multiple_event_areas_response.yml +51 -0
  20. data/spec/fixtures/vcr_cassettes/multiple_get_coupons_response.yml +60 -0
  21. data/spec/fixtures/vcr_cassettes/multiple_get_upcoming_events_response.yml +277 -0
  22. data/spec/fixtures/vcr_cassettes/multple_get_events_response.yml +96 -0
  23. data/spec/fixtures/vcr_cassettes/single_event_areas_response.yml +49 -0
  24. data/spec/fixtures/vcr_cassettes/single_get_coupons_response.yml +51 -0
  25. data/spec/fixtures/vcr_cassettes/single_get_events_response.yml +52 -0
  26. data/spec/fixtures/vcr_cassettes/single_get_upcoming_events_response.yml +61 -0
  27. data/spec/full_circle/api_spec.rb +170 -0
  28. data/spec/full_circle/connection_spec.rb +21 -0
  29. data/spec/full_circle/object_builder_spec.rb +21 -0
  30. data/spec/full_circle/response_parser_spec.rb +187 -0
  31. data/spec/spec_helper.rb +11 -0
  32. metadata +202 -0
@@ -0,0 +1,170 @@
1
+ require 'spec_helper'
2
+ require 'vcr'
3
+
4
+ describe FullCircle::API do
5
+
6
+ let!(:api){FullCircle::API.new(FullCircle::Connection.new("360durango.com"))}
7
+
8
+ describe "#fetch_events_for_ad" do
9
+ it "calls the appropriate method on call_api_method" do
10
+ mock_connection = double()
11
+ mock_connection.should_receive(:call_api_method).with("ad.getEvents",{adId: "1"})
12
+
13
+ described_class.new(mock_connection).fetch_events_for_ad("1")
14
+ end
15
+
16
+ context "with one event" do
17
+ it "returns an array of one event" do
18
+ VCR.use_cassette "single_get_events_response" do
19
+ results = api.fetch_events_for_ad "81213"
20
+ results.should be_a Array
21
+ results
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ context "with multiple events" do
28
+ it "returns an array of multiple events" do
29
+ VCR.use_cassette "multple_get_events_response" do
30
+ results = api.fetch_events_for_ad "89690"
31
+ results.should be_a Array
32
+ (results.length > 1).should be_true
33
+ end
34
+ end
35
+ end
36
+
37
+ context "with no events" do
38
+ it "returns an empty array" do
39
+ VCR.use_cassette "empty_get_events_response" do
40
+ results = api.fetch_events_for_ad "1"
41
+ results.should eq []
42
+ end
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+
49
+ describe "#fetch_coupons_for_ad" do
50
+
51
+ it "calls the appropriate method on call_api_method" do
52
+ mock_connection = double()
53
+ mock_connection.should_receive(:call_api_method).with("ad.getCoupons",{adId: "1"})
54
+
55
+ described_class.new(mock_connection).fetch_coupons_for_ad("1")
56
+ end
57
+
58
+ context "with one coupon" do
59
+ it "returns an array of one coupon" do
60
+ VCR.use_cassette "single_get_coupons_response" do
61
+ results = api.fetch_coupons_for_ad "123094"
62
+ results.should be_a Array
63
+ results.length.should eq 1
64
+ end
65
+ end
66
+ end
67
+
68
+ context "with multiple coupons" do
69
+ it "returns an array of multiple coupons" do
70
+ VCR.use_cassette "multiple_get_coupons_response" do
71
+ results = api.fetch_coupons_for_ad "82196"
72
+ results.should be_a Array
73
+ results.length.should eq 3
74
+ end
75
+ end
76
+ end
77
+
78
+ context "with no coupons" do
79
+ it "returns an empty array" do
80
+ VCR.use_cassette "empty_get_coupons_response" do
81
+ results = api.fetch_coupons_for_ad "1"
82
+ results.should eq []
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ describe "#fetch_event_areas" do
89
+ it "calls the appropriate method on call_api_method" do
90
+ mock_connection = double()
91
+ mock_connection.should_receive(:call_api_method).with("city.getEventAreas")
92
+
93
+ described_class.new(mock_connection).fetch_event_areas
94
+ end
95
+
96
+ context "with one event area" do
97
+ it "returns an array of one event area" do
98
+ VCR.use_cassette "single_event_areas_response" do
99
+ results = api.fetch_event_areas
100
+ results.should be_a Array
101
+ results.length.should eq 1
102
+ end
103
+ end
104
+ end
105
+
106
+ context "with multiple event areas" do
107
+ it "returns an array of multiple event areas" do
108
+ VCR.use_cassette "multiple_event_areas_response" do
109
+ results = api.fetch_event_areas
110
+ results.should be_a Array
111
+ results.length.should eq 7
112
+ end
113
+ end
114
+ end
115
+
116
+ context "with no event areas" do
117
+ let!(:api){FullCircle::API.new(FullCircle::Connection.new("1019thewave.com"))}
118
+ it "returns an empty array" do
119
+ VCR.use_cassette "empty_event_area_response" do
120
+ results = api.fetch_event_areas
121
+ results.should eq []
122
+ end
123
+ end
124
+ end
125
+
126
+ end
127
+
128
+ describe "#fetch_upcoming_events" do
129
+
130
+ it "calls the appropriate method on call_api_method" do
131
+ mock_connection = double()
132
+ mock_connection.should_receive(:call_api_method).with("city.getUpcomingEvents",{})
133
+
134
+ described_class.new(mock_connection).fetch_upcoming_events
135
+ end
136
+
137
+ context "with one event" do
138
+ it "returns an array of one event" do
139
+ VCR.use_cassette "single_get_upcoming_events_response" do
140
+ results = api.fetch_upcoming_events areaId: "592"
141
+ results.should be_a Array
142
+ results.length.should be 1
143
+ end
144
+ end
145
+
146
+ end
147
+
148
+ context "with multiple events" do
149
+ it "returns an array of multiple events" do
150
+ VCR.use_cassette "multiple_get_upcoming_events_response" do
151
+ results = api.fetch_upcoming_events
152
+ results.should be_a Array
153
+ (results.length > 1).should be_true
154
+ end
155
+ end
156
+ end
157
+
158
+ context "with no events" do
159
+ let!(:api){FullCircle::API.new(FullCircle::Connection.new("boatersbluepages.com"))}
160
+ it "returns an empty array" do
161
+ VCR.use_cassette "empty_get_upcoming_events_response" do
162
+ results = api.fetch_upcoming_events
163
+ results.should eq []
164
+ end
165
+ end
166
+ end
167
+
168
+ end
169
+
170
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe FullCircle::Connection do
4
+
5
+ subject {FullCircle::Connection.new "360durango.com"}
6
+
7
+ its(:domain) {should == "360durango.com"}
8
+ its(:base_uri) {should == "http://api.360durango.com/1.0/"}
9
+
10
+ describe ".call_api_method" do
11
+ it "should call HTTParty.get with the correct arguments" do
12
+ HTTParty.should_receive(:get).with("ad.getCoupons",base_uri: subject.base_uri, query: {adId: "81304"})
13
+
14
+ subject.call_api_method "ad.getCoupons", adId: "81304"
15
+ end
16
+
17
+
18
+ end
19
+
20
+
21
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe FullCircle::ObjectBuilder do
4
+
5
+ describe "#from_api_hash" do
6
+ let(:builder) { described_class.new}
7
+
8
+ it "builds a new event with the appropriate attribute set" do
9
+ object = builder.from_api_hash("id" => "123", "title" => "Hello World")
10
+ object.id.should eq "123"
11
+ object.title.should eq "Hello World"
12
+ end
13
+
14
+ it "builds a new event with camelcased attributes converted to underscored attributes" do
15
+ object = builder.from_api_hash("linkUrl" => "http://www.google.com", "siteId" => "77")
16
+ object.link_url.should eq "http://www.google.com"
17
+ object.site_id.should eq "77"
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,187 @@
1
+ require "spec_helper"
2
+
3
+ describe FullCircle::ResponseParser do
4
+
5
+ describe "#parse" do
6
+
7
+
8
+ context "parsing coupons" do
9
+
10
+ let(:parser) {described_class.new "ad.getCoupons","coupon"}
11
+
12
+ context "with one coupon" do
13
+ it "returns an array of one coupon" do
14
+ response_double = double("response")
15
+ response_double.stub(:parsed_response) do
16
+ {"ad_getCouponsResponse" => {"coupons" => {"coupon" =>
17
+ {"id" => "58794", :name => "Early Bird Discount"}
18
+ }}}
19
+ end
20
+
21
+
22
+ results = parser.parse response_double
23
+
24
+ results.should be_a Array
25
+ results.length.should == 1
26
+ coupon = results.first
27
+ coupon.id.should eq "58794"
28
+ coupon.name.should eq "Early Bird Discount"
29
+
30
+ #TODO Test command message is sent to object builder
31
+
32
+ end
33
+ end
34
+
35
+ context "with multiple coupons" do
36
+ it "returns an array of multiple coupons" do
37
+ response_double = double("response")
38
+ response_double.stub(:parsed_response) do
39
+ {"ad_getCouponsResponse" => {"coupons" => {"coupon" =>[
40
+ {"id" => "58794", :name => "TWO FOR ONE ENTREES"},
41
+ {"id" => "12345", :name => "Three FOR ONE ENTREES"}
42
+ ]}}}
43
+ end
44
+
45
+ results = parser.parse response_double
46
+
47
+ results.should be_a Array
48
+ results.length.should == 2
49
+ end
50
+ end
51
+
52
+ context "with no coupons" do
53
+ it "returns an empty array" do
54
+ response_double = double("response")
55
+ response_double.stub(:parsed_response) do
56
+ {"ad_getCouponsResponse" => {"coupons" => nil}}
57
+ end
58
+
59
+ results = parser.parse response_double
60
+
61
+ results.should eq []
62
+ end
63
+ end
64
+ end
65
+
66
+ context "parsing events" do
67
+
68
+ let(:parser) {described_class.new "ad.getEvents","event"}
69
+
70
+ context "with one event" do
71
+
72
+ it "returns an array of one event" do
73
+ response_double = double("response")
74
+ response_double.stub(:parsed_response) do
75
+ {"ad_getEventsResponse" => {"events" => {"event" =>
76
+ {"id" => "58794", :title => "TWO FOR ONE ENTREES"}
77
+ }}}
78
+ end
79
+
80
+
81
+ results = parser.parse response_double
82
+
83
+ results.should be_a Array
84
+ results.length.should == 1
85
+
86
+ end
87
+
88
+ end
89
+
90
+ context "with multiple events" do
91
+
92
+ it "returns an array of multiple events" do
93
+ response_double = double("response")
94
+ response_double.stub(:parsed_response) do
95
+ {"ad_getEventsResponse" => {"events" => {"event" =>[
96
+ {"id" => "58794", :title => "TWO FOR ONE ENTREES"},
97
+ {"id" => "12345", :title => "Three FOR ONE ENTREES"}
98
+ ]}}}
99
+ end
100
+
101
+ results = parser.parse response_double
102
+
103
+ results.should be_a Array
104
+ results.length.should == 2
105
+ end
106
+
107
+ end
108
+
109
+ context "with no events" do
110
+ it "returns an emtpy array" do
111
+
112
+ response_double = double("response")
113
+ response_double.stub(:parsed_response) do
114
+ {"ad_getEventsResponse" => {"events" => nil}}
115
+ end
116
+
117
+ results = parser.parse response_double
118
+
119
+ results.should eq []
120
+ end
121
+ end
122
+
123
+ end
124
+
125
+ context "parsing event areas" do
126
+
127
+ let(:parser) {described_class.new "city.getEventAreas","eventArea"}
128
+
129
+ context "with one event areas" do
130
+
131
+ it "returns an array of one event area" do
132
+ response_double = double("response")
133
+ response_double.stub(:parsed_response) do
134
+ {"city_getEventAreasResponse" => {"eventAreas" => {"eventArea" =>
135
+ {"id" => "736", :title => "Bayfield"}
136
+ }}}
137
+ end
138
+
139
+
140
+ results = parser.parse response_double
141
+
142
+ results.should be_a Array
143
+ results.length.should == 1
144
+
145
+
146
+ end
147
+
148
+ end
149
+
150
+ context "with multiple event areas" do
151
+
152
+ it "returns an array of multiple event areas" do
153
+ response_double = double("response")
154
+ response_double.stub(:parsed_response) do
155
+ {"city_getEventAreasResponse" => {"eventAreas" => {"eventArea" =>[
156
+ {"id" => "58794", :title => "Bayfield"},
157
+ {"id" => "12345", :title => "Vallecito"}
158
+ ]}}}
159
+ end
160
+
161
+ results = parser.parse response_double
162
+
163
+ results.should be_a Array
164
+ results.length.should == 2
165
+ end
166
+
167
+ end
168
+
169
+ context "with no event areas" do
170
+ it "returns an emtpy array" do
171
+
172
+ response_double = double("response")
173
+ response_double.stub(:parsed_response) do
174
+ {"city_getEventAreasResponse" => {"eventAreas" => nil}}
175
+ end
176
+
177
+ results = parser.parse response_double
178
+
179
+ results.should eq []
180
+ end
181
+ end
182
+
183
+ end
184
+
185
+ end
186
+
187
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: UTF-8
2
+ $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'rspec'
5
+ require 'vcr'
6
+ require 'full_circle'
7
+
8
+ VCR.configure do |c|
9
+ c.cassette_library_dir = "spec/fixtures/vcr_cassettes"
10
+ c.hook_into :webmock
11
+ end
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: full_circle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Renner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 3.2.12
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.12
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.8.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.8.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rb-inotify
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '0.9'
125
+ description: Library for interfacing with the 360Directories API
126
+ email:
127
+ - aaron@animascodelabs.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - Gemfile
134
+ - Guardfile
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - full_circle.gemspec
139
+ - lib/full_circle.rb
140
+ - lib/full_circle/api.rb
141
+ - lib/full_circle/connection.rb
142
+ - lib/full_circle/object_builder.rb
143
+ - lib/full_circle/response_parser.rb
144
+ - lib/full_circle/version.rb
145
+ - spec/fixtures/vcr_cassettes/empty_event_area_response.yml
146
+ - spec/fixtures/vcr_cassettes/empty_get_coupons_response.yml
147
+ - spec/fixtures/vcr_cassettes/empty_get_events_response.yml
148
+ - spec/fixtures/vcr_cassettes/empty_get_upcoming_events_response.yml
149
+ - spec/fixtures/vcr_cassettes/multiple_event_areas_response.yml
150
+ - spec/fixtures/vcr_cassettes/multiple_get_coupons_response.yml
151
+ - spec/fixtures/vcr_cassettes/multiple_get_upcoming_events_response.yml
152
+ - spec/fixtures/vcr_cassettes/multple_get_events_response.yml
153
+ - spec/fixtures/vcr_cassettes/single_event_areas_response.yml
154
+ - spec/fixtures/vcr_cassettes/single_get_coupons_response.yml
155
+ - spec/fixtures/vcr_cassettes/single_get_events_response.yml
156
+ - spec/fixtures/vcr_cassettes/single_get_upcoming_events_response.yml
157
+ - spec/full_circle/api_spec.rb
158
+ - spec/full_circle/connection_spec.rb
159
+ - spec/full_circle/object_builder_spec.rb
160
+ - spec/full_circle/response_parser_spec.rb
161
+ - spec/spec_helper.rb
162
+ homepage: https://github.com/aaronrenner/full_circle
163
+ licenses: []
164
+ metadata: {}
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: 1.9.2
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ! '>='
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubyforge_project:
181
+ rubygems_version: 2.0.3
182
+ signing_key:
183
+ specification_version: 4
184
+ summary: Library for interfacing with the 360Directories API
185
+ test_files:
186
+ - spec/fixtures/vcr_cassettes/empty_event_area_response.yml
187
+ - spec/fixtures/vcr_cassettes/empty_get_coupons_response.yml
188
+ - spec/fixtures/vcr_cassettes/empty_get_events_response.yml
189
+ - spec/fixtures/vcr_cassettes/empty_get_upcoming_events_response.yml
190
+ - spec/fixtures/vcr_cassettes/multiple_event_areas_response.yml
191
+ - spec/fixtures/vcr_cassettes/multiple_get_coupons_response.yml
192
+ - spec/fixtures/vcr_cassettes/multiple_get_upcoming_events_response.yml
193
+ - spec/fixtures/vcr_cassettes/multple_get_events_response.yml
194
+ - spec/fixtures/vcr_cassettes/single_event_areas_response.yml
195
+ - spec/fixtures/vcr_cassettes/single_get_coupons_response.yml
196
+ - spec/fixtures/vcr_cassettes/single_get_events_response.yml
197
+ - spec/fixtures/vcr_cassettes/single_get_upcoming_events_response.yml
198
+ - spec/full_circle/api_spec.rb
199
+ - spec/full_circle/connection_spec.rb
200
+ - spec/full_circle/object_builder_spec.rb
201
+ - spec/full_circle/response_parser_spec.rb
202
+ - spec/spec_helper.rb