7digital 0.0.2 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +132 -5
- data/lib/sevendigital.rb +1 -2
- data/lib/sevendigital/api_operator.rb +103 -12
- data/lib/sevendigital/api_operator_cached.rb +14 -8
- data/lib/sevendigital/api_request.rb +50 -9
- data/lib/sevendigital/client.rb +51 -89
- data/lib/sevendigital/client_configuration.rb +86 -0
- data/lib/sevendigital/client_digestors.rb +79 -0
- data/lib/sevendigital/client_managers.rb +34 -0
- data/lib/sevendigital/digestion_tract/api_response_digestor.rb +8 -3
- data/lib/sevendigital/digestion_tract/artist_digestor.rb +1 -1
- data/lib/sevendigital/digestion_tract/basket_digestor.rb +18 -0
- data/lib/sevendigital/digestion_tract/basket_item_digestor.rb +25 -0
- data/lib/sevendigital/digestion_tract/chart_item_digestor.rb +1 -1
- data/lib/sevendigital/digestion_tract/digestor.rb +7 -3
- data/lib/sevendigital/digestion_tract/download_url_digestor.rb +19 -0
- data/lib/sevendigital/digestion_tract/format_digestor.rb +1 -1
- data/lib/sevendigital/digestion_tract/label_digestor.rb +1 -1
- data/lib/sevendigital/digestion_tract/locker_digestor.rb +17 -0
- data/lib/sevendigital/digestion_tract/locker_release_digestor.rb +19 -0
- data/lib/sevendigital/digestion_tract/locker_track_digestor.rb +21 -0
- data/lib/sevendigital/digestion_tract/oauth_access_token_digestor.rb +14 -0
- data/lib/sevendigital/digestion_tract/oauth_request_token_digestor.rb +14 -0
- data/lib/sevendigital/digestion_tract/pager_digestor.rb +1 -1
- data/lib/sevendigital/digestion_tract/price_digestor.rb +3 -3
- data/lib/sevendigital/digestion_tract/release_digestor.rb +1 -1
- data/lib/sevendigital/digestion_tract/tag_digestor.rb +22 -0
- data/lib/sevendigital/digestion_tract/track_digestor.rb +1 -1
- data/lib/sevendigital/management/artist_manager.rb +71 -34
- data/lib/sevendigital/management/basket_manager.rb +29 -0
- data/lib/sevendigital/management/manager.rb +1 -1
- data/lib/sevendigital/management/oauth_manager.rb +23 -0
- data/lib/sevendigital/management/release_manager.rb +7 -14
- data/lib/sevendigital/management/tag_manager.rb +11 -0
- data/lib/sevendigital/management/track_manager.rb +9 -9
- data/lib/sevendigital/management/user_manager.rb +51 -0
- data/lib/sevendigital/model/api_response.rb +19 -3
- data/lib/sevendigital/model/artist.rb +27 -9
- data/lib/sevendigital/model/basket.rb +16 -0
- data/lib/sevendigital/model/basket_item.rb +15 -0
- data/lib/sevendigital/model/download_url.rb +7 -0
- data/lib/sevendigital/model/format.rb +0 -2
- data/lib/sevendigital/model/label.rb +1 -3
- data/lib/sevendigital/model/locker.rb +5 -0
- data/lib/sevendigital/model/locker_release.rb +9 -0
- data/lib/sevendigital/model/locker_track.rb +9 -0
- data/lib/sevendigital/model/price.rb +0 -2
- data/lib/sevendigital/model/release.rb +22 -8
- data/lib/sevendigital/model/sevendigital_error.rb +9 -1
- data/lib/sevendigital/model/sevendigital_object.rb +16 -11
- data/lib/sevendigital/model/tag.rb +7 -0
- data/lib/sevendigital/model/track.rb +4 -4
- data/lib/sevendigital/model/user.rb +34 -0
- data/lib/sevendigital/pager.rb +8 -2
- data/lib/sevendigital/proxy_police.rb +5 -1
- data/lib/sevendigital/version.rb +5 -0
- data/spec/api_operator_cached_spec.rb +62 -7
- data/spec/api_operator_spec.rb +245 -21
- data/spec/api_request_spec.rb +20 -15
- data/spec/client_configuration_spec.rb +75 -0
- data/spec/client_spec.rb +126 -48
- data/spec/coverage/assets/0.3.9/app.js +66 -0
- data/spec/coverage/assets/0.3.9/fancybox/blank.gif +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_close.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_loading.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_nav_left.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_nav_right.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_shadow_e.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_shadow_n.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_shadow_ne.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_shadow_nw.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_shadow_s.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_shadow_se.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_shadow_sw.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_shadow_w.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_title_left.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_title_main.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_title_over.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancy_title_right.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancybox-x.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancybox-y.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/fancybox.png +0 -0
- data/spec/coverage/assets/0.3.9/fancybox/jquery.fancybox-1.3.1.css +363 -0
- data/spec/coverage/assets/0.3.9/fancybox/jquery.fancybox-1.3.1.pack.js +44 -0
- data/spec/coverage/assets/0.3.9/favicon.png +0 -0
- data/spec/coverage/assets/0.3.9/jquery-1.4.2.min.js +155 -0
- data/spec/coverage/assets/0.3.9/jquery.dataTables.min.js +152 -0
- data/spec/coverage/assets/0.3.9/jquery.timeago.js +141 -0
- data/spec/coverage/assets/0.3.9/jquery.url.js +174 -0
- data/spec/coverage/assets/0.3.9/loading.gif +0 -0
- data/spec/coverage/assets/0.3.9/magnify.png +0 -0
- data/spec/coverage/assets/0.3.9/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/spec/coverage/assets/0.3.9/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/spec/coverage/assets/0.3.9/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/spec/coverage/assets/0.3.9/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/spec/coverage/assets/0.3.9/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/spec/coverage/assets/0.3.9/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/spec/coverage/assets/0.3.9/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/spec/coverage/assets/0.3.9/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/spec/coverage/assets/0.3.9/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/spec/coverage/assets/0.3.9/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/spec/coverage/assets/0.3.9/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/spec/coverage/assets/0.3.9/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/spec/coverage/assets/0.3.9/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/spec/coverage/assets/0.3.9/smoothness/jquery-ui-1.8.4.custom.css +295 -0
- data/spec/coverage/assets/0.3.9/stylesheet.css +341 -0
- data/spec/coverage/index.html +43412 -0
- data/spec/coverage/resultset.yml +3251 -0
- data/spec/data/configuration_override.yml +2 -1
- data/spec/digestion_tract/api_response_digestor_spec.rb +15 -1
- data/spec/digestion_tract/artist_digestor_spec.rb +3 -3
- data/spec/digestion_tract/basket_digestor_spec.rb +32 -0
- data/spec/digestion_tract/basket_item_digestor_spec.rb +58 -0
- data/spec/digestion_tract/chart_digestor_spec.rb +2 -2
- data/spec/digestion_tract/download_url_digestor_spec.rb +41 -0
- data/spec/digestion_tract/format_digestor_spec.rb +2 -2
- data/spec/digestion_tract/label_digestor_spec.rb +2 -2
- data/spec/digestion_tract/locker_digestor_spec.rb +31 -0
- data/spec/digestion_tract/locker_release_digestor_spec.rb +71 -0
- data/spec/digestion_tract/locker_track_digestor_spec.rb +56 -0
- data/spec/digestion_tract/oauth_access_token_digestor_spec.rb +35 -0
- data/spec/digestion_tract/oauth_request_token_digestor_spec.rb +35 -0
- data/spec/digestion_tract/pager_digestor_spec.rb +2 -2
- data/spec/digestion_tract/price_digestor_spec.rb +21 -5
- data/spec/digestion_tract/release_digestor_spec.rb +2 -2
- data/spec/digestion_tract/tag_digestor_spec.rb +46 -0
- data/spec/digestion_tract/track_digestor_spec.rb +1 -1
- data/spec/management/artist_manager_spec.rb +46 -41
- data/spec/management/basket_manager_spec.rb +78 -0
- data/spec/management/oauth_manager_spec.rb +73 -0
- data/spec/management/release_manager_spec.rb +33 -74
- data/spec/management/tag_manager_spec.rb +34 -0
- data/spec/management/track_manager_spec.rb +42 -25
- data/spec/management/user_manager_spec.rb +163 -0
- data/spec/model/api_response_spec.rb +69 -2
- data/spec/model/artist_spec.rb +1 -26
- data/spec/model/basket_spec.rb +63 -0
- data/spec/model/coverage/assets/0.3.9/app.js +66 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/blank.gif +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_close.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_loading.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_nav_left.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_nav_right.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_shadow_e.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_shadow_n.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_shadow_ne.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_shadow_nw.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_shadow_s.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_shadow_se.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_shadow_sw.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_shadow_w.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_title_left.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_title_main.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_title_over.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancy_title_right.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancybox-x.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancybox-y.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/fancybox.png +0 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/jquery.fancybox-1.3.1.css +363 -0
- data/spec/model/coverage/assets/0.3.9/fancybox/jquery.fancybox-1.3.1.pack.js +44 -0
- data/spec/model/coverage/assets/0.3.9/favicon.png +0 -0
- data/spec/model/coverage/assets/0.3.9/jquery-1.4.2.min.js +155 -0
- data/spec/model/coverage/assets/0.3.9/jquery.dataTables.min.js +152 -0
- data/spec/model/coverage/assets/0.3.9/jquery.timeago.js +141 -0
- data/spec/model/coverage/assets/0.3.9/jquery.url.js +174 -0
- data/spec/model/coverage/assets/0.3.9/loading.gif +0 -0
- data/spec/model/coverage/assets/0.3.9/magnify.png +0 -0
- data/spec/model/coverage/assets/0.3.9/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/spec/model/coverage/assets/0.3.9/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/spec/model/coverage/assets/0.3.9/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/spec/model/coverage/assets/0.3.9/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/spec/model/coverage/assets/0.3.9/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/spec/model/coverage/assets/0.3.9/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/spec/model/coverage/assets/0.3.9/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/spec/model/coverage/assets/0.3.9/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/spec/model/coverage/assets/0.3.9/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/spec/model/coverage/assets/0.3.9/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/spec/model/coverage/assets/0.3.9/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/spec/model/coverage/assets/0.3.9/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/spec/model/coverage/assets/0.3.9/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/spec/model/coverage/assets/0.3.9/smoothness/jquery-ui-1.8.4.custom.css +295 -0
- data/spec/model/coverage/assets/0.3.9/stylesheet.css +341 -0
- data/spec/model/coverage/index.html +8637 -0
- data/spec/model/coverage/resultset.yml +642 -0
- data/spec/model/release_spec.rb +15 -14
- data/spec/model/sevendigital_object_spec.rb +74 -0
- data/spec/model/track_spec.rb +8 -4
- data/spec/model/user_spec.rb +98 -0
- data/spec/pager_spec.rb +2 -2
- data/spec/proxy_police_spec.rb +1 -1
- data/spec/spec_helper.rb +11 -3
- data/spec/test-xml/methods/artist/browse.xml +22 -0
- data/spec/test-xml/methods/artist/chart.xml +31 -0
- data/spec/test-xml/methods/basket/additem.xml +24 -0
- data/spec/test-xml/methods/basket/create.xml +11 -0
- data/spec/test-xml/methods/basket/index.xml +24 -0
- data/spec/test-xml/methods/basket/removeitem.xml +11 -0
- data/spec/test-xml/methods/oauth/accesstoken.xml +6 -0
- data/spec/test-xml/methods/oauth/requesttoken.xml +6 -0
- data/spec/test-xml/methods/tag/index.xml +17 -0
- data/spec/test-xml/methods/user/locker.xml +50 -0
- data/spec/test-xml/methods/user/purchase/item.xml +49 -0
- data/spec/test-xml/objects/basket.xml +22 -0
- data/spec/test-xml/objects/basket_item.xml +12 -0
- data/spec/test-xml/objects/basket_item_list.xml +26 -0
- data/spec/test-xml/objects/basket_item_list_empty.xml +2 -0
- data/spec/test-xml/objects/download_url.xml +8 -0
- data/spec/test-xml/objects/locker.xml +48 -0
- data/spec/test-xml/objects/locker_release.xml +41 -0
- data/spec/test-xml/objects/locker_release_list.xml +87 -0
- data/spec/test-xml/objects/locker_release_list_empty.xml +5 -0
- data/spec/test-xml/objects/locker_release_one_item_list.xml +43 -0
- data/spec/test-xml/objects/locker_track.xml +25 -0
- data/spec/test-xml/objects/locker_track_list.xml +26 -0
- data/spec/test-xml/objects/locker_track_list_empty.xml +2 -0
- data/spec/test-xml/objects/oauth_access_token.xml +4 -0
- data/spec/test-xml/objects/oauth_request_token.xml +4 -0
- data/spec/test-xml/objects/tag.xml +5 -0
- metadata +395 -13
- data/lib/sevendigital/peachy_patch.rb +0 -19
data/spec/api_operator_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
require 'ostruct'
|
3
|
+
require 'oauth'
|
3
4
|
|
4
5
|
describe "ApiOperator" do
|
5
6
|
|
@@ -17,7 +18,7 @@ describe "ApiOperator" do
|
|
17
18
|
|
18
19
|
end
|
19
20
|
|
20
|
-
it "should create request
|
21
|
+
it "should create http request uri based on api method and client configuration" do
|
21
22
|
|
22
23
|
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
23
24
|
|
@@ -25,26 +26,134 @@ describe "ApiOperator" do
|
|
25
26
|
|
26
27
|
uri.kind_of?(URI).should == true
|
27
28
|
|
28
|
-
uri.to_s.should =~ /http:\/\/base.api.url\/version\/api\/method
|
29
|
-
uri.to_s.should =~
|
30
|
-
uri.to_s.should =~
|
29
|
+
uri.to_s.should =~ /http:\/\/base.api.url\/version\/api\/method/
|
30
|
+
uri.to_s.should =~ /[\?\&]param1=value/
|
31
|
+
uri.to_s.should =~ /[\?\&]paramTwo=2/
|
31
32
|
|
32
33
|
end
|
33
34
|
|
34
|
-
it "should
|
35
|
-
@client.stub!(:country).and_return("sk")
|
35
|
+
it "should URL encode parameters accourding to OAuth spec" do
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
@api_operator.
|
37
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "a+b@c.d", :paramTwo => "<a b>"})
|
38
|
+
|
39
|
+
uri = @api_operator.create_request_uri(api_request)
|
40
|
+
|
41
|
+
uri.to_s.should =~ /[\?\&]param1=a%2Bb%40c.d/
|
42
|
+
uri.to_s.should =~ /[\?\&]paramTwo=%3Ca%20b%3E/
|
40
43
|
|
41
44
|
end
|
42
45
|
|
43
|
-
it "should
|
46
|
+
it "should create http GET request by default" do
|
44
47
|
|
45
|
-
|
48
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
49
|
+
|
50
|
+
client, request = @api_operator.create_http_request(api_request)
|
46
51
|
|
47
|
-
|
52
|
+
request.class.should == Net::HTTP::Get
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should create http POST request" do
|
57
|
+
|
58
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
59
|
+
api_request.http_method = :POST
|
60
|
+
|
61
|
+
client, request = @api_operator.create_http_request(api_request)
|
62
|
+
|
63
|
+
request.class.should == Net::HTTP::Post
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should create http DELETE request" do
|
68
|
+
|
69
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
70
|
+
api_request.http_method = :DELETE
|
71
|
+
|
72
|
+
client, request = @api_operator.create_http_request(api_request)
|
73
|
+
|
74
|
+
request.class.should == Net::HTTP::Delete
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should create http PUT request" do
|
79
|
+
|
80
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
81
|
+
api_request.http_method = :PUT
|
82
|
+
|
83
|
+
client, request = @api_operator.create_http_request(api_request)
|
84
|
+
|
85
|
+
request.class.should == Net::HTTP::Put
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should have empty body if no form parameters provided" do
|
90
|
+
|
91
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
92
|
+
|
93
|
+
client, request = @api_operator.create_http_request(api_request)
|
94
|
+
|
95
|
+
request.instance_variable_get("@body").empty?.should == true
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should set up any form parameters in body" do
|
100
|
+
|
101
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
102
|
+
api_request.form_parameters[:shop_id] = "1234"
|
103
|
+
api_request.form_parameters[:email] = "test@example.com"
|
104
|
+
api_request.form_parameters[:ignore] = nil
|
105
|
+
|
106
|
+
client, request = @api_operator.create_http_request(api_request)
|
107
|
+
|
108
|
+
request.instance_variable_get("@body").should == "shopId=1234&email=test%40example.com"
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should create HTTPS request uri based on api method that requires secure connection and client configuration" do
|
113
|
+
|
114
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
115
|
+
api_request.require_secure_connection
|
116
|
+
|
117
|
+
uri = @api_operator.create_request_uri(api_request)
|
118
|
+
|
119
|
+
uri.kind_of?(URI).should == true
|
120
|
+
|
121
|
+
uri.to_s.should =~ /https:\/\/base.api.url\/version\/api\/method/
|
122
|
+
uri.to_s.should =~ /[\?\&]param1=value/
|
123
|
+
uri.to_s.should =~ /[\?\&]paramTwo=2/
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should create http request uri based on api method for non standard api service" do
|
128
|
+
|
129
|
+
@client.should_receive(:api_host_and_version).with(:media).and_return(["media-base.api.url","media-version"])
|
130
|
+
|
131
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
132
|
+
api_request.api_service = :media
|
133
|
+
uri = @api_operator.create_request_uri(api_request)
|
134
|
+
|
135
|
+
uri.kind_of?(URI).should == true
|
136
|
+
|
137
|
+
uri.to_s.should =~ /http:\/\/media-base.api.url\/media-version\/api\/method/
|
138
|
+
uri.to_s.should =~ /[\?\&]param1=value/
|
139
|
+
uri.to_s.should =~ /[\?\&]paramTwo=2/
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should make HTTP request and get http response" do
|
144
|
+
|
145
|
+
http_response = fake_api_response
|
146
|
+
|
147
|
+
@stub_http_request = stub(Net::HTTP::Get)
|
148
|
+
@stub_http_client = stub(Net::HTTP)
|
149
|
+
|
150
|
+
@api_operator.should_receive(:create_http_request).with(@stub_api_request).and_return([@stub_http_client, @stub_http_request])
|
151
|
+
|
152
|
+
@stub_http_client.should_receive(:request).with(@stub_http_request).and_return(http_response)
|
153
|
+
|
154
|
+
response = @api_operator.make_http_request(@stub_api_request)
|
155
|
+
|
156
|
+
response.should == http_response
|
48
157
|
|
49
158
|
end
|
50
159
|
|
@@ -53,7 +162,20 @@ describe "ApiOperator" do
|
|
53
162
|
http_response = fake_api_response
|
54
163
|
digested_response = fake_digested_response
|
55
164
|
|
56
|
-
|
165
|
+
@client.api_response_digestor.should_receive(:from_http_response).with(http_response).and_return(digested_response)
|
166
|
+
|
167
|
+
response = @api_operator.digest_http_response(http_response)
|
168
|
+
|
169
|
+
response.should == digested_response
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should call API by making an http request and digesting the response" do
|
174
|
+
|
175
|
+
http_response = fake_api_response
|
176
|
+
digested_response = fake_digested_response
|
177
|
+
|
178
|
+
@api_operator.should_receive(:make_http_request).and_return(http_response)
|
57
179
|
|
58
180
|
@client.api_response_digestor.should_receive(:from_http_response).with(http_response).and_return(digested_response)
|
59
181
|
|
@@ -65,20 +187,116 @@ describe "ApiOperator" do
|
|
65
187
|
|
66
188
|
it "should throw an exception if response is not ok" do
|
67
189
|
|
68
|
-
Net::HTTP.stub(:get_response).and_return(fake_api_response)
|
69
190
|
failed_response = fake_digested_response(false)
|
70
|
-
failed_response.stub!(:error_code).and_return(
|
191
|
+
failed_response.stub!(:error_code).and_return(4000)
|
71
192
|
failed_response.stub!(:error_message).and_return("error")
|
72
|
-
|
193
|
+
@api_operator.should_receive(:make_http_request).and_return(fake_api_response)
|
194
|
+
@client.api_response_digestor.stub!(:from_http_response).and_return(failed_response)
|
195
|
+
|
196
|
+
running { @api_operator.call_api(@stub_api_request) }.should raise_error(Sevendigital::SevendigitalError) { |error|
|
197
|
+
error.error_code.should == 4000
|
198
|
+
error.error_message.should == "error"
|
199
|
+
}
|
200
|
+
|
201
|
+
end
|
73
202
|
|
74
|
-
|
203
|
+
it "should create a 2-legged signed HTTP request" do
|
204
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
205
|
+
api_request.require_signature
|
206
|
+
http_client, http_request = @api_operator.create_http_request(api_request)
|
207
|
+
http_client.use_ssl?.should == false
|
208
|
+
http_request.path.should =~ /api\/method/
|
209
|
+
http_request.path.should =~ /param1=value/
|
210
|
+
http_request["Authorization"].should =~ /OAuth oauth_consumer_key="oauth_consumer_key"/
|
211
|
+
http_request["Authorization"].should =~ / oauth_signature=/
|
212
|
+
# http_request["Authorization"].should !=~ / oauth_token="token"/
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should create a 3-legged signed HTTP request" do
|
216
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
217
|
+
api_request.require_signature
|
218
|
+
api_request.token = OAuth::AccessToken.new(@client.oauth_consumer, "token", "secret")
|
219
|
+
http_client, http_request = @api_operator.create_http_request(api_request)
|
220
|
+
http_client.use_ssl?.should == false
|
221
|
+
http_request.path.should =~ /api\/method/
|
222
|
+
http_request.path.should =~ /param1=value/
|
223
|
+
http_request["Authorization"].should =~ /OAuth oauth_consumer_key="oauth_consumer_key"/
|
224
|
+
http_request["Authorization"].should =~ / oauth_signature=/
|
225
|
+
http_request["Authorization"].should =~ / oauth_token="token"/
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should create a 3-legged signed HTTPS request" do
|
229
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
230
|
+
api_request.require_signature
|
231
|
+
api_request.require_secure_connection
|
232
|
+
api_request.token = OAuth::AccessToken.new(@client.oauth_consumer, "token", "secret")
|
233
|
+
http_client, http_request = @api_operator.create_http_request(api_request)
|
234
|
+
http_client.inspect.should =~ /base\.api\.url:443/
|
235
|
+
http_client.use_ssl?.should == true
|
236
|
+
http_client.verify_mode.should == OpenSSL::SSL::VERIFY_NONE
|
237
|
+
http_request.path.should =~ /api\/method/
|
238
|
+
http_request.path.should =~ /param1=value/
|
239
|
+
http_request["Authorization"].should =~ /OAuth oauth_consumer_key="oauth_consumer_key"/
|
240
|
+
http_request["Authorization"].should =~ / oauth_signature=/
|
241
|
+
http_request["Authorization"].should =~ / oauth_token="token"/
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should create a standard HTTP request" do
|
245
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
246
|
+
http_client, http_request = @api_operator.create_http_request(api_request)
|
247
|
+
http_client.inspect.should =~ /base\.api\.url:80/
|
248
|
+
http_client.use_ssl?.should == false
|
249
|
+
http_request.path.should =~ /api\/method/
|
250
|
+
http_request.path.should =~ /param1=value/
|
251
|
+
http_request.path.should =~ /oauth_consumer_key=oauth_consumer_key/
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should add custom user agent info to created HTTP request" do
|
255
|
+
|
256
|
+
@client.stub!(:user_agent_info).and_return("7digital Gem")
|
257
|
+
|
258
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
259
|
+
http_client, http_request = @api_operator.create_http_request(api_request)
|
260
|
+
http_request["User-agent"].should =~ /7digital Gem/
|
261
|
+
end
|
262
|
+
|
263
|
+
it "get_request_uri should return oauth sign URI if api request requires signature" do
|
264
|
+
|
265
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
266
|
+
api_request.token = OAuth::AccessToken.new(nil, "token", "token_secret")
|
267
|
+
api_request.require_signature
|
268
|
+
api_request.require_secure_connection
|
269
|
+
signed_uri = @api_operator.get_request_uri(api_request)
|
270
|
+
|
271
|
+
signed_uri.should =~ /oauth_signature=/
|
272
|
+
signed_uri.should =~ /oauth_consumer_key=oauth_consumer_key&/
|
273
|
+
signed_uri.should =~ /oauth_token=token&/
|
274
|
+
signed_uri.should =~ /https:\/\/base.api.url\/version\/api\/method/
|
275
|
+
end
|
276
|
+
|
277
|
+
it "get_request_uri should return simple request URI if api request does not require signature" do
|
278
|
+
|
279
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
280
|
+
signed_uri = @api_operator.get_request_uri(api_request)
|
281
|
+
|
282
|
+
signed_uri.match(/oauth_signature=/).should == nil
|
283
|
+
signed_uri.should =~ /oauth_consumer_key=oauth_consumer_key/
|
284
|
+
signed_uri.should =~ /http:\/\/base.api.url\/version\/api\/method/
|
285
|
+
end
|
286
|
+
|
287
|
+
it "get_request_uri should return secure request URI if api request does not require signature" do
|
288
|
+
|
289
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
290
|
+
api_request.require_secure_connection
|
291
|
+
signed_uri = @api_operator.get_request_uri(api_request)
|
75
292
|
|
293
|
+
signed_uri.match(/oauth_signature=/).should == nil
|
294
|
+
signed_uri.should =~ /oauth_consumer_key=oauth_consumer_key/
|
295
|
+
signed_uri.should =~ /https:\/\/base.api.url\/version\/api\/method/
|
76
296
|
end
|
77
297
|
|
78
298
|
def test_configuration
|
79
299
|
configuration = OpenStruct.new
|
80
|
-
configuration.api_url = "base.api.url"
|
81
|
-
configuration.api_version = "version"
|
82
300
|
configuration.oauth_consumer_key = "oauth_consumer_key"
|
83
301
|
return configuration
|
84
302
|
end
|
@@ -96,10 +314,13 @@ describe "ApiOperator" do
|
|
96
314
|
def stub_api_client(configuration, response_digestor)
|
97
315
|
@client = stub(Sevendigital::Client)
|
98
316
|
@client.stub!(:configuration).and_return(configuration)
|
317
|
+
@client.stub!(:oauth_consumer).and_return(OAuth::Consumer.new( configuration.oauth_consumer_key, configuration.oauth_consumer_secret))
|
99
318
|
@client.stub!(:api_response_digestor).and_return(response_digestor)
|
100
|
-
@client.stub!(:
|
319
|
+
@client.stub!(:default_parameters).and_return({:country => 'sk'})
|
320
|
+
@client.stub!(:user_agent_info).and_return("7digital")
|
101
321
|
@client.stub!(:verbose?).and_return(false)
|
102
322
|
@client.stub!(:very_verbose?).and_return(false)
|
323
|
+
@client.stub!(:api_host_and_version).and_return(["base.api.url","version"])
|
103
324
|
|
104
325
|
end
|
105
326
|
|
@@ -107,7 +328,10 @@ def stub_api_request
|
|
107
328
|
api_request = stub(Sevendigital::ApiRequest)
|
108
329
|
|
109
330
|
api_request.stub!(:parameters).and_return({})
|
331
|
+
api_request.stub!(:api_service).and_return(nil)
|
110
332
|
api_request.stub!(:api_method).and_return("m")
|
333
|
+
api_request.stub!(:requires_signature?).and_return(false)
|
334
|
+
api_request.stub!(:requires_secure_connection?).and_return(false)
|
111
335
|
api_request.stub!(:ensure_country_is_set)
|
112
336
|
return api_request
|
113
337
|
end
|
data/spec/api_request_spec.rb
CHANGED
@@ -1,26 +1,31 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe "ApiRequest" do
|
4
4
|
|
5
|
-
it "should
|
5
|
+
it "should always provide selected parameters in 7digital API format" do
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
request.parameters[:page].should ==
|
14
|
-
request.parameters.
|
7
|
+
request = Sevendigital::ApiRequest.new('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
|
15
20
|
|
16
21
|
end
|
17
22
|
|
18
|
-
it "should
|
23
|
+
it "should not contain nil parameters" do
|
19
24
|
|
20
|
-
request = Sevendigital::ApiRequest.new('method', {
|
21
|
-
request.parameters[:
|
22
|
-
request.parameters
|
25
|
+
request = Sevendigital::ApiRequest.new('method', {:key1 => "value", :key2 => nil})
|
26
|
+
request.parameters[:key1].should == "value"
|
27
|
+
request.parameters.has_key?(:key2).should == false
|
23
28
|
|
24
|
-
|
29
|
+
end
|
25
30
|
|
26
31
|
end
|
@@ -0,0 +1,75 @@
|
|
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
|
+
puts conf_file
|
60
|
+
Object.const_set(:RAILS_ENV, "development")
|
61
|
+
configuration = Sevendigital::ClientConfiguration.new(conf_file)
|
62
|
+
configuration.api_url.should == 'test-yml-development.7digital.com'
|
63
|
+
Object.instance_eval{ remove_const :RAILS_ENV }
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should use rails/config/sevendigital configuration as default rails settings" do
|
67
|
+
rails_root = File.join(File.dirname(__FILE__),"data")
|
68
|
+
puts rails_root
|
69
|
+
Object.const_set(:RAILS_ROOT, rails_root)
|
70
|
+
configuration = Sevendigital::ClientConfiguration.new()
|
71
|
+
configuration.api_url.should == 'test-yml-rails-common.7digital.com'
|
72
|
+
Object.instance_eval{ remove_const :RAILS_ROOT }
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|