actv 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. data/.gitignore +30 -0
  2. data/.rspec +2 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/CHANGELOG.md +64 -0
  6. data/Gemfile +4 -0
  7. data/Guardfile +20 -0
  8. data/LICENSE +22 -0
  9. data/README.md +63 -0
  10. data/Rakefile +17 -0
  11. data/actv.gemspec +34 -0
  12. data/lib/actv.rb +48 -0
  13. data/lib/actv/address.rb +9 -0
  14. data/lib/actv/article.rb +89 -0
  15. data/lib/actv/article_search_results.rb +15 -0
  16. data/lib/actv/asset.rb +186 -0
  17. data/lib/actv/asset_channel.rb +13 -0
  18. data/lib/actv/asset_component.rb +8 -0
  19. data/lib/actv/asset_description.rb +15 -0
  20. data/lib/actv/asset_description_type.rb +12 -0
  21. data/lib/actv/asset_image.rb +13 -0
  22. data/lib/actv/asset_legacy_data.rb +20 -0
  23. data/lib/actv/asset_price.rb +11 -0
  24. data/lib/actv/asset_seo_url.rb +5 -0
  25. data/lib/actv/asset_status.rb +17 -0
  26. data/lib/actv/asset_tag.rb +9 -0
  27. data/lib/actv/asset_topic.rb +11 -0
  28. data/lib/actv/base.rb +148 -0
  29. data/lib/actv/channel.rb +13 -0
  30. data/lib/actv/client.rb +330 -0
  31. data/lib/actv/configurable.rb +39 -0
  32. data/lib/actv/default.rb +87 -0
  33. data/lib/actv/error.rb +32 -0
  34. data/lib/actv/error/bad_gateway.rb +11 -0
  35. data/lib/actv/error/bad_request.rb +10 -0
  36. data/lib/actv/error/client_error.rb +39 -0
  37. data/lib/actv/error/enhance_your_calm.rb +10 -0
  38. data/lib/actv/error/forbidden.rb +10 -0
  39. data/lib/actv/error/internal_server_error.rb +11 -0
  40. data/lib/actv/error/not_acceptable.rb +10 -0
  41. data/lib/actv/error/not_found.rb +10 -0
  42. data/lib/actv/error/server_error.rb +19 -0
  43. data/lib/actv/error/service_unavailable.rb +11 -0
  44. data/lib/actv/error/unauthorized.rb +10 -0
  45. data/lib/actv/event.rb +213 -0
  46. data/lib/actv/event_result.rb +8 -0
  47. data/lib/actv/event_search_results.rb +11 -0
  48. data/lib/actv/evergreen.rb +53 -0
  49. data/lib/actv/facet.rb +16 -0
  50. data/lib/actv/facet_term.rb +5 -0
  51. data/lib/actv/facet_value.rb +7 -0
  52. data/lib/actv/identity.rb +28 -0
  53. data/lib/actv/interest.rb +39 -0
  54. data/lib/actv/null_object.rb +19 -0
  55. data/lib/actv/phone_number.rb +9 -0
  56. data/lib/actv/place.rb +24 -0
  57. data/lib/actv/popular_interest.rb +18 -0
  58. data/lib/actv/popular_interest_search_results.rb +12 -0
  59. data/lib/actv/request/multipart_with_file.rb +37 -0
  60. data/lib/actv/response/parse_json.rb +29 -0
  61. data/lib/actv/response/raise_client_error.rb +21 -0
  62. data/lib/actv/response/raise_server_error.rb +18 -0
  63. data/lib/actv/search_results.rb +30 -0
  64. data/lib/actv/sub_event.rb +15 -0
  65. data/lib/actv/tag.rb +9 -0
  66. data/lib/actv/topic.rb +9 -0
  67. data/lib/actv/user.rb +38 -0
  68. data/lib/actv/version.rb +3 -0
  69. data/spec/actv/article_search_results_spec.rb +16 -0
  70. data/spec/actv/article_spec.rb +44 -0
  71. data/spec/actv/asset_channel_spec.rb +17 -0
  72. data/spec/actv/asset_description_spec.rb +17 -0
  73. data/spec/actv/asset_image_spec.rb +27 -0
  74. data/spec/actv/asset_price_spec.rb +23 -0
  75. data/spec/actv/asset_spec.rb +172 -0
  76. data/spec/actv/asset_status_spec.rb +24 -0
  77. data/spec/actv/base_spec.rb +51 -0
  78. data/spec/actv/client/articles_spec.rb +130 -0
  79. data/spec/actv/client/assets_spec.rb +87 -0
  80. data/spec/actv/client/event_results_spec.rb +35 -0
  81. data/spec/actv/client/events_spec.rb +99 -0
  82. data/spec/actv/client/search_spec.rb +58 -0
  83. data/spec/actv/client/system_health_spec.rb +16 -0
  84. data/spec/actv/client/users_spec.rb +31 -0
  85. data/spec/actv/client_spec.rb +140 -0
  86. data/spec/actv/event_spec.rb +331 -0
  87. data/spec/actv/evergreen_spec.rb +33 -0
  88. data/spec/actv/identifiable_spec.rb +31 -0
  89. data/spec/actv/null_object_spec.rb +24 -0
  90. data/spec/actv/place_spec.rb +25 -0
  91. data/spec/actv/search_results_spec.rb +44 -0
  92. data/spec/actv/user_spec.rb +25 -0
  93. data/spec/actv_spec.rb +60 -0
  94. data/spec/faraday/response_spec.rb +0 -0
  95. data/spec/fixtures/me.json +21 -0
  96. data/spec/fixtures/system_health.json +1 -0
  97. data/spec/fixtures/valid_article.json +187 -0
  98. data/spec/fixtures/valid_asset.json +185 -0
  99. data/spec/fixtures/valid_event.json +188 -0
  100. data/spec/fixtures/valid_event_results.json +23 -0
  101. data/spec/fixtures/valid_evergreen.json +1 -0
  102. data/spec/fixtures/valid_evergreen_child_1.json +1 -0
  103. data/spec/fixtures/valid_search.json +1282 -0
  104. data/spec/fixtures/valid_search_no_event_results.json +5 -0
  105. data/spec/fixtures/valid_search_no_results.json +9 -0
  106. data/spec/spec_helper.rb +15 -0
  107. data/spec/support/helper.rb +43 -0
  108. metadata +432 -0
@@ -0,0 +1,140 @@
1
+ require 'spec_helper'
2
+
3
+ describe ACTV::Client do
4
+
5
+ subject do
6
+ client = ACTV::Client.new
7
+ # client.class_eval{public *ACTV::Client.private_instance_methods}
8
+ client
9
+ end
10
+
11
+ context "with module configuration" do
12
+
13
+ before do
14
+ ACTV.configure do |config|
15
+ ACTV::Configurable.keys.each do |key|
16
+ config.send("#{key}=", key)
17
+ end
18
+ end
19
+ end
20
+
21
+ after do
22
+ ACTV.reset!
23
+ end
24
+
25
+ it "inherits the module configuration" do
26
+ client = ACTV::Client.new
27
+ ACTV::Configurable.keys.each do |key|
28
+ client.instance_variable_get("@#{key}").should eq key
29
+ end
30
+ end
31
+
32
+ context "with class configuration" do
33
+
34
+ before do
35
+ @configuration = {
36
+ :connection_options => {:timeout => 10},
37
+ :consumer_key => 'CK',
38
+ :consumer_secret => 'CS',
39
+ :endpoint => 'http://tumblr.com/',
40
+ :media_endpoint => 'http://upload.twitter.com',
41
+ :middleware => Proc.new{},
42
+ :oauth_token => 'OT',
43
+ :oauth_token_secret => 'OS',
44
+ :search_endpoint => 'http://search.twitter.com',
45
+ :api_key => 'TEST'
46
+ }
47
+ end
48
+
49
+ context "during initialization" do
50
+ it "overrides the module configuration" do
51
+ client = ACTV::Client.new(@configuration)
52
+ ACTV::Configurable.keys.each do |key|
53
+ client.instance_variable_get("@#{key}").should eq @configuration[key]
54
+ end
55
+ end
56
+ end
57
+
58
+ context "after initilization" do
59
+ it "overrides the module configuration after initialization" do
60
+ client = ACTV::Client.new
61
+ client.configure do |config|
62
+ @configuration.each do |key, value|
63
+ config.send("#{key}=", value)
64
+ end
65
+ end
66
+ ACTV::Configurable.keys.each do |key|
67
+ client.instance_variable_get("@#{key}").should eq @configuration[key]
68
+ end
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ describe "#credentials?" do
77
+ it "returns true if all credentials are present" do
78
+ client = ACTV::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS')
79
+ client.credentials?.should be_true
80
+ end
81
+ # it "returns false if any credentials are missing" do
82
+ # client = ACTV::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT')
83
+ # client.credentials?.should be_false
84
+ # end
85
+ end
86
+
87
+ describe "#connection" do
88
+ it "looks like Faraday connection" do
89
+ subject.connection.should respond_to(:run_request)
90
+ end
91
+ it "memoizes the connection" do
92
+ c1, c2 = subject.connection, subject.connection
93
+ c1.object_id.should eq c2.object_id
94
+ end
95
+ end
96
+
97
+ describe "#request" do
98
+ before do
99
+ @client = ACTV::Client.new({:consumer_key => "CK", :consumer_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS"})
100
+ end
101
+
102
+ it "does something" do
103
+ stub_request(:get, "https://api.active.com/system_health").
104
+ with(:headers => {'Accept'=>'application/json'}).
105
+ to_return(:status => 200, :body => '{"status":"not implemented"}', :headers => {})
106
+
107
+ @client.request(:get, "/system_health", {}, {})[:body].should eql({status: "not implemented"})
108
+ end
109
+
110
+ it "encodes the entire body when no uploaded media is present" do
111
+ # stub_post("/1/statuses/update.json").
112
+ # with(:body => {:status => "Update"}).
113
+ # to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
114
+ # @client.update("Update")
115
+ # a_post("/1/statuses/update.json").
116
+ # with(:body => {:status => "Update"}).
117
+ # should have_been_made
118
+ end
119
+ # it "encodes none of the body when uploaded media is present" do
120
+ # stub_post("/1/statuses/update_with_media.json", "https://upload.twitter.com").
121
+ # to_return(:body => fixture("status_with_media.json"), :headers => {:content_type => "application/json; charset=utf-8"})
122
+ # @client.update_with_media("Update", fixture("pbjt.gif"))
123
+ # a_post("/1/statuses/update_with_media.json", "https://upload.twitter.com").
124
+ # should have_been_made
125
+ # end
126
+ # it "catches Faraday errors" do
127
+ # subject.stub!(:connection).and_raise(Faraday::Error::ClientError.new("Oups"))
128
+ # lambda do
129
+ # subject.request(:get, "/path", {}, {})
130
+ # end.should raise_error(Twitter::Error::ClientError, "Oups")
131
+ # end
132
+ end
133
+
134
+ ACTV::Configurable::CONFIG_KEYS.each do |key|
135
+ it "has a default #{key.to_s.gsub('_', ' ')}" do
136
+ subject.send(key).should eq ACTV::Default.options[key]
137
+ end
138
+ end
139
+
140
+ end
@@ -0,0 +1,331 @@
1
+ require 'spec_helper'
2
+ require "active_support/time"
3
+
4
+ describe ACTV::Event do
5
+ before do
6
+ stub_get("/v2/assets/valid_event.json").to_return(body: fixture("valid_event.json"), headers: { content_type: "application/json; charset=utf-8" })
7
+ end
8
+
9
+ subject { ACTV.event('valid_event') }
10
+
11
+ def format_date date
12
+ date.strftime('%Y-%m-%dT%H:%M:%S')
13
+ end
14
+
15
+ def format_date_in_utc date
16
+ format_date(date) << ' UTC'
17
+ end
18
+
19
+ # describe "available methods" do
20
+ # subject { ACTV::Event.new(assetGuid: 1) }
21
+ # it { should respond_to :online_registration_available? }
22
+ # it { should respond_to :registration_not_yet_open? }
23
+ # it { should respond_to :registration_open? }
24
+ # it { should respond_to :registration_closed? }
25
+ # it { should respond_to :event_ended? }
26
+ # end
27
+
28
+ describe '#online_registration_available?' do
29
+ context 'when online_registration_available is true' do
30
+ before do
31
+ subject.legacy_data.stub(:onlineRegistration).and_return("true")
32
+ subject.stub(:registrationUrlAdr).and_return("something")
33
+ end
34
+
35
+ its(:online_registration_available?) { should be_true }
36
+ end
37
+
38
+ context "when online_registration_available is not true" do
39
+ before do
40
+ subject.legacy_data.stub(:onlineRegistration).and_return("false")
41
+ subject.stub(:registrationUrlAdr).and_return("something")
42
+ end
43
+
44
+ its(:online_registration_available?) { should be_false }
45
+ end
46
+
47
+ context "when online_registration_available is not present" do
48
+ before do
49
+ subject.legacy_data.stub(:onlineRegistration).and_return(nil)
50
+ end
51
+
52
+ context "when registrationUrlAdr is present" do
53
+ before { subject.stub(:registrationUrlAdr).and_return("something") }
54
+ its(:online_registration_available?) { should be_true }
55
+ end
56
+
57
+ context "when registrationUrlAdr is not present" do
58
+ before { subject.stub(:registrationUrlAdr).and_return(nil) }
59
+ its(:online_registration_available?) { should be_false }
60
+ end
61
+ end
62
+
63
+ context "when legacy_data is not present" do
64
+ before { subject.stub(:legacy_data).and_return(nil) }
65
+
66
+ context "when registrationUrlAdr is present" do
67
+ before { subject.stub(:registrationUrlAdr).and_return("something") }
68
+ its(:online_registration_available?) { should be_true }
69
+ end
70
+
71
+ context "when registrationUrlAdr is not present" do
72
+ before { subject.stub(:registrationUrlAdr).and_return(nil) }
73
+ its(:online_registration_available?) { should be_false }
74
+ end
75
+ end
76
+ end
77
+
78
+ describe '#registration_open_date' do
79
+ before { subject.stub(:sales_start_date).and_return format_date 1.day.from_now }
80
+ it "returns the correct date in the correct timezone" do
81
+ subject.registration_open_date.should be_within(1.second).of Time.parse format_date_in_utc 1.day.from_now
82
+ end
83
+ end
84
+
85
+ describe '#registration_close_date' do
86
+ before { subject.stub(:sales_end_date).and_return format_date 1.day.from_now }
87
+ it "returns the correct date in the correct timezone" do
88
+ subject.registration_close_date.should be_within(1.second).of Time.parse format_date_in_utc 1.day.from_now
89
+ end
90
+ end
91
+
92
+ describe '#event_start_date' do
93
+ before do
94
+ subject.stub(:activity_start_date).and_return("2013-05-10T00:00:00")
95
+ subject.stub(:timezone_offset).and_return(-4)
96
+ end
97
+ it "returns the correct date in the correct timezone" do
98
+ subject.event_start_date.should eq Time.parse "2013-05-10T00:00:00 -0400"
99
+ end
100
+ end
101
+
102
+ describe '#event_end_date' do
103
+ before do
104
+ subject.stub(:activity_end_date).and_return("2013-05-10T00:00:00")
105
+ subject.stub(:timezone_offset).and_return(-4)
106
+ end
107
+ it "returns the correct date in the correct timezone" do
108
+ subject.event_end_date.should eq Time.parse "2013-05-10T00:00:00 -0400"
109
+ end
110
+ end
111
+
112
+ describe '#registration_not_yet_open' do
113
+
114
+ context 'when the event has sales start date' do
115
+ context 'when now is before the date' do
116
+ before do
117
+ subject.stub(:sales_start_date).and_return format_date 1.day.from_now
118
+ subject.stub(:registrationUrlAdr).and_return("something")
119
+ end
120
+ its(:registration_not_yet_open?) { should be_true }
121
+ end
122
+ context 'when now is after the date' do
123
+ before do
124
+ subject.stub(:sales_start_date).and_return format_date 1.day.ago
125
+ end
126
+ its(:registration_not_yet_open?) { should be_false }
127
+ end
128
+ end
129
+ context 'when the event does not have a sales start date' do
130
+ before do
131
+ subject.stub(:sales_start_date).and_return nil
132
+ end
133
+ its(:registration_not_yet_open?) { should be_false }
134
+
135
+ context 'when the event has no dates' do
136
+ before do
137
+ subject.stub(:sales_start_date).and_return nil
138
+ subject.stub(:sales_end_date).and_return nil
139
+ subject.stub(:activity_start_date).and_return nil
140
+ subject.stub(:activity_end_date).and_return nil
141
+ end
142
+ its(:registration_not_yet_open?) { should be_false }
143
+ end
144
+ end
145
+ end
146
+
147
+ describe '#registration_closed' do
148
+
149
+ context 'when the event has sales end date' do
150
+ context 'when now is before the date' do
151
+ before do
152
+ subject.stub(:sales_end_date).and_return format_date 1.day.from_now
153
+ end
154
+ its(:registration_closed?) { should be_false }
155
+ end
156
+ context 'when now is after the date' do
157
+ before do
158
+ subject.stub(:sales_end_date).and_return format_date 1.day.ago
159
+ subject.stub(:registrationUrlAdr).and_return("something")
160
+ end
161
+ its(:registration_closed?) { should be_true }
162
+ end
163
+ end
164
+ context 'when the event does not have a sales end date' do
165
+ before do
166
+ subject.stub(:sales_end_date).and_return nil
167
+ end
168
+ context 'when the event has an activity end date' do
169
+ context 'when now is before the date' do
170
+ before do
171
+ subject.stub(:activity_end_date).and_return format_date 1.day.from_now
172
+ end
173
+ its(:registration_closed?) { should be_false }
174
+ end
175
+ context 'when now is after the date' do
176
+ before do
177
+ subject.stub(:activity_end_date).and_return format_date 1.day.ago
178
+ subject.stub(:registrationUrlAdr).and_return("something")
179
+ end
180
+ its(:registration_closed?) { should be_true }
181
+ end
182
+ end
183
+ context 'when the event has no dates' do
184
+ before do
185
+ subject.stub(:sales_start_date).and_return nil
186
+ subject.stub(:sales_end_date).and_return nil
187
+ subject.stub(:activity_start_date).and_return nil
188
+ subject.stub(:activity_end_date).and_return nil
189
+ end
190
+ its(:registration_closed?) { should be_false }
191
+ end
192
+ end
193
+ end
194
+
195
+ describe '#registration_open' do
196
+ subject { ACTV.event('valid_event') }
197
+
198
+ context 'when the event is unregisterable' do
199
+ before do
200
+ subject.stub(:online_registration_available?).and_return false
201
+ end
202
+ its(:registration_open?) { should be_false }
203
+ end
204
+
205
+ context 'when the event has sales start and end dates' do
206
+ context 'when now is between start and end dates' do
207
+ before do
208
+ subject.stub(:sales_start_date).and_return format_date 1.day.ago
209
+ subject.stub(:sales_end_date).and_return format_date 1.day.from_now
210
+ subject.stub(:registrationUrlAdr).and_return("something")
211
+ end
212
+ its(:registration_open?) { should be_true }
213
+ end
214
+
215
+ context 'when now is before start' do
216
+ before do
217
+ subject.stub(:sales_start_date).and_return format_date 1.day.from_now
218
+ subject.stub(:sales_end_date).and_return format_date 2.days.from_now
219
+ end
220
+ its(:registration_open?) { should be_false }
221
+ end
222
+
223
+ context 'when now is after end' do
224
+ before do
225
+ subject.stub(:sales_start_date).and_return format_date 2.days.ago
226
+ subject.stub(:sales_end_date).and_return format_date 1.day.ago
227
+ end
228
+ its(:registration_open?) { should be_false }
229
+ end
230
+ end
231
+
232
+ context 'when the event does not have sales start and end dates' do
233
+ before do
234
+ subject.stub(:sales_start_date).and_return nil
235
+ subject.stub(:sales_end_date).and_return nil
236
+ end
237
+ context 'when the event has activity start and end dates' do
238
+ before do
239
+ subject.stub(:activity_start_date).and_return format_date 2.days.ago
240
+ subject.stub(:activity_end_date).and_return format_date 2.days.from_now
241
+ end
242
+ context 'when now is between start and end dates' do
243
+ before do
244
+ subject.stub(:activity_start_date).and_return format_date 2.days.ago
245
+ subject.stub(:activity_end_date).and_return format_date 2.days.from_now
246
+ subject.stub(:registrationUrlAdr).and_return("something")
247
+ end
248
+ its(:registration_open?) { should be_true }
249
+ end
250
+ context 'when now is after end' do
251
+ before do
252
+ subject.stub(:activity_start_date).and_return format_date 3.days.ago
253
+ subject.stub(:activity_end_date).and_return format_date 2.days.ago
254
+ end
255
+ its(:registration_open?) { should be_false }
256
+ end
257
+ end
258
+ context 'when the event does not have activity start and end dates' do
259
+ before do
260
+ subject.stub(:activity_start_date).and_return nil
261
+ subject.stub(:activity_end_date).and_return nil
262
+ subject.stub(:registrationUrlAdr).and_return("something")
263
+ end
264
+ its(:registration_open?) { should be_true } # Huiwen says this is correct
265
+ end
266
+ end
267
+ end
268
+
269
+ describe "Fixes for LH bugs" do
270
+ describe "LH-925" do
271
+ context "when the sales dates are not available" do
272
+ before do
273
+ subject.stub(:sales_start_date).and_return nil
274
+ subject.stub(:sales_end_date).and_return nil
275
+ end
276
+ context "when the activity start and end date are the same" do
277
+ before do
278
+ subject.stub(:activity_start_date).and_return format_date 1.month.ago
279
+ subject.stub(:activity_end_date).and_return format_date Date.today
280
+ subject.stub(:registrationUrlAdr).and_return("something")
281
+ end
282
+ its(:event_ended?) { should be_false }
283
+ its(:registration_open?) { should be_true }
284
+ end
285
+ end
286
+ end
287
+
288
+ describe "LH-906" do
289
+ context 'when the sales_start_date is nil, sales_end_date is in the past and today is between activity start and end' do
290
+ before do
291
+ subject.stub(:sales_start_date).and_return nil
292
+ subject.stub(:sales_end_date).and_return format_date 2.days.ago
293
+ subject.stub(:activity_start_date).and_return format_date 1.day.ago
294
+ subject.stub(:activity_end_date).and_return format_date 1.day.from_now
295
+ subject.stub(:registrationUrlAdr).and_return("something")
296
+ end
297
+ its(:registration_not_yet_open?) { should be_false }
298
+ its(:registration_open?) { should be_false }
299
+ its(:registration_closed?) { should be_true }
300
+ end
301
+ end
302
+ end
303
+
304
+ describe '#disply_close_date' do
305
+ context 'when tag is not set' do
306
+ before do
307
+ subject.stub(:tag_by_description).with("displayclosedate").and_return nil
308
+ end
309
+
310
+ its(:display_close_date?) { should eq true }
311
+ end
312
+
313
+ context 'when tag is set' do
314
+ context 'when true' do
315
+ before do
316
+ subject.stub(:tag_by_description).with("displayclosedate").and_return 'true'
317
+ end
318
+
319
+ its(:display_close_date?) { should eq true }
320
+ end
321
+
322
+ context 'when false' do
323
+ before do
324
+ subject.stub(:tag_by_description).with("displayclosedate").and_return 'false'
325
+ end
326
+
327
+ its(:display_close_date?) { should eq false }
328
+ end
329
+ end
330
+ end
331
+ end