7digital 0.0.5 → 0.0.6

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