7digital 0.1.2 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +143 -143
- data/lib/sevendigital.rb +55 -55
- data/lib/sevendigital/api_operator.rb +127 -127
- data/lib/sevendigital/api_operator_cached.rb +91 -62
- data/lib/sevendigital/api_request.rb +72 -62
- data/lib/sevendigital/client.rb +122 -122
- data/lib/sevendigital/client_configuration.rb +85 -83
- data/lib/sevendigital/client_digestors.rb +122 -122
- data/lib/sevendigital/client_managers.rb +57 -57
- data/lib/sevendigital/digestion_tract/api_response_digestor.rb +48 -48
- data/lib/sevendigital/digestion_tract/artist_digestor.rb +35 -35
- data/lib/sevendigital/digestion_tract/basket_digestor.rb +19 -19
- data/lib/sevendigital/digestion_tract/basket_item_digestor.rb +26 -26
- data/lib/sevendigital/digestion_tract/chart_item_digestor.rb +34 -34
- data/lib/sevendigital/digestion_tract/country_digestor.rb +15 -15
- data/lib/sevendigital/digestion_tract/digestor.rb +122 -122
- data/lib/sevendigital/digestion_tract/download_url_digestor.rb +23 -23
- data/lib/sevendigital/digestion_tract/format_digestor.rb +24 -24
- data/lib/sevendigital/digestion_tract/label_digestor.rb +21 -21
- data/lib/sevendigital/digestion_tract/list_digestor.rb +24 -24
- data/lib/sevendigital/digestion_tract/list_item_digestor.rb +26 -26
- data/lib/sevendigital/digestion_tract/locker_digestor.rb +22 -22
- data/lib/sevendigital/digestion_tract/locker_release_digestor.rb +26 -26
- data/lib/sevendigital/digestion_tract/locker_track_digestor.rb +26 -26
- data/lib/sevendigital/digestion_tract/oauth_access_token_digestor.rb +18 -18
- data/lib/sevendigital/digestion_tract/oauth_request_token_digestor.rb +18 -18
- data/lib/sevendigital/digestion_tract/pager_digestor.rb +28 -28
- data/lib/sevendigital/digestion_tract/price_digestor.rb +28 -28
- data/lib/sevendigital/digestion_tract/release_digestor.rb +45 -45
- data/lib/sevendigital/digestion_tract/tag_digestor.rb +23 -23
- data/lib/sevendigital/digestion_tract/track_digestor.rb +38 -37
- data/lib/sevendigital/digestion_tract/user_card_digestor.rb +24 -24
- data/lib/sevendigital/digestion_tract/user_digestor.rb +21 -21
- data/lib/sevendigital/management/artist_manager.rb +97 -97
- data/lib/sevendigital/management/basket_manager.rb +29 -29
- data/lib/sevendigital/management/country_manager.rb +10 -10
- data/lib/sevendigital/management/list_manager.rb +18 -18
- data/lib/sevendigital/management/manager.rb +12 -12
- data/lib/sevendigital/management/oauth_manager.rb +23 -23
- data/lib/sevendigital/management/release_manager.rb +54 -54
- data/lib/sevendigital/management/tag_manager.rb +10 -10
- data/lib/sevendigital/management/track_manager.rb +29 -27
- data/lib/sevendigital/management/user_card_manager.rb +26 -26
- data/lib/sevendigital/management/user_manager.rb +76 -76
- data/lib/sevendigital/model/api_response.rb +32 -32
- data/lib/sevendigital/model/artist.rb +104 -104
- data/lib/sevendigital/model/basket.rb +15 -15
- data/lib/sevendigital/model/basket_item.rb +14 -14
- data/lib/sevendigital/model/card.rb +11 -11
- data/lib/sevendigital/model/chart_item.rb +9 -9
- data/lib/sevendigital/model/download_url.rb +7 -7
- data/lib/sevendigital/model/format.rb +7 -7
- data/lib/sevendigital/model/label.rb +7 -7
- data/lib/sevendigital/model/list.rb +4 -4
- data/lib/sevendigital/model/list_item.rb +8 -8
- data/lib/sevendigital/model/locker.rb +4 -4
- data/lib/sevendigital/model/locker_release.rb +9 -9
- data/lib/sevendigital/model/locker_track.rb +9 -9
- data/lib/sevendigital/model/price.rb +9 -9
- data/lib/sevendigital/model/release.rb +57 -57
- data/lib/sevendigital/model/sevendigital_error.rb +11 -11
- data/lib/sevendigital/model/sevendigital_object.rb +57 -57
- data/lib/sevendigital/model/tag.rb +7 -7
- data/lib/sevendigital/model/track.rb +87 -83
- data/lib/sevendigital/model/user.rb +74 -74
- data/lib/sevendigital/pager.rb +20 -20
- data/lib/sevendigital/version.rb +5 -5
- data/spec/api_operator_cached_spec.rb +233 -178
- data/spec/api_operator_spec.rb +320 -320
- data/spec/api_request_spec.rb +46 -31
- data/spec/client_configuration_spec.rb +78 -78
- data/spec/client_spec.rb +161 -161
- data/spec/data/config/sevendigital.yml +5 -5
- data/spec/data/configuration_env_override.yml +5 -5
- data/spec/data/configuration_override.yml +1 -1
- data/spec/digestion_tract/api_response_digestor_spec.rb +93 -93
- data/spec/digestion_tract/artist_digestor_spec.rb +81 -81
- data/spec/digestion_tract/basket_digestor_spec.rb +31 -31
- data/spec/digestion_tract/basket_item_digestor_spec.rb +58 -58
- data/spec/digestion_tract/chart_digestor_spec.rb +52 -52
- data/spec/digestion_tract/country_digestor_spec.rb +33 -33
- data/spec/digestion_tract/digestor_spec.rb +33 -33
- data/spec/digestion_tract/download_url_digestor_spec.rb +40 -40
- data/spec/digestion_tract/format_digestor_spec.rb +38 -38
- data/spec/digestion_tract/label_digestor_spec.rb +33 -33
- data/spec/digestion_tract/list_digestor_spec.rb +31 -31
- data/spec/digestion_tract/list_item_digestor_spec.rb +80 -80
- data/spec/digestion_tract/locker_digestor_spec.rb +30 -30
- data/spec/digestion_tract/locker_release_digestor_spec.rb +70 -70
- data/spec/digestion_tract/locker_track_digestor_spec.rb +56 -56
- data/spec/digestion_tract/oauth_access_token_digestor_spec.rb +34 -34
- data/spec/digestion_tract/oauth_request_token_digestor_spec.rb +34 -34
- data/spec/digestion_tract/pager_digestor_spec.rb +50 -50
- data/spec/digestion_tract/price_digestor_spec.rb +73 -73
- data/spec/digestion_tract/release_digestor_spec.rb +115 -115
- data/spec/digestion_tract/tag_digestor_spec.rb +46 -46
- data/spec/digestion_tract/track_digestor_spec.rb +105 -104
- data/spec/digestion_tract/user_card_digestor_spec.rb +58 -58
- data/spec/digestion_tract/user_digestor_spec.rb +42 -42
- data/spec/integration/artist_spec.rb +99 -86
- data/spec/integration/country_spec.rb +18 -18
- data/spec/integration/list_spec.rb +22 -22
- data/spec/integration/purchasing_spec.rb +24 -24
- data/spec/integration/release_spec.rb +34 -34
- data/spec/integration/sevendigital_spec.yml +4 -4
- data/spec/integration/track_spec.rb +38 -23
- data/spec/integration/user_spec.rb +22 -22
- data/spec/management/artist_manager_spec.rb +172 -172
- data/spec/management/basket_manager_spec.rb +77 -77
- data/spec/management/country_manager_spec.rb +34 -34
- data/spec/management/list_manager_spec.rb +26 -26
- data/spec/management/oauth_manager_spec.rb +72 -72
- data/spec/management/release_manager_spec.rb +200 -200
- data/spec/management/tag_manager_spec.rb +34 -34
- data/spec/management/track_manager_spec.rb +111 -107
- data/spec/management/user_card_manager_spec.rb +78 -78
- data/spec/management/user_manager_spec.rb +218 -218
- data/spec/model/api_response_spec.rb +48 -48
- data/spec/model/artist_spec.rb +162 -162
- data/spec/model/basket_spec.rb +62 -62
- data/spec/model/release_spec.rb +133 -133
- data/spec/model/sevendigital_object_spec.rb +73 -73
- data/spec/model/track_spec.rb +146 -144
- data/spec/model/user_spec.rb +181 -181
- data/spec/spec_helper.rb +86 -84
- data/spec/test-xml/methods/artist/browse.xml +21 -21
- data/spec/test-xml/methods/artist/byTag/top.xml +50 -50
- data/spec/test-xml/methods/artist/chart.xml +30 -30
- data/spec/test-xml/methods/artist/details.xml +9 -9
- data/spec/test-xml/methods/artist/releases.xml +544 -544
- data/spec/test-xml/methods/artist/search.xml +18 -18
- data/spec/test-xml/methods/artist/similar.xml +39 -39
- data/spec/test-xml/methods/artist/tags.xml +11 -11
- data/spec/test-xml/methods/artist/toptracks.xml +279 -279
- data/spec/test-xml/methods/basket/additem.xml +23 -23
- data/spec/test-xml/methods/basket/create.xml +10 -10
- data/spec/test-xml/methods/basket/index.xml +23 -23
- data/spec/test-xml/methods/basket/removeitem.xml +10 -10
- data/spec/test-xml/methods/country/resolve.xml +6 -6
- data/spec/test-xml/methods/editorial/list.xml +170 -170
- data/spec/test-xml/methods/oauth/accesstoken.xml +5 -5
- data/spec/test-xml/methods/oauth/requesttoken.xml +5 -5
- data/spec/test-xml/methods/release/bydate.xml +173 -173
- data/spec/test-xml/methods/release/bytag/top.xml +150 -150
- data/spec/test-xml/methods/release/chart.xml +181 -181
- data/spec/test-xml/methods/release/details.xml +48 -48
- data/spec/test-xml/methods/release/recommend.xml +89 -89
- data/spec/test-xml/methods/release/search.xml +194 -194
- data/spec/test-xml/methods/release/tags.xml +27 -27
- data/spec/test-xml/methods/release/tracks.xml +28 -28
- data/spec/test-xml/methods/tag/index.xml +16 -16
- data/spec/test-xml/methods/track/chart.xml +149 -149
- data/spec/test-xml/methods/track/details.xml +30 -30
- data/spec/test-xml/methods/track/search.xml +159 -159
- data/spec/test-xml/methods/user/details.xml +4 -4
- data/spec/test-xml/methods/user/locker.xml +49 -49
- data/spec/test-xml/methods/user/payment/card/add.xml +7 -7
- data/spec/test-xml/methods/user/payment/card/index.xml +7 -7
- data/spec/test-xml/methods/user/purchase/basket.xml +48 -48
- data/spec/test-xml/methods/user/purchase/item.xml +48 -48
- data/spec/test-xml/methods/user/signUp.xml +5 -5
- data/spec/test-xml/objects/artist.xml +7 -7
- data/spec/test-xml/objects/artist_chart_item.xml +7 -7
- data/spec/test-xml/objects/artist_list.xml +22 -22
- data/spec/test-xml/objects/artist_list_empty.xml +4 -4
- data/spec/test-xml/objects/basket.xml +21 -21
- data/spec/test-xml/objects/basket_item.xml +11 -11
- data/spec/test-xml/objects/basket_item_list.xml +25 -25
- data/spec/test-xml/objects/basket_item_list_empty.xml +1 -1
- data/spec/test-xml/objects/download_url.xml +7 -7
- data/spec/test-xml/objects/list.xml +89 -89
- data/spec/test-xml/objects/list_item_list.xml +85 -85
- data/spec/test-xml/objects/list_item_release.xml +13 -13
- data/spec/test-xml/objects/locker.xml +47 -47
- data/spec/test-xml/objects/locker_release.xml +40 -40
- data/spec/test-xml/objects/locker_release_list.xml +87 -87
- data/spec/test-xml/objects/locker_release_list_empty.xml +4 -4
- data/spec/test-xml/objects/locker_release_one_item_list.xml +43 -43
- data/spec/test-xml/objects/locker_track.xml +25 -25
- data/spec/test-xml/objects/locker_track_list.xml +26 -26
- data/spec/test-xml/objects/locker_track_list_empty.xml +2 -2
- data/spec/test-xml/objects/nested_release_list.xml +22 -22
- data/spec/test-xml/objects/oauth_access_token.xml +3 -3
- data/spec/test-xml/objects/oauth_request_token.xml +3 -3
- data/spec/test-xml/objects/price.xml +7 -7
- data/spec/test-xml/objects/release.xml +40 -40
- data/spec/test-xml/objects/release_chart_item.xml +39 -39
- data/spec/test-xml/objects/release_list.xml +18 -18
- data/spec/test-xml/objects/release_list_empty.xml +4 -4
- data/spec/test-xml/objects/response.xml +38 -38
- data/spec/test-xml/objects/tag.xml +4 -4
- data/spec/test-xml/objects/track.xml +34 -33
- data/spec/test-xml/objects/track_chart_item.xml +27 -27
- data/spec/test-xml/objects/user.xml +4 -4
- data/spec/test-xml/objects/user_payment_card.xml +5 -5
- metadata +15 -25
data/spec/api_request_spec.rb
CHANGED
@@ -1,31 +1,46 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "ApiRequest" do
|
4
|
-
|
5
|
-
it "should always provide selected parameters in 7digital API format" do
|
6
|
-
|
7
|
-
request = Sevendigital::ApiRequest.new(:METHOD, 'method', {
|
8
|
-
:page => 5,
|
9
|
-
:per_page => 3,
|
10
|
-
:shop_id => 99,
|
11
|
-
:image_size => 999
|
12
|
-
})
|
13
|
-
request.parameters[:page].should == 5
|
14
|
-
request.parameters[:pageSize].should == 3
|
15
|
-
request.parameters[:per_page].should == nil
|
16
|
-
request.parameters[:shopId].should == 99
|
17
|
-
request.parameters[:shop_id].should == nil
|
18
|
-
request.parameters[:imageSize].should == 999
|
19
|
-
request.parameters[:image_size].should == nil
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should not contain nil parameters" do
|
24
|
-
|
25
|
-
request = Sevendigital::ApiRequest.new(:METHOD, 'method', {:key1 => "value", :key2 => nil})
|
26
|
-
request.parameters[:key1].should == "value"
|
27
|
-
request.parameters.has_key?(:key2).should == false
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "ApiRequest" do
|
4
|
+
|
5
|
+
it "should always provide selected parameters in 7digital API format" do
|
6
|
+
|
7
|
+
request = Sevendigital::ApiRequest.new(:METHOD, 'method', {
|
8
|
+
:page => 5,
|
9
|
+
:per_page => 3,
|
10
|
+
:shop_id => 99,
|
11
|
+
:image_size => 999
|
12
|
+
})
|
13
|
+
request.parameters[:page].should == 5
|
14
|
+
request.parameters[:pageSize].should == 3
|
15
|
+
request.parameters[:per_page].should == nil
|
16
|
+
request.parameters[:shopId].should == 99
|
17
|
+
request.parameters[:shop_id].should == nil
|
18
|
+
request.parameters[:imageSize].should == 999
|
19
|
+
request.parameters[:image_size].should == nil
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not contain nil parameters" do
|
24
|
+
|
25
|
+
request = Sevendigital::ApiRequest.new(:METHOD, 'method', {:key1 => "value", :key2 => nil})
|
26
|
+
request.parameters[:key1].should == "value"
|
27
|
+
request.parameters.has_key?(:key2).should == false
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
it "parameters should not contain wrapper options" do
|
32
|
+
|
33
|
+
request = Sevendigital::ApiRequest.new(:METHOD, 'method', {:key1 => "value", :cache_max_age => 123})
|
34
|
+
request.parameters[:key1].should == "value"
|
35
|
+
request.parameters.has_key?(:cache_max_age).should == false
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
it "options should be populated with wrapper options from parameters" do
|
40
|
+
|
41
|
+
request = Sevendigital::ApiRequest.new(:METHOD, 'method', {:key1 => "value", :cache_max_age => 123})
|
42
|
+
request.options[:cache_max_age].should == 123
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -1,79 +1,79 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "ClientConfiguration" do
|
4
|
-
|
5
|
-
it "should initialize with default configuration" do
|
6
|
-
configuration = Sevendigital::ClientConfiguration.new
|
7
|
-
configuration.api_url.should == 'api.7digital.com'
|
8
|
-
configuration.api_version.should == '1.2'
|
9
|
-
configuration.media_api_url.should == 'media-eu.7digital.com'
|
10
|
-
configuration.media_api_version.should == 'media'
|
11
|
-
configuration.account_api_url.should == 'account.7digital.com'
|
12
|
-
configuration.account_api_version.should == 'web'
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should initialize using hash" do
|
16
|
-
configuration = Sevendigital::ClientConfiguration.new(:api_url => "test-hash.7digital.com")
|
17
|
-
configuration.api_url.should == 'test-hash.7digital.com'
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should initialize using OpenStruct object" do
|
21
|
-
configuration = Sevendigital::ClientConfiguration.new(OpenStruct.new(:api_url => "test-openstruct.7digital.com"))
|
22
|
-
configuration.api_url.should == 'test-openstruct.7digital.com'
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should initialize using simple YAML file" do
|
26
|
-
configuration = Sevendigital::ClientConfiguration.new(File.join(File.dirname(__FILE__),"data", "configuration_override.yml"))
|
27
|
-
configuration.api_url.should == 'test-yml-simple.7digital.com'
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should initialize mixing configuration file name and explicit hash override" do
|
31
|
-
conf_file = File.join(File.dirname(__FILE__),"data", "configuration_override.yml")
|
32
|
-
configuration = Sevendigital::ClientConfiguration.new(conf_file, :api_url => 'hash-override')
|
33
|
-
configuration.api_url.should == 'hash-override'
|
34
|
-
configuration.api_version.should == 'yml-simple'
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should initialize mixing hash settings and configuration file override" do
|
38
|
-
conf_file = File.join(File.dirname(__FILE__),"data", "configuration_override.yml")
|
39
|
-
configuration = Sevendigital::ClientConfiguration.new({:api_url => 'hash-override', :xxx => 'yyy'}, conf_file)
|
40
|
-
configuration.api_url.should == 'test-yml-simple.7digital.com'
|
41
|
-
configuration.xxx.should == 'yyy'
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should initialize mixing 2 explicit hash overrides" do
|
45
|
-
configuration = Sevendigital::ClientConfiguration.new( {:api_url => 'v1', :a => 'x'}, {:api_url => 'v2', :b => 'y'})
|
46
|
-
configuration.api_url.should == 'v2'
|
47
|
-
configuration.a.should == 'x'
|
48
|
-
configuration.b.should == 'y'
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should use environment specific configuration file" do
|
52
|
-
conf_file = File.join(File.dirname(__FILE__),"data", "configuration_env_override.yml")
|
53
|
-
configuration = Sevendigital::ClientConfiguration.new(conf_file)
|
54
|
-
configuration.api_url.should == 'test-yml-common.7digital.com'
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should use environment specific configuration file with environment specific settings" do
|
58
|
-
conf_file = File.join(File.dirname(__FILE__),"data", "configuration_env_override.yml")
|
59
|
-
|
60
|
-
rails = OpenStruct.new
|
61
|
-
rails.env = "development"
|
62
|
-
Object.const_set(:Rails, rails)
|
63
|
-
|
64
|
-
configuration = Sevendigital::ClientConfiguration.new(conf_file)
|
65
|
-
configuration.api_url.should == 'test-yml-development.7digital.com'
|
66
|
-
Object.instance_eval{ remove_const :Rails }
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should use rails/config/sevendigital configuration as default rails settings" do
|
70
|
-
rails = OpenStruct.new
|
71
|
-
rails.root = Pathname(File.join(File.dirname(__FILE__),"data"))
|
72
|
-
Object.const_set(:Rails, rails)
|
73
|
-
|
74
|
-
configuration = Sevendigital::ClientConfiguration.new()
|
75
|
-
configuration.api_url.should == 'test-yml-rails-common.7digital.com'
|
76
|
-
Object.instance_eval{ remove_const :Rails }
|
77
|
-
end
|
78
|
-
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "ClientConfiguration" do
|
4
|
+
|
5
|
+
it "should initialize with default configuration" do
|
6
|
+
configuration = Sevendigital::ClientConfiguration.new
|
7
|
+
configuration.api_url.should == 'api.7digital.com'
|
8
|
+
configuration.api_version.should == '1.2'
|
9
|
+
configuration.media_api_url.should == 'media-eu.7digital.com'
|
10
|
+
configuration.media_api_version.should == 'media'
|
11
|
+
configuration.account_api_url.should == 'account.7digital.com'
|
12
|
+
configuration.account_api_version.should == 'web'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should initialize using hash" do
|
16
|
+
configuration = Sevendigital::ClientConfiguration.new(:api_url => "test-hash.7digital.com")
|
17
|
+
configuration.api_url.should == 'test-hash.7digital.com'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should initialize using OpenStruct object" do
|
21
|
+
configuration = Sevendigital::ClientConfiguration.new(OpenStruct.new(:api_url => "test-openstruct.7digital.com"))
|
22
|
+
configuration.api_url.should == 'test-openstruct.7digital.com'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should initialize using simple YAML file" do
|
26
|
+
configuration = Sevendigital::ClientConfiguration.new(File.join(File.dirname(__FILE__),"data", "configuration_override.yml"))
|
27
|
+
configuration.api_url.should == 'test-yml-simple.7digital.com'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should initialize mixing configuration file name and explicit hash override" do
|
31
|
+
conf_file = File.join(File.dirname(__FILE__),"data", "configuration_override.yml")
|
32
|
+
configuration = Sevendigital::ClientConfiguration.new(conf_file, :api_url => 'hash-override')
|
33
|
+
configuration.api_url.should == 'hash-override'
|
34
|
+
configuration.api_version.should == 'yml-simple'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should initialize mixing hash settings and configuration file override" do
|
38
|
+
conf_file = File.join(File.dirname(__FILE__),"data", "configuration_override.yml")
|
39
|
+
configuration = Sevendigital::ClientConfiguration.new({:api_url => 'hash-override', :xxx => 'yyy'}, conf_file)
|
40
|
+
configuration.api_url.should == 'test-yml-simple.7digital.com'
|
41
|
+
configuration.xxx.should == 'yyy'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should initialize mixing 2 explicit hash overrides" do
|
45
|
+
configuration = Sevendigital::ClientConfiguration.new( {:api_url => 'v1', :a => 'x'}, {:api_url => 'v2', :b => 'y'})
|
46
|
+
configuration.api_url.should == 'v2'
|
47
|
+
configuration.a.should == 'x'
|
48
|
+
configuration.b.should == 'y'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should use environment specific configuration file" do
|
52
|
+
conf_file = File.join(File.dirname(__FILE__),"data", "configuration_env_override.yml")
|
53
|
+
configuration = Sevendigital::ClientConfiguration.new(conf_file)
|
54
|
+
configuration.api_url.should == 'test-yml-common.7digital.com'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should use environment specific configuration file with environment specific settings" do
|
58
|
+
conf_file = File.join(File.dirname(__FILE__),"data", "configuration_env_override.yml")
|
59
|
+
|
60
|
+
rails = OpenStruct.new
|
61
|
+
rails.env = "development"
|
62
|
+
Object.const_set(:Rails, rails)
|
63
|
+
|
64
|
+
configuration = Sevendigital::ClientConfiguration.new(conf_file)
|
65
|
+
configuration.api_url.should == 'test-yml-development.7digital.com'
|
66
|
+
Object.instance_eval{ remove_const :Rails }
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should use rails/config/sevendigital configuration as default rails settings" do
|
70
|
+
rails = OpenStruct.new
|
71
|
+
rails.root = Pathname(File.join(File.dirname(__FILE__),"data"))
|
72
|
+
Object.const_set(:Rails, rails)
|
73
|
+
|
74
|
+
configuration = Sevendigital::ClientConfiguration.new()
|
75
|
+
configuration.api_url.should == 'test-yml-rails-common.7digital.com'
|
76
|
+
Object.instance_eval{ remove_const :Rails }
|
77
|
+
end
|
78
|
+
|
79
79
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -1,162 +1,162 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "Client" do
|
4
|
-
|
5
|
-
it "should not be verbose if not told anything" do
|
6
|
-
client = Sevendigital::Client.new
|
7
|
-
client.verbose?.should == false
|
8
|
-
client.very_verbose?.should == false
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should not be verbose if told to so" do
|
12
|
-
client = Sevendigital::Client.new(:verbose => false)
|
13
|
-
client.verbose?.should == false
|
14
|
-
client.very_verbose?.should == false
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should be verbose if told to be verbose in configuration" do
|
18
|
-
client = Sevendigital::Client.new(:verbose => true)
|
19
|
-
client.verbose?.should == true
|
20
|
-
client.very_verbose?.should == false
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should be very verbose if told to be very verbose in configruation" do
|
24
|
-
client = Sevendigital::Client.new(:verbose => :very_verbose)
|
25
|
-
client.verbose?.should == true
|
26
|
-
client.very_verbose?.should == true
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should be verbose if told so" do
|
30
|
-
client = Sevendigital::Client.new(:verbose => false)
|
31
|
-
client.configuration.verbose = true
|
32
|
-
client.verbose?.should == true
|
33
|
-
client.very_verbose?.should == false
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should provide selected properties as default parameters for all api requests" do
|
37
|
-
client = Sevendigital::Client.new(:page_size => 12345, :country => 'gb')
|
38
|
-
client.configuration.country = 'sk'
|
39
|
-
client.send(:default_parameters).should == {:page_size => 12345, :country => 'sk'}
|
40
|
-
end
|
41
|
-
|
42
|
-
it "create_api_request should merge method parameters and options with parameters taking preference" do
|
43
|
-
client = Sevendigital::Client.new
|
44
|
-
parameters = {:trackId => 1239, :releaseId => 456, :country => "CU"}
|
45
|
-
options = {:page => 1, :country => "US", :trackId => "SS"}
|
46
|
-
request = client.create_api_request(:GET, 'method', parameters, options)
|
47
|
-
request.parameters[:trackId].should == 1239
|
48
|
-
request.parameters[:releaseId].should == 456
|
49
|
-
request.parameters[:country].should == "CU"
|
50
|
-
request.parameters[:page].should == 1
|
51
|
-
request.parameters.keys.size.should == 4 # page_size == null
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
it "create_api_request should add default parameters to request" do
|
56
|
-
client = Sevendigital::Client.new
|
57
|
-
client.configuration.page_size = 100
|
58
|
-
client.configuration.shop_id = 200
|
59
|
-
request = client.create_api_request('method', {}, {})
|
60
|
-
|
61
|
-
request.parameters[:pageSize].should == 100;
|
62
|
-
request.parameters[:shopId].should == 200;
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should make an API call using API request created by the client itself " do
|
67
|
-
a_method_name = "method"
|
68
|
-
a_method_params = { :param1 => 1 }
|
69
|
-
an_http_method = :METHOD
|
70
|
-
|
71
|
-
an_api_response = stub(Sevendigital::ApiResponse)
|
72
|
-
an_api_request = stub(Sevendigital::ApiRequest)
|
73
|
-
|
74
|
-
client = Sevendigital::Client.new
|
75
|
-
mock_operator = mock(Sevendigital::ApiOperator)
|
76
|
-
client.stub!(:operator).and_return(mock_operator)
|
77
|
-
|
78
|
-
client.should_receive(:create_api_request).with(an_http_method, a_method_name, a_method_params, {}).and_return(an_api_request)
|
79
|
-
|
80
|
-
mock_operator.should_receive(:call_api).with(an_api_request).and_return(an_api_response)
|
81
|
-
|
82
|
-
response = client.make_api_request(an_http_method, a_method_name, a_method_params, {})
|
83
|
-
|
84
|
-
response.should == an_api_response
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should make a signed & secure API call" do
|
89
|
-
a_method_name = "method"
|
90
|
-
a_method_params = { :param1 => 1 }
|
91
|
-
an_http_method = :METHOD
|
92
|
-
a_token = "token"
|
93
|
-
|
94
|
-
an_api_response = "response"
|
95
|
-
|
96
|
-
client = Sevendigital::Client.new
|
97
|
-
mock_operator = mock(Sevendigital::ApiOperator)
|
98
|
-
client.stub!(:operator).and_return(mock_operator)
|
99
|
-
|
100
|
-
mock_operator.should_receive(:call_api) { |api_request|
|
101
|
-
api_request.api_method.should == a_method_name
|
102
|
-
api_request.http_method.should == an_http_method
|
103
|
-
api_request.requires_secure_connection?.should == true
|
104
|
-
api_request.requires_signature?.should == true
|
105
|
-
api_request.parameters.should == a_method_params
|
106
|
-
api_request.token.should == a_token
|
107
|
-
an_api_response
|
108
|
-
}
|
109
|
-
|
110
|
-
response = client.make_signed_api_request(an_http_method, a_method_name, a_method_params, {}, a_token)
|
111
|
-
|
112
|
-
response.should == an_api_response
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should get API host url for specific API service from configuration" do
|
117
|
-
|
118
|
-
client = Sevendigital::Client.new { |configuration|
|
119
|
-
configuration.media_api_url = "media-base.api.url"
|
120
|
-
configuration.media_api_version = "media-version"
|
121
|
-
}
|
122
|
-
|
123
|
-
client.api_host_and_version(:media).should == ["media-base.api.url", "media-version"]
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should get API host url for standard API service from configuration" do
|
128
|
-
|
129
|
-
client = Sevendigital::Client.new { |configuration|
|
130
|
-
configuration.api_url = "base.api.url"
|
131
|
-
configuration.api_version = "version"
|
132
|
-
}
|
133
|
-
|
134
|
-
client.send(:api_host_and_version).should == ["base.api.url", "version"]
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should provide initialized oauth consumer" do
|
139
|
-
|
140
|
-
configuration = Sevendigital::ClientConfiguration.new
|
141
|
-
configuration.oauth_consumer_key = "api_key"
|
142
|
-
configuration.oauth_consumer_secret = "secret"
|
143
|
-
configuration.account_api_url = "account.7d.com"
|
144
|
-
configuration.account_api_version = "mobile"
|
145
|
-
client = Sevendigital::Client.new(configuration)
|
146
|
-
|
147
|
-
consumer = client.oauth_consumer
|
148
|
-
consumer.authorize_path.should == "https://account.7d.com/mobile/oauth/authorise"
|
149
|
-
consumer.key.should == "api_key"
|
150
|
-
consumer.secret.should == "secret"
|
151
|
-
|
152
|
-
end
|
153
|
-
|
154
|
-
it "user_agent_info should contain app_name & version if specified" do
|
155
|
-
client = Sevendigital::Client.new(:app_name => "RSpec", :app_version => "0.0.7")
|
156
|
-
|
157
|
-
client.user_agent_info.should == "7digital Gem #{Sevendigital::VERSION}/RSpec 0.0.7"
|
158
|
-
|
159
|
-
end
|
160
|
-
|
161
|
-
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Client" do
|
4
|
+
|
5
|
+
it "should not be verbose if not told anything" do
|
6
|
+
client = Sevendigital::Client.new
|
7
|
+
client.verbose?.should == false
|
8
|
+
client.very_verbose?.should == false
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not be verbose if told to so" do
|
12
|
+
client = Sevendigital::Client.new(:verbose => false)
|
13
|
+
client.verbose?.should == false
|
14
|
+
client.very_verbose?.should == false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be verbose if told to be verbose in configuration" do
|
18
|
+
client = Sevendigital::Client.new(:verbose => true)
|
19
|
+
client.verbose?.should == true
|
20
|
+
client.very_verbose?.should == false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should be very verbose if told to be very verbose in configruation" do
|
24
|
+
client = Sevendigital::Client.new(:verbose => :very_verbose)
|
25
|
+
client.verbose?.should == true
|
26
|
+
client.very_verbose?.should == true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be verbose if told so" do
|
30
|
+
client = Sevendigital::Client.new(:verbose => false)
|
31
|
+
client.configuration.verbose = true
|
32
|
+
client.verbose?.should == true
|
33
|
+
client.very_verbose?.should == false
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should provide selected properties as default parameters for all api requests" do
|
37
|
+
client = Sevendigital::Client.new(:page_size => 12345, :country => 'gb')
|
38
|
+
client.configuration.country = 'sk'
|
39
|
+
client.send(:default_parameters).should == {:page_size => 12345, :country => 'sk'}
|
40
|
+
end
|
41
|
+
|
42
|
+
it "create_api_request should merge method parameters and options with parameters taking preference" do
|
43
|
+
client = Sevendigital::Client.new
|
44
|
+
parameters = {:trackId => 1239, :releaseId => 456, :country => "CU"}
|
45
|
+
options = {:page => 1, :country => "US", :trackId => "SS"}
|
46
|
+
request = client.create_api_request(:GET, 'method', parameters, options)
|
47
|
+
request.parameters[:trackId].should == 1239
|
48
|
+
request.parameters[:releaseId].should == 456
|
49
|
+
request.parameters[:country].should == "CU"
|
50
|
+
request.parameters[:page].should == 1
|
51
|
+
request.parameters.keys.size.should == 4 # page_size == null
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
it "create_api_request should add default parameters to request" do
|
56
|
+
client = Sevendigital::Client.new
|
57
|
+
client.configuration.page_size = 100
|
58
|
+
client.configuration.shop_id = 200
|
59
|
+
request = client.create_api_request('method', {}, {})
|
60
|
+
|
61
|
+
request.parameters[:pageSize].should == 100;
|
62
|
+
request.parameters[:shopId].should == 200;
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should make an API call using API request created by the client itself " do
|
67
|
+
a_method_name = "method"
|
68
|
+
a_method_params = { :param1 => 1 }
|
69
|
+
an_http_method = :METHOD
|
70
|
+
|
71
|
+
an_api_response = stub(Sevendigital::ApiResponse)
|
72
|
+
an_api_request = stub(Sevendigital::ApiRequest)
|
73
|
+
|
74
|
+
client = Sevendigital::Client.new
|
75
|
+
mock_operator = mock(Sevendigital::ApiOperator)
|
76
|
+
client.stub!(:operator).and_return(mock_operator)
|
77
|
+
|
78
|
+
client.should_receive(:create_api_request).with(an_http_method, a_method_name, a_method_params, {}).and_return(an_api_request)
|
79
|
+
|
80
|
+
mock_operator.should_receive(:call_api).with(an_api_request).and_return(an_api_response)
|
81
|
+
|
82
|
+
response = client.make_api_request(an_http_method, a_method_name, a_method_params, {})
|
83
|
+
|
84
|
+
response.should == an_api_response
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should make a signed & secure API call" do
|
89
|
+
a_method_name = "method"
|
90
|
+
a_method_params = { :param1 => 1 }
|
91
|
+
an_http_method = :METHOD
|
92
|
+
a_token = "token"
|
93
|
+
|
94
|
+
an_api_response = "response"
|
95
|
+
|
96
|
+
client = Sevendigital::Client.new
|
97
|
+
mock_operator = mock(Sevendigital::ApiOperator)
|
98
|
+
client.stub!(:operator).and_return(mock_operator)
|
99
|
+
|
100
|
+
mock_operator.should_receive(:call_api) { |api_request|
|
101
|
+
api_request.api_method.should == a_method_name
|
102
|
+
api_request.http_method.should == an_http_method
|
103
|
+
api_request.requires_secure_connection?.should == true
|
104
|
+
api_request.requires_signature?.should == true
|
105
|
+
api_request.parameters.should == a_method_params
|
106
|
+
api_request.token.should == a_token
|
107
|
+
an_api_response
|
108
|
+
}
|
109
|
+
|
110
|
+
response = client.make_signed_api_request(an_http_method, a_method_name, a_method_params, {}, a_token)
|
111
|
+
|
112
|
+
response.should == an_api_response
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should get API host url for specific API service from configuration" do
|
117
|
+
|
118
|
+
client = Sevendigital::Client.new { |configuration|
|
119
|
+
configuration.media_api_url = "media-base.api.url"
|
120
|
+
configuration.media_api_version = "media-version"
|
121
|
+
}
|
122
|
+
|
123
|
+
client.api_host_and_version(:media).should == ["media-base.api.url", "media-version"]
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should get API host url for standard API service from configuration" do
|
128
|
+
|
129
|
+
client = Sevendigital::Client.new { |configuration|
|
130
|
+
configuration.api_url = "base.api.url"
|
131
|
+
configuration.api_version = "version"
|
132
|
+
}
|
133
|
+
|
134
|
+
client.send(:api_host_and_version).should == ["base.api.url", "version"]
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should provide initialized oauth consumer" do
|
139
|
+
|
140
|
+
configuration = Sevendigital::ClientConfiguration.new
|
141
|
+
configuration.oauth_consumer_key = "api_key"
|
142
|
+
configuration.oauth_consumer_secret = "secret"
|
143
|
+
configuration.account_api_url = "account.7d.com"
|
144
|
+
configuration.account_api_version = "mobile"
|
145
|
+
client = Sevendigital::Client.new(configuration)
|
146
|
+
|
147
|
+
consumer = client.oauth_consumer
|
148
|
+
consumer.authorize_path.should == "https://account.7d.com/mobile/oauth/authorise"
|
149
|
+
consumer.key.should == "api_key"
|
150
|
+
consumer.secret.should == "secret"
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
it "user_agent_info should contain app_name & version if specified" do
|
155
|
+
client = Sevendigital::Client.new(:app_name => "RSpec", :app_version => "0.0.7")
|
156
|
+
|
157
|
+
client.user_agent_info.should == "7digital Gem #{Sevendigital::VERSION}/RSpec 0.0.7"
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
162
|
end
|