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,38 @@
1
+ require 'actv/address'
2
+ require 'actv/phone_number'
3
+
4
+ module ACTV
5
+ class User < ACTV::Identity
6
+
7
+ attr_reader :first_name, :last_name, :middle_name, :gender,
8
+ :display_name, :date_of_birth, :email, :user_name, :created_date
9
+
10
+ attr_accessor :access_token
11
+
12
+ alias dob date_of_birth
13
+
14
+ def advantage_member
15
+ @is_member ||= begin
16
+ client= ACTV::Client.new({ oauth_token: @access_token })
17
+ client.is_advantage_member?
18
+ end
19
+ end
20
+ alias is_advantage_member? advantage_member
21
+
22
+ def avatar_url
23
+ @avatar_url ||= begin
24
+ client= ACTV::Client.new({ oauth_token: @access_token })
25
+ client.avatar_url
26
+ end
27
+ end
28
+
29
+ def address
30
+ @address ||= ACTV::Address.new(@attrs[:address]) unless @attrs[:address].nil?
31
+ end
32
+
33
+ def phone_number
34
+ @phone_number ||= ACTV::PhoneNumber.new(@attrs[:phone_number]) unless @attrs[:phone_number].nil?
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module ACTV
2
+ VERSION = "1.1.0"
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe ACTV::ArticleSearchResults do
4
+ describe '#results' do
5
+ it 'should return an array of ACTV::Article when results is set' do
6
+ results = ACTV::ArticleSearchResults.new({results: [{assetGuid: '123', assetName: 'test1'}, {assetGuid: '345', assetName: 'test2'}]}).results
7
+ results.should be_a Array
8
+ results.first.should be_a ACTV::Article
9
+ end
10
+
11
+ it 'should return an emtpy array when results is not set' do
12
+ results = ACTV::ArticleSearchResults.new({}).results
13
+ results.should eql []
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe ACTV::Article do
4
+ context "shoulda matchers" do
5
+ subject { ACTV::Article.new(assetGuid: 1) }
6
+
7
+ it { should respond_to :summary }
8
+ it { should respond_to :description }
9
+ it { should respond_to :by_line }
10
+ it { should respond_to :author_bio }
11
+ it { should respond_to :author_photo }
12
+ it { should respond_to :source }
13
+ it { should respond_to :type }
14
+ it { should respond_to :image }
15
+ it { should respond_to :subtitle }
16
+ it { should respond_to :footer }
17
+ it { should respond_to :inline_ad }
18
+ it { should respond_to :inline_ad? }
19
+ end
20
+
21
+ describe '#inline_ad?' do
22
+ context 'if inlindead is set to true' do
23
+ let(:article) { ACTV::Article.new(assetGuid: 1, assetTags: [ { tag: { tagId: '1', tagName: 'true', tagDescription: 'inlinead' } } ]) }
24
+ it 'should return true' do
25
+ article.inline_ad?.should eq true
26
+ end
27
+ end
28
+
29
+ context 'if inlindead is set to false' do
30
+ let(:article) { ACTV::Article.new(assetGuid: 1, assetTags: [ { tag: { tagId: '1', tagName: 'false', tagDescription: 'inlinead' } } ]) }
31
+ it 'should return false' do
32
+ article.inline_ad?.should eq false
33
+ end
34
+ end
35
+
36
+ context 'if inlindead is not set' do
37
+ let(:article) { ACTV::Article.new assetGuid: 1 }
38
+
39
+ it 'should return true' do
40
+ article.inline_ad?.should eq true
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe ACTV::AssetChannel do
4
+
5
+ describe "#channel" do
6
+ it "returns a Channel when channel is set" do
7
+ channel = ACTV::AssetChannel.new(sequence: "1", channel: { channelId: "1", channelName: "Channel", channelDsc: "Channel" }).channel
8
+ channel.should be_a ACTV::Channel
9
+ end
10
+
11
+ it "returns nil when channel is not set" do
12
+ channel = ACTV::AssetChannel.new(sequence: "1").channel
13
+ channel.should be_nil
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe ACTV::AssetDescription do
4
+
5
+ describe "#description_type" do
6
+ it "returns a Asset Description Type when descriptionType is set" do
7
+ description_type = ACTV::AssetDescription.new(description: "Description #1", descriptionType: { descriptionTypeId: 1, descriptionTypeName: "TYPE" }).description_type
8
+ description_type.should be_a ACTV::AssetDescriptionType
9
+ end
10
+
11
+ it "returns nil when descriptionType is not set" do
12
+ description_type = ACTV::AssetDescription.new(description: "Description #1").description_type
13
+ description_type.should be_nil
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe ACTV::AssetImage do
4
+
5
+ before(:each) do
6
+ @img = ACTV::AssetImage.new(imageUrlAdr: 'http://test.com/1.jpg',
7
+ imageName: 'image1', imageCaptionTxt: 'caption1', linkUrl: 'http://test.com/',
8
+ linkTarget: '_blank')
9
+ end
10
+
11
+ describe "attribute accessors and aliases" do
12
+ subject { @img }
13
+
14
+ its(:url){ should eq 'http://test.com/1.jpg' }
15
+ its(:name){ should eq 'image1' }
16
+ its(:caption){ should eq 'caption1' }
17
+ its(:link){ should eq 'http://test.com/'}
18
+ its(:target){ should eq '_blank' }
19
+
20
+ its(:imageUrlAdr){ should eq 'http://test.com/1.jpg' }
21
+ its(:imageName){ should eq 'image1' }
22
+ its(:imageCaptionTxt){ should eq 'caption1' }
23
+ its(:linkUrl){ should eq 'http://test.com/'}
24
+ its(:linkTarget){ should eq '_blank' }
25
+ end
26
+
27
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe ACTV::AssetPrice do
4
+
5
+ before(:each) do
6
+ @price = ACTV::AssetPrice.new(effectiveDate: "2012-08-03T06:59:00", priceAmt: "10", maxPriceAmt: "15", minPriceAmt: "5")
7
+ end
8
+
9
+ describe "attribute accessors and aliases" do
10
+ subject { @price }
11
+
12
+ its(:effective_date){ should eq "2012-08-03T06:59:00" }
13
+ its(:amount){ should eq "10" }
14
+ its(:max_amount){ should eq "15" }
15
+ its(:min_amount){ should eq "5" }
16
+
17
+ its(:effectiveDate){ should eq "2012-08-03T06:59:00" }
18
+ its(:priceAmt){ should eq "10" }
19
+ its(:maxPriceAmt){ should eq "15" }
20
+ its(:minPriceAmt){ should eq "5" }
21
+ end
22
+
23
+ end
@@ -0,0 +1,172 @@
1
+ require 'spec_helper'
2
+
3
+ describe ACTV::Asset do
4
+
5
+ describe "#==" do
6
+ it "return true when objects IDs are the same" do
7
+ asset = ACTV::Asset.new(assetGuid: 1, assetName: "Title 1")
8
+ other = ACTV::Asset.new(assetGuid: 1, assetName: "Title 2")
9
+ (asset == other).should be_true
10
+ end
11
+
12
+ it "return false when objects IDs are different" do
13
+ asset = ACTV::Asset.new(assetGuid: 1)
14
+ other = ACTV::Asset.new(assetGuid: 2)
15
+ (asset == other).should be_false
16
+ end
17
+
18
+ it "return false when classes are different" do
19
+ asset = ACTV::Asset.new(assetGuid: 1)
20
+ other = ACTV::Identity.new(id: 1)
21
+ (asset == other).should be_false
22
+ end
23
+ end
24
+
25
+ describe "#place" do
26
+ it "returns a Place when place is set" do
27
+ place = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1", place: { placeGuid: 1, placeName: "Name #1" }).place
28
+ place.should be_a ACTV::Place
29
+ end
30
+
31
+ it "return nil when place is not set" do
32
+ place = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1").place
33
+ place.should be_nil
34
+ end
35
+ end
36
+
37
+ describe "#descriptions" do
38
+ it "returns an Array of Asset Descriptions when assetDescriptions is set" do
39
+ descriptions = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1", assetDescriptions: [{ description: "Description #1" }, { description: "Description #2" }]).descriptions
40
+ descriptions.should be_a Array
41
+ descriptions.first.should be_a ACTV::AssetDescription
42
+ end
43
+
44
+ it "returns an empty array when assetDescriptions is not set" do
45
+ descriptions = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1").descriptions
46
+ descriptions.should be_a Array
47
+ descriptions.should eq []
48
+ end
49
+ end
50
+
51
+ describe "#status" do
52
+ it "returns a Asset Status when assetStatus is set" do
53
+ status = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1", assetStatus: { assetStatusId: 1, assetStatusName: "Status #1", isSearchable: true }).status
54
+ status.should be_a ACTV::AssetStatus
55
+ end
56
+
57
+ it "returns nil when assetStatus is not set" do
58
+ status = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1").status
59
+ status.should be_nil
60
+ end
61
+ end
62
+
63
+ describe "#legacy_data" do
64
+ it "returns a Asset Legacy Data when assetLegacyData is set" do
65
+ legacy_data = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1", assetLegacyData: { assetTypeId: 1, typeName: "Legacy Data", isSearchable: true }).legacy_data
66
+ legacy_data.should be_a ACTV::AssetLegacyData
67
+ end
68
+
69
+ it "returns nil when assetLegacyData is not set" do
70
+ legacy_data = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1").legacy_data
71
+ legacy_data.should be_nil
72
+ end
73
+ end
74
+
75
+ describe "#images" do
76
+ it "returns an Array of Asset Images when assetImages is set" do
77
+ images = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1", assetImages: [{ imageUrlAdr: "img1.jpg" }, { imageUrlAdr: "img2.jpg" }]).images
78
+ images.should be_a Array
79
+ images.first.should be_a ACTV::AssetImage
80
+ end
81
+
82
+ it "returns an empty array when assetImages is not set" do
83
+ images = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1").images
84
+ images.should be_a Array
85
+ images.should eq []
86
+ end
87
+ end
88
+
89
+ describe "#tags" do
90
+ it "returns an Array of Asset Tags when assetTags is set" do
91
+ tags = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1", assetTags: [{ tag: { tagId: 1, tagName: "Tag" } }]).tags
92
+ tags.should be_a Array
93
+ tags.first.should be_a ACTV::AssetTag
94
+ end
95
+
96
+ it "returns an empty array when assetImages is not set" do
97
+ tags = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1").tags
98
+ tags.should be_a Array
99
+ tags.should eq []
100
+ end
101
+ end
102
+
103
+ describe "#components" do
104
+ it "returns an Array of Asset Components when assetComponents is set" do
105
+ components = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1", assetComponents: [{ assetGuid: 1}]).components
106
+ components.should be_a Array
107
+ components.first.should be_a ACTV::AssetComponent
108
+ end
109
+
110
+ it "returns an empty array when assetComponents is not set" do
111
+ components = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1").tags
112
+ components.should be_a Array
113
+ components.should eq []
114
+ end
115
+ end
116
+
117
+ describe "#prices" do
118
+ it "returns an Array of Asset Prices when assetPrices is set" do
119
+ prices = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1", assetPrices: [{ effectiveDate: "2012-08-03T06:59:00", priceAmt: "10" }]).prices
120
+ prices.should be_a Array
121
+ prices.first.should be_a ACTV::AssetPrice
122
+ end
123
+
124
+ it "returns an empty array when assetComponents is not set" do
125
+ prices = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1").tags
126
+ prices.should be_a Array
127
+ prices.should eq []
128
+ end
129
+ end
130
+
131
+ describe "#topics" do
132
+ it "returns an Array of Asset Topics when assetTopics is set" do
133
+ topics = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1", assetTopics: [{ sequence: "1", topic: { topicId: "27", topicName: "Running" } }]).topics
134
+ topics.should be_a Array
135
+ topics.first.should be_a ACTV::AssetTopic
136
+ end
137
+
138
+ it "returns an empty array when assetComponents is not set" do
139
+ topics = ACTV::Asset.new(assetGuid: 1, assetName: "Asset #1").topics
140
+ topics.should be_a Array
141
+ topics.should eq []
142
+ end
143
+ end
144
+
145
+ describe "is_article?" do
146
+ before(:each) do
147
+ stub_get("/v2/assets/valid_article.json").
148
+ to_return(body: fixture("valid_article.json"), headers: { content_type: "application/json; charset=utf-8" })
149
+ end
150
+
151
+ it "should return true if the asset has Articles as an assetCategory" do
152
+ asset = ACTV.asset('valid_article')[0]
153
+ asset.is_article?.should be_true
154
+ end
155
+
156
+ it "should return true if the asset has no assetCategories but the sourceSystem is Active.com Articles" do
157
+ asset = ACTV.asset('valid_article')[0]
158
+ asset.stub(:assetCategories).and_return([])
159
+ asset.is_article?.should be_true
160
+ end
161
+
162
+ it "should return false if no assetCategory of Article" do
163
+ stub_get("/v2/assets/valid_event.json").
164
+ to_return(body: fixture("valid_event.json"), headers: { content_type: "application/json; charset=utf-8" })
165
+
166
+ asset = ACTV.asset('valid_event')[0]
167
+ asset.is_article?.should be_false
168
+ end
169
+
170
+ end
171
+
172
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe ACTV::AssetStatus do
4
+
5
+ describe "#==" do
6
+ it "return true when objects IDs are the same" do
7
+ asset = ACTV::AssetStatus.new(assetStatusId: 1, assetStatusName: "Status 1")
8
+ other = ACTV::AssetStatus.new(assetStatusId: 1, assetStatusName: "Status 2")
9
+ (asset == other).should be_true
10
+ end
11
+
12
+ it "return false when objects IDs are different" do
13
+ asset = ACTV::AssetStatus.new(assetStatusId: 1)
14
+ other = ACTV::AssetStatus.new(assetStatusId: 2)
15
+ (asset == other).should be_false
16
+ end
17
+
18
+ it "return false when classes are different" do
19
+ asset = ACTV::AssetStatus.new(assetStatusId: 1)
20
+ other = ACTV::Identity.new(id: 1)
21
+ (asset == other).should be_false
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe ACTV::Base do
4
+
5
+ before do
6
+ @base = ACTV::Base.new(:id => 1)
7
+ end
8
+
9
+ describe "#[]" do
10
+ it "calls methods using [] with symbol" do
11
+ @base[:object_id].should be_an Integer
12
+ end
13
+ it "calls methods using [] with string" do
14
+ @base['object_id'].should be_an Integer
15
+ end
16
+ it "returns nil for missing method" do
17
+ @base[:foo].should be_nil
18
+ @base['foo'].should be_nil
19
+ end
20
+ end
21
+
22
+ describe "#attrs" do
23
+ it "returns a hash of attributes" do
24
+ @base.attrs.should eq({:id => 1})
25
+ end
26
+ end
27
+
28
+ describe "#delete" do
29
+ it "deletes an attribute and returns its value" do
30
+ base = ACTV::Base.new(:id => 1)
31
+ base.delete(:id).should eq(1)
32
+ base.attrs[:id].should be_nil
33
+ end
34
+ end
35
+
36
+ describe "#update" do
37
+ it "returns a hash of attributes" do
38
+ base = ACTV::Base.new(:id => 1)
39
+ base.update(:id => 2)
40
+ base.attrs[:id].should eq(2)
41
+ end
42
+ end
43
+
44
+ describe "#to_hash" do
45
+ it "returns a hash" do
46
+ @base.to_hash.should be_a Hash
47
+ @base.to_hash[:id].should eq 1
48
+ end
49
+ end
50
+
51
+ end