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 CHANGED
@@ -1,4 +1,6 @@
1
1
  [![Build Status](https://travis-ci.org/activenetwork/actv.png)](https://travis-ci.org/activenetwork/actv)
2
+ [![Code
3
+ Climate](https://codeclimate.com/github/activenetwork/actv/badges/gpa.svg)](https://codeclimate.com/github/activenetwork/actv)
2
4
 
3
5
  # ACTV
4
6
 
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
- # this guid is equal to the Active.com Articles
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
- (activenet? || awcamps? || awcamps30?) && kidsinterest?
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.sort_by(&:sequence).first
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
@@ -7,5 +7,9 @@ module ACTV
7
7
  def topic
8
8
  @topic ||= ACTV::Topic.new(@attrs[:topic]) unless @attrs[:topic].nil?
9
9
  end
10
+
11
+ def <=> topic
12
+ sequence <=> topic.sequence
13
+ end
10
14
  end
11
15
  end
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
- results = []
78
- response[:body].each do |item|
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
- event = ACTV::Event.from_response(response)
170
- event = ACTV::Evergreen.new(event) if event.evergreen?
171
- event.is_article? ? nil : event
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
@@ -1,3 +1,3 @@
1
1
  module ACTV
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -82,13 +82,13 @@ describe ACTV::Asset do
82
82
  end
83
83
  end
84
84
 
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
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
- it "returns nil when assetLegacyData is not set" do
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
- stub_get("/v2/assets/valid_article.json").
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
- stub_get("/v2/assets/valid_event.json").
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
- context 'when kidsinterest? is true' do
206
- before do
207
- asset.stub kidsinterest?: true
208
- class Rails
209
- def self.env
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
- context "when source system is Active Net" do
216
- before { asset.stub activenet?: true }
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 source system is AW Camps' do
219
- before do
220
- asset.stub awcamps?: true
221
- asset.stub awcamps30?: true
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 source system is not AW Camps' do
229
- before do
230
- asset.stub awcamps?: false
231
- asset.stub awcamps30?: false
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
- it "evaluates to true" do
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 'when source system is not Active Net' do
240
- before { asset.stub activenet?: false }
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 'when source system is AW Camps' do
243
- before do
244
- asset.stub awcamps?: true
245
- asset.stub awcamps30?: true
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
- context 'when source system is not AW Camps' do
253
- before do
254
- asset.stub awcamps?: false
255
- asset.stub awcamps30?: false
256
- end
257
- it "evaluates to false" do
258
- asset.kids?.should eq false
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
- context 'when kidsinterest? is false' do
265
- before { asset.stub kidsinterest?: false }
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
- describe "#kidsinterest?" do
273
- let(:asset) { ACTV::Asset.new assetGuid: 1, assetMetaInterests: meta_interests }
274
- context "when kids meta-interest" do
275
- let(:meta_interests) do
276
- [ { sequence: '2', metaInterest: { metaInterestName: 'Family' } },
277
- { sequence: '1', metaInterest: { metaInterestName: 'Kids' } } ]
278
- end
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 other meta-interest" do
285
- let(:meta_interests) do
286
- [ { sequence: '2', metaInterest: { metaInterestName: 'NoFamily' } },
287
- { sequence: '1', metaInterest: { metaInterestName: 'NoKids' } } ]
288
- end
289
- it "evaluates to false" do
290
- asset.kidsinterest?.should eq false
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
- context "when no meta-interest" do
295
- let(:meta_interests) {[]}
296
- it "evaluates to false" do
297
- asset.kidsinterest?.should eq false
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
- stub_get("/v2/assets/valid_asset.json").
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
- a_get("/v2/assets/valid_asset.json").should have_been_made
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 => 200, :body => "", :headers => {})
26
+ to_return(:status => 500, :body => "", :headers => {})
27
27
  end
28
28
 
29
29
  it 'returns nil' do
@@ -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