actv 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/actv.gemspec +1 -0
- data/lib/actv/asset.rb +23 -12
- data/lib/actv/asset_topic.rb +4 -0
- data/lib/actv/client.rb +11 -8
- data/lib/actv/version.rb +1 -1
- data/spec/actv/asset_spec.rb +92 -74
- data/spec/actv/asset_topic_spec.rb +18 -0
- data/spec/actv/client/assets_spec.rb +3 -3
- data/spec/actv/client/event_results_spec.rb +1 -1
- data/spec/actv/client_spec.rb +14 -0
- data/spec/actv_spec.rb +3 -3
- data/spec/fixtures/valid_assets.json +839 -0
- metadata +82 -29
- checksums.yaml +0 -7
data/README.md
CHANGED
data/actv.gemspec
CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.add_development_dependency 'pry'
|
12
12
|
gem.add_development_dependency 'rake'
|
13
13
|
gem.add_development_dependency 'rspec', '~> 2.14.1'
|
14
|
+
gem.add_development_dependency 'rspec-core'
|
14
15
|
gem.add_development_dependency 'simplecov'
|
15
16
|
gem.add_development_dependency 'timecop'
|
16
17
|
gem.add_development_dependency 'webmock'
|
data/lib/actv/asset.rb
CHANGED
@@ -132,7 +132,7 @@ module ACTV
|
|
132
132
|
def topics
|
133
133
|
@asset_topics ||= Array(@attrs[:assetTopics]).map do |topic|
|
134
134
|
ACTV::AssetTopic.new(topic)
|
135
|
-
end
|
135
|
+
end.sort
|
136
136
|
end
|
137
137
|
alias asset_topics topics
|
138
138
|
alias assetTopics topics
|
@@ -191,10 +191,7 @@ module ACTV
|
|
191
191
|
end
|
192
192
|
else
|
193
193
|
# no categories so check the sourceSystem
|
194
|
-
|
195
|
-
if self.sourceSystem.fetch(:legacyGuid, "").upcase == "CA4EA0B1-7377-470D-B20D-BF6BEA23F040"
|
196
|
-
is_article = true
|
197
|
-
end
|
194
|
+
is_article = articles_source?
|
198
195
|
end
|
199
196
|
|
200
197
|
is_article
|
@@ -242,12 +239,7 @@ module ACTV
|
|
242
239
|
|
243
240
|
def kids?
|
244
241
|
return false if Rails.env == 'production'
|
245
|
-
|
246
|
-
end
|
247
|
-
|
248
|
-
def kidsinterest?
|
249
|
-
interests = meta_interests.to_a.map(&:downcase)
|
250
|
-
['kids', 'family'].any? { |tag| interests.include? tag }
|
242
|
+
kids_friendly_source_system? && kids_interest?
|
251
243
|
end
|
252
244
|
|
253
245
|
def registration_status
|
@@ -296,6 +288,10 @@ module ACTV
|
|
296
288
|
urlize first_topic
|
297
289
|
end
|
298
290
|
|
291
|
+
def first_topic_name
|
292
|
+
topics.first.topic.name
|
293
|
+
end
|
294
|
+
|
299
295
|
def sub_topic
|
300
296
|
get_first_topic_taxonomy[1]
|
301
297
|
end
|
@@ -372,7 +368,7 @@ module ACTV
|
|
372
368
|
end
|
373
369
|
|
374
370
|
def get_first_topic_taxonomy
|
375
|
-
@first_topic_taxonomy ||= assetTopics.
|
371
|
+
@first_topic_taxonomy ||= assetTopics.first
|
376
372
|
if @first_topic_taxonomy
|
377
373
|
@first_topic_taxonomy.topic.topicTaxonomy.split '/'
|
378
374
|
else
|
@@ -388,5 +384,20 @@ module ACTV
|
|
388
384
|
end
|
389
385
|
end
|
390
386
|
|
387
|
+
private
|
388
|
+
def kids_interest?
|
389
|
+
interests = meta_interests.to_a.map(&:downcase)
|
390
|
+
['kids', 'family'].any? { |tag| interests.include? tag }
|
391
|
+
end
|
392
|
+
|
393
|
+
def kids_friendly_source_system?
|
394
|
+
activenet? || awcamps? || awcamps30? || articles_source?
|
395
|
+
end
|
396
|
+
|
397
|
+
def articles_source?
|
398
|
+
# this guid is equal to the Active.com Articles
|
399
|
+
self.sourceSystem.fetch(:legacyGuid, "").upcase == "CA4EA0B1-7377-470D-B20D-BF6BEA23F040"
|
400
|
+
end
|
401
|
+
|
391
402
|
end
|
392
403
|
end
|
data/lib/actv/asset_topic.rb
CHANGED
data/lib/actv/client.rb
CHANGED
@@ -74,12 +74,9 @@ module ACTV
|
|
74
74
|
end
|
75
75
|
|
76
76
|
if response[:body].is_a? Array
|
77
|
-
|
78
|
-
|
79
|
-
results << ACTV::Asset.from_response({body: item})
|
77
|
+
response[:body].map do |item|
|
78
|
+
ACTV::Asset.from_response body: item
|
80
79
|
end
|
81
|
-
|
82
|
-
results
|
83
80
|
else
|
84
81
|
[ACTV::Asset.from_response(response)]
|
85
82
|
end
|
@@ -166,9 +163,15 @@ module ACTV
|
|
166
163
|
|
167
164
|
response = get("#{request_string}.json", params)
|
168
165
|
|
169
|
-
|
170
|
-
|
171
|
-
|
166
|
+
if response[:body].is_a? Array
|
167
|
+
response[:body].map do |item|
|
168
|
+
ACTV::Event.from_response body: item
|
169
|
+
end
|
170
|
+
else
|
171
|
+
event = ACTV::Event.from_response(response)
|
172
|
+
event = ACTV::Evergreen.new(event) if event.evergreen?
|
173
|
+
event.is_article? ? nil : event
|
174
|
+
end
|
172
175
|
end
|
173
176
|
|
174
177
|
# Returns popular assets that match a specified query.
|
data/lib/actv/version.rb
CHANGED
data/spec/actv/asset_spec.rb
CHANGED
@@ -82,13 +82,13 @@ describe ACTV::Asset do
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
describe "#legacy_data" do
|
86
|
+
it "returns a Asset Legacy Data when assetLegacyData is set" do
|
87
|
+
legacy_data = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1", assetLegacyData: { assetTypeId: 1, typeName: "Legacy Data", isSearchable: true }).legacy_data
|
88
|
+
legacy_data.should be_a ACTV::AssetLegacyData
|
89
|
+
end
|
90
90
|
|
91
|
-
|
91
|
+
it "returns nil when assetLegacyData is not set" do
|
92
92
|
legacy_data = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1").legacy_data
|
93
93
|
legacy_data.should be_nil
|
94
94
|
end
|
@@ -162,11 +162,16 @@ describe ACTV::Asset do
|
|
162
162
|
topics.should be_a Array
|
163
163
|
topics.should eq []
|
164
164
|
end
|
165
|
+
|
166
|
+
it "returns an Array of Assets that are sorted by sequence" do
|
167
|
+
topics = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1", assetTopics: [{ sequence: "2", topic: { topicId: "28", topicName: "Triathlon" } }, { sequence: "1", topic: { topicId: "27", topicName: "Running" } }]).topics
|
168
|
+
topics.first.sequence.should eq "1"
|
169
|
+
end
|
165
170
|
end
|
166
171
|
|
167
172
|
describe "is_article?" do
|
168
173
|
before(:each) do
|
169
|
-
|
174
|
+
stub_post("/v2/assets.json").with(:body => {"id"=>"valid_article"}).
|
170
175
|
to_return(body: fixture("valid_article.json"), headers: { content_type: "application/json; charset=utf-8" })
|
171
176
|
end
|
172
177
|
|
@@ -182,7 +187,7 @@ describe ACTV::Asset do
|
|
182
187
|
end
|
183
188
|
|
184
189
|
it "should return false if no assetCategory of Article" do
|
185
|
-
|
190
|
+
stub_post("/v2/assets.json").with(:body => {"id"=>"valid_event"}).
|
186
191
|
to_return(body: fixture("valid_event.json"), headers: { content_type: "application/json; charset=utf-8" })
|
187
192
|
|
188
193
|
asset = ACTV.asset('valid_event')[0]
|
@@ -202,99 +207,105 @@ describe ACTV::Asset do
|
|
202
207
|
|
203
208
|
describe "#kids?" do
|
204
209
|
let(:asset) { ACTV::Asset.new assetGuid: 1 }
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
"development"
|
211
|
-
end
|
210
|
+
|
211
|
+
before do
|
212
|
+
class Rails
|
213
|
+
def self.env
|
214
|
+
"development"
|
212
215
|
end
|
213
216
|
end
|
217
|
+
end
|
214
218
|
|
215
|
-
|
216
|
-
|
219
|
+
context "when kids_friendly_source_system? is true" do
|
220
|
+
context "by stubbing kids_friendly_source_system?" do
|
221
|
+
before { asset.stub kids_friendly_source_system?: true }
|
217
222
|
|
218
|
-
context 'when
|
219
|
-
before
|
220
|
-
|
221
|
-
|
222
|
-
end
|
223
|
-
it "evaluates to true" do
|
223
|
+
context 'when kids_interest? is true' do
|
224
|
+
before { asset.stub kids_interest?: true }
|
225
|
+
|
226
|
+
it 'evaluates to true' do
|
224
227
|
asset.kids?.should eq true
|
225
228
|
end
|
226
229
|
end
|
227
230
|
|
228
|
-
context 'when
|
229
|
-
before
|
230
|
-
|
231
|
-
|
231
|
+
context 'when kids_interest? is false' do
|
232
|
+
before { asset.stub kids_interest?: false }
|
233
|
+
|
234
|
+
it 'evaluates to false' do
|
235
|
+
asset.kids?.should eq false
|
232
236
|
end
|
233
|
-
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
context "and activenet? returns true" do
|
241
|
+
let(:asset) { ACTV::Asset.new assetGuid: 1, sourceSystem: {legacyGuid: "FB27C928-54DB-4ECD-B42F-482FC3C8681F"} }
|
242
|
+
|
243
|
+
context 'and kids_interest? is true' do
|
244
|
+
before { asset.stub kids_interest?: true }
|
245
|
+
|
246
|
+
it 'evaluates to true' do
|
234
247
|
asset.kids?.should eq true
|
235
248
|
end
|
236
249
|
end
|
237
250
|
end
|
238
251
|
|
239
|
-
context
|
240
|
-
|
252
|
+
context "and awcamps? returns true" do
|
253
|
+
let(:asset) { ACTV::Asset.new assetGuid: 1, sourceSystem: {legacyGuid: "2B22B4E6-5AA4-44D7-BF06-F7A71F9FA8A6"} }
|
241
254
|
|
242
|
-
context '
|
243
|
-
before
|
244
|
-
|
245
|
-
|
246
|
-
end
|
247
|
-
it "evaluates to true" do
|
255
|
+
context 'and kids_interest? is true' do
|
256
|
+
before { asset.stub kids_interest?: true }
|
257
|
+
|
258
|
+
it 'evaluates to true' do
|
248
259
|
asset.kids?.should eq true
|
249
260
|
end
|
250
261
|
end
|
262
|
+
end
|
251
263
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
264
|
+
context "and awcamps30? returns true" do
|
265
|
+
let(:asset) { ACTV::Asset.new assetGuid: 1, sourceSystem: {legacyGuid: "89208DBA-F535-4950-880A-34A6888A184C"} }
|
266
|
+
|
267
|
+
context 'and kids_interest? is true' do
|
268
|
+
before { asset.stub kids_interest?: true }
|
269
|
+
|
270
|
+
it 'evaluates to true' do
|
271
|
+
asset.kids?.should eq true
|
259
272
|
end
|
260
273
|
end
|
261
274
|
end
|
262
|
-
end
|
263
275
|
|
264
|
-
|
265
|
-
|
266
|
-
it 'evaluates to false' do
|
267
|
-
asset.kids?.should eq false
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
276
|
+
context "and articles_source? returns true" do
|
277
|
+
let(:asset) { ACTV::Asset.new assetGuid: 1, sourceSystem: {legacyGuid: "CA4EA0B1-7377-470D-B20D-BF6BEA23F040"} }
|
271
278
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
it "evaluates to true" do
|
280
|
-
asset.kidsinterest?.should eq true
|
279
|
+
context 'and kids_interest? is true' do
|
280
|
+
before { asset.stub kids_interest?: true }
|
281
|
+
|
282
|
+
it 'evaluates to true' do
|
283
|
+
asset.kids?.should eq true
|
284
|
+
end
|
285
|
+
end
|
281
286
|
end
|
282
287
|
end
|
283
288
|
|
284
|
-
context "when
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
289
|
+
context "when kids_friendly_source_system? is false" do
|
290
|
+
context "by stubbing kids_friendly_source_system?" do
|
291
|
+
before { asset.stub kids_friendly_source_system?: false }
|
292
|
+
|
293
|
+
it 'evaluates to false' do
|
294
|
+
asset.kids?.should eq false
|
295
|
+
end
|
291
296
|
end
|
292
|
-
end
|
293
297
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
+
context "and all source systems return false" do
|
299
|
+
before do
|
300
|
+
asset.stub activenet?: false
|
301
|
+
asset.stub awcamps?: false
|
302
|
+
asset.stub awcamps30?: false
|
303
|
+
asset.stub articles_source?: false
|
304
|
+
end
|
305
|
+
|
306
|
+
it 'evaluates to false' do
|
307
|
+
asset.kids?.should eq false
|
308
|
+
end
|
298
309
|
end
|
299
310
|
end
|
300
311
|
end
|
@@ -318,11 +329,18 @@ describe ACTV::Asset do
|
|
318
329
|
|
319
330
|
describe "topic path methods" do
|
320
331
|
let(:assetTopics) do
|
321
|
-
[ { sequence: '2', topic: { topicTaxonomy: "Forth/Fifth/Sixth" } },
|
322
|
-
{ sequence: '1', topic: { topicTaxonomy: "First/Second/Third" } } ]
|
332
|
+
[ { sequence: '2', topic: { topicTaxonomy: "Forth/Fifth/Sixth", topicName: "Triathlon" } },
|
333
|
+
{ sequence: '1', topic: { topicTaxonomy: "First/Second/Third", topicName: "Running" } } ]
|
323
334
|
end
|
324
335
|
let(:asset) { ACTV::Asset.new assetGuid: 1, assetTopics: assetTopics }
|
325
336
|
|
337
|
+
|
338
|
+
describe '#first_topic_name' do
|
339
|
+
it "returns the first topics name" do
|
340
|
+
asset.first_topic_name.should == "Running"
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
326
344
|
describe "#first_topic_path" do
|
327
345
|
it "returns the first part of the first asset topic" do
|
328
346
|
asset.first_topic_path.should == 'first'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ACTV::AssetTopic do
|
4
|
+
|
5
|
+
let(:topic) { ACTV::AssetTopic.new sequence: '1' }
|
6
|
+
let(:topic_2) { ACTV::AssetTopic.new sequence: '2' }
|
7
|
+
|
8
|
+
describe "attribute accessors and aliases" do
|
9
|
+
subject { topic }
|
10
|
+
|
11
|
+
its(:sequence){ should eq '1' }
|
12
|
+
it "sorts by sequence" do
|
13
|
+
[topic_2,topic].sort.first.sequence.should eq '1'
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -9,14 +9,14 @@ describe ACTV::Client do
|
|
9
9
|
describe "#asset" do
|
10
10
|
context "with a valid asset ID passed" do
|
11
11
|
before do
|
12
|
-
|
12
|
+
stub_post("/v2/assets.json").with(:body => {"id"=>"valid_asset"}).
|
13
13
|
to_return(body: fixture("valid_asset.json"), headers: { content_type: "application/json; charset=utf-8" })
|
14
14
|
|
15
15
|
@asset = @client.asset("valid_asset")[0]
|
16
16
|
end
|
17
17
|
|
18
18
|
it "requests the correct asset" do
|
19
|
-
|
19
|
+
a_post("/v2/assets.json").should have_been_made
|
20
20
|
end
|
21
21
|
|
22
22
|
it "returns the correct place" do
|
@@ -84,4 +84,4 @@ describe ACTV::Client do
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
end
|
87
|
+
end
|
@@ -23,7 +23,7 @@ describe ACTV::Client do
|
|
23
23
|
before do
|
24
24
|
stub_request(:get, "http://api.amp.active.com/api/v1/events/asdf/asdf.json").
|
25
25
|
with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'}).
|
26
|
-
to_return(:status =>
|
26
|
+
to_return(:status => 500, :body => "", :headers => {})
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'returns nil' do
|
data/spec/actv/client_spec.rb
CHANGED
@@ -145,6 +145,20 @@ describe ACTV::Client do
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
+
context 'when mutiple event ids' do
|
149
|
+
before do
|
150
|
+
stub_request(:get, "http://api.amp.active.com/v2/assets/asset_ids.json").
|
151
|
+
to_return(body: fixture("valid_assets.json"), headers: { content_type: "application/json; charset=utf-8" })
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'returns an Array of Event' do
|
155
|
+
client.event('asset_ids').should be_a Array
|
156
|
+
client.event('asset_ids').first.should be_a ACTV::Event
|
157
|
+
client.event('asset_ids').last.should be_a ACTV::Event
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
148
162
|
context 'preview event' do
|
149
163
|
context 'when set to true' do
|
150
164
|
before do
|