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,31 +1,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', {
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', {:key1 => "value", :key2 => nil})
26
- request.parameters[:key1].should == "value"
27
- request.parameters.has_key?(:key2).should == false
28
-
29
- end
30
-
31
- end
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
+ end
@@ -1,75 +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
-
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
75
  end
data/spec/client_spec.rb CHANGED
@@ -1,154 +1,163 @@
1
- require "spec_helper"
2
-
3
- describe "Client" do
4
-
5
- it "should not be verbose if not told to so" do
6
- client = Sevendigital::Client.new
7
- client.verbose?.should == false
8
- client.very_verbose?.should == false
9
- end
10
-
11
- it "should be verbose if told to be verbose in configuration" do
12
- client = Sevendigital::Client.new(:verbose => true)
13
- client.verbose?.should == true
14
- client.very_verbose?.should == false
15
- end
16
-
17
- it "should be very verbose if told to be very verbose in configruation" do
18
- client = Sevendigital::Client.new(:verbose => :very_verbose)
19
- client.verbose?.should == true
20
- client.very_verbose?.should == true
21
- end
22
-
23
- it "should be verbose if told so" do
24
- client = Sevendigital::Client.new(:verbose => false)
25
- client.configuration.verbose = true
26
- client.verbose?.should == true
27
- client.very_verbose?.should == false
28
- end
29
-
30
- it "should provide selected properties as default parameters for all api requests" do
31
- client = Sevendigital::Client.new(:page_size => 12345, :country => 'gb')
32
- client.configuration.country = 'sk'
33
- client.default_parameters.should == {:page_size => 12345, :country => 'sk'}
34
- end
35
-
36
- it "create_api_request should merge method parameters and options with parameters taking preference" do
37
- client = Sevendigital::Client.new
38
- parameters = {:trackId => 1239, :releaseId => 456, :country => "CU"}
39
- options = {:page => 1, :country => "US", :trackId => "SS"}
40
- request = client.create_api_request('method', parameters, options)
41
- request.parameters[:trackId].should == 1239
42
- request.parameters[:releaseId].should == 456
43
- request.parameters[:country].should == "CU"
44
- request.parameters[:page].should == 1
45
- puts request.parameters.inspect
46
- request.parameters.keys.size.should == 4 # page_size == null
47
-
48
- end
49
-
50
- it "create_api_request should add default parameters to request" do
51
- client = Sevendigital::Client.new
52
- client.configuration.page_size = 100
53
- client.configuration.shop_id = 200
54
- request = client.create_api_request('method', {}, {})
55
-
56
- request.parameters[:pageSize].should == 100;
57
- request.parameters[:shopId].should == 200;
58
-
59
- end
60
-
61
- it "should make an API call using API request created by the client itself " do
62
- a_method_name = "method"
63
- a_method_params = { :param1 => 1 }
64
-
65
- an_api_response = stub(Sevendigital::ApiResponse)
66
- an_api_request = stub(Sevendigital::ApiRequest)
67
-
68
- client = Sevendigital::Client.new
69
- mock_operator = mock(Sevendigital::ApiOperator)
70
- client.stub!(:operator).and_return(mock_operator)
71
-
72
- client.should_receive(:create_api_request).with(a_method_name, a_method_params, {}).and_return(an_api_request)
73
-
74
- mock_operator.should_receive(:call_api).with(an_api_request).and_return(an_api_response)
75
-
76
- response = client.make_api_request(a_method_name, a_method_params, {})
77
-
78
- response.should == an_api_response
79
-
80
- end
81
-
82
- it "should make a signed & secure API call" do
83
- a_method_name = "method"
84
- a_method_params = { :param1 => 1 }
85
- a_token = "token"
86
-
87
- an_api_response = "response"
88
-
89
- client = Sevendigital::Client.new
90
- mock_operator = mock(Sevendigital::ApiOperator)
91
- client.stub!(:operator).and_return(mock_operator)
92
-
93
- mock_operator.should_receive(:call_api) { |api_request|
94
- api_request.api_method.should == a_method_name
95
- api_request.requires_secure_connection?.should == true
96
- api_request.requires_signature?.should == true
97
- api_request.parameters.should == a_method_params
98
- api_request.token.should == a_token
99
- an_api_response
100
- }
101
-
102
- response = client.make_signed_api_request(a_method_name, a_method_params, {}, a_token)
103
-
104
- response.should == an_api_response
105
-
106
- end
107
-
108
- it "should get API host url for specific API service from configuration" do
109
-
110
- client = Sevendigital::Client.new { |configuration|
111
- configuration.media_api_url = "media-base.api.url"
112
- configuration.media_api_version = "media-version"
113
- }
114
-
115
- client.api_host_and_version(:media).should == ["media-base.api.url", "media-version"]
116
-
117
- end
118
-
119
- it "should get API host url for standard API service from configuration" do
120
-
121
- client = Sevendigital::Client.new { |configuration|
122
- configuration.api_url = "base.api.url"
123
- configuration.api_version = "version"
124
- }
125
-
126
- client.api_host_and_version.should == ["base.api.url", "version"]
127
-
128
- end
129
-
130
- it "should provide initialized oauth consumer" do
131
-
132
- configuration = Sevendigital::ClientConfiguration.new
133
- configuration.oauth_consumer_key = "api_key"
134
- configuration.oauth_consumer_secret = "secret"
135
- configuration.account_api_url = "account.7d.com"
136
- configuration.account_api_version = "mobile"
137
- client = Sevendigital::Client.new(configuration)
138
-
139
- consumer = client.oauth_consumer
140
- consumer.authorize_path.should == "https://account.7d.com/mobile/oauth/authorise"
141
- consumer.key.should == "api_key"
142
- consumer.secret.should == "secret"
143
-
144
- end
145
-
146
- it "user_agent_info should contain app_name & version if specified" do
147
- client = Sevendigital::Client.new(:app_name => "RSpec", :app_version => "0.0.7")
148
-
149
- client.user_agent_info.should == "7digital Gem #{Sevendigital::VERSION}/RSpec 0.0.7"
150
-
151
- end
152
-
153
-
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
+ puts request.parameters.inspect
52
+ request.parameters.keys.size.should == 4 # page_size == null
53
+
54
+ end
55
+
56
+ it "create_api_request should add default parameters to request" do
57
+ client = Sevendigital::Client.new
58
+ client.configuration.page_size = 100
59
+ client.configuration.shop_id = 200
60
+ request = client.create_api_request('method', {}, {})
61
+
62
+ request.parameters[:pageSize].should == 100;
63
+ request.parameters[:shopId].should == 200;
64
+
65
+ end
66
+
67
+ it "should make an API call using API request created by the client itself " do
68
+ a_method_name = "method"
69
+ a_method_params = { :param1 => 1 }
70
+ an_http_method = :METHOD
71
+
72
+ an_api_response = stub(Sevendigital::ApiResponse)
73
+ an_api_request = stub(Sevendigital::ApiRequest)
74
+
75
+ client = Sevendigital::Client.new
76
+ mock_operator = mock(Sevendigital::ApiOperator)
77
+ client.stub!(:operator).and_return(mock_operator)
78
+
79
+ client.should_receive(:create_api_request).with(an_http_method, a_method_name, a_method_params, {}).and_return(an_api_request)
80
+
81
+ mock_operator.should_receive(:call_api).with(an_api_request).and_return(an_api_response)
82
+
83
+ response = client.make_api_request(an_http_method, a_method_name, a_method_params, {})
84
+
85
+ response.should == an_api_response
86
+
87
+ end
88
+
89
+ it "should make a signed & secure API call" do
90
+ a_method_name = "method"
91
+ a_method_params = { :param1 => 1 }
92
+ an_http_method = :METHOD
93
+ a_token = "token"
94
+
95
+ an_api_response = "response"
96
+
97
+ client = Sevendigital::Client.new
98
+ mock_operator = mock(Sevendigital::ApiOperator)
99
+ client.stub!(:operator).and_return(mock_operator)
100
+
101
+ mock_operator.should_receive(:call_api) { |api_request|
102
+ api_request.api_method.should == a_method_name
103
+ api_request.http_method.should == an_http_method
104
+ api_request.requires_secure_connection?.should == true
105
+ api_request.requires_signature?.should == true
106
+ api_request.parameters.should == a_method_params
107
+ api_request.token.should == a_token
108
+ an_api_response
109
+ }
110
+
111
+ response = client.make_signed_api_request(an_http_method, a_method_name, a_method_params, {}, a_token)
112
+
113
+ response.should == an_api_response
114
+
115
+ end
116
+
117
+ it "should get API host url for specific API service from configuration" do
118
+
119
+ client = Sevendigital::Client.new { |configuration|
120
+ configuration.media_api_url = "media-base.api.url"
121
+ configuration.media_api_version = "media-version"
122
+ }
123
+
124
+ client.api_host_and_version(:media).should == ["media-base.api.url", "media-version"]
125
+
126
+ end
127
+
128
+ it "should get API host url for standard API service from configuration" do
129
+
130
+ client = Sevendigital::Client.new { |configuration|
131
+ configuration.api_url = "base.api.url"
132
+ configuration.api_version = "version"
133
+ }
134
+
135
+ client.send(:api_host_and_version).should == ["base.api.url", "version"]
136
+
137
+ end
138
+
139
+ it "should provide initialized oauth consumer" do
140
+
141
+ configuration = Sevendigital::ClientConfiguration.new
142
+ configuration.oauth_consumer_key = "api_key"
143
+ configuration.oauth_consumer_secret = "secret"
144
+ configuration.account_api_url = "account.7d.com"
145
+ configuration.account_api_version = "mobile"
146
+ client = Sevendigital::Client.new(configuration)
147
+
148
+ consumer = client.oauth_consumer
149
+ consumer.authorize_path.should == "https://account.7d.com/mobile/oauth/authorise"
150
+ consumer.key.should == "api_key"
151
+ consumer.secret.should == "secret"
152
+
153
+ end
154
+
155
+ it "user_agent_info should contain app_name & version if specified" do
156
+ client = Sevendigital::Client.new(:app_name => "RSpec", :app_version => "0.0.7")
157
+
158
+ client.user_agent_info.should == "7digital Gem #{Sevendigital::VERSION}/RSpec 0.0.7"
159
+
160
+ end
161
+
162
+
154
163
  end