7digital 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
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
data/README.rdoc CHANGED
@@ -1,136 +1,136 @@
1
- =Ruby wrapper for 7digital API
2
-
3
- This is a ruby wrapper for the 7digital API.
4
-
5
- ==About 7digital
6
-
7
- 7digital.com is an online music store operating in over 16 countries and offering more than 11 million high quality DRM free MP3s (320kbps) from all major labels and wide range of idependent labels and distributors. 7digital API will give you access to the full catalogue including high quality album art, 30s preview clips for all tracks, commissions on sales, integrated purchasing and full length streaming. More details at http://developer.7digital.net
8
-
9
- ==Installation
10
-
11
- gem install 7digital
12
-
13
- ==Quick start example
14
-
15
-
16
- require "sevendigital"
17
- api_client = Sevendigital::Client.new(:oauth_consumer_key => "YOUR_KEY_HERE", :country => "GB")
18
- an_artist = api_client.artist.search("radiohead").first
19
- a_release = an_artist.releases(:page_size=>100).sort_by{|release| release.year}.last
20
- puts "the latest #{an_artist.name} release is #{a_release.title} from #{a_release.year}"
21
- puts "go and buy it at #{a_release.url} !"
22
-
23
- ==Usage details
24
-
25
- ===Initializing & configuring an API Client
26
-
27
- To use the wrapper and access the 7digital API you need a configured instance of Sevendigital::Client. Create one using the standard new method:
28
-
29
- client = Sevendigital::Client.new
30
-
31
- This will get you an API client configured with default settings. At very least before making any API calls you will need to update the configuration with your own API key. You can adjust the client's configuration in several ways:
32
-
33
- 1. In Rails app you can put _sevendigital.yml_ inside your app's config dir and this will be automatically picked up (for a template please see the examples directory)
34
-
35
- 2. You can provide a custom location of configuration file when instantiating a client
36
-
37
- client = Sevendigital::Client.new("dir/subdir/my_7d_configuration.yml")
38
- 3. You can supply a hash of configuration settings when instantiating a client
39
-
40
- client = Sevendigital::Client.new(:oauth_consumer_key => "YOUR_KEY_HERE", :country => "GB")
41
- 4. You can update the configuration in block whilst instantiating a client
42
-
43
- client = Sevendigital::Client.new { |config|
44
- config.oauth_consumer_key => "YOUR_KEY_HERE"
45
- config.verbose => true
46
- }
47
-
48
- You can also combine all of the above (if the same setting is specified multiple times the last one will be applied)
49
- An extreme example:
50
-
51
- client = Sevendigital::Client.new("7digital_default_settings.yml", :oauth_consumer_key => "MY_OTHER_KEY") { |conf|
52
- conf.country = "SE"
53
- conf.oauth_consumer_key = "ACTUALLY_USE_THIS_KEY"
54
- }
55
-
56
- ===Using the client
57
-
58
- List of all available API methods and their return types
59
-
60
- ----
61
-
62
- Provided by Sevendigital::ArtistManager :
63
-
64
- client.artist.*get_details*(artist_id, options={}) => Sevendigital::Artist
65
-
66
- client.artist.*get_releases*(artist_id, options={}) => [ Sevendigital::Release ]
67
-
68
- client.artist.*get_similar*(artist_id, options={}) => [ Sevendigital::Artist ]
69
-
70
- client.artist.*get_top_by_tag*(tags, options={}) => [ Sevendigital::Artist ]
71
-
72
- client.artist.*get_top_tracks*(artist_id, options={}) => [ Sevendigital::Track ]
73
-
74
- client.artist.*search*(query, options={}) => [ Sevendigital::Artist ]
75
-
76
- ----
77
-
78
- Provided by Sevendigital::ReleaseManager :
79
-
80
- client.release.*get_details*(release_id, options = {}) => Sevendigital::Release
81
-
82
- client.release.*get_tracks*(release_id, options = {}) => [ Sevendigital::Track ]
83
-
84
- client.release.*get_chart*(options={}) => [ Sevendigital::ChartItem ]
85
-
86
- client.release.*get_by_date*(from_date = nil, to_date = nil, options = {}) => [ Sevendigital::Release ]
87
-
88
- client.release.*get_recommendations*(release_id, options = {}) => [ Sevendigital::Release ]
89
-
90
- client.release.*get_top_by_tag*(tags, options = {}) => [ Sevendigital::Release ]
91
-
92
- client.release.*search*(query, options={}) => [ Sevendigital::Release ]
93
-
94
- ----
95
-
96
- client.track.*get_details*(id, options={}) => Sevendigital::Track
97
-
98
- client.track.*get_details_from_release*(track_id, release_id, options={}) => Sevendigital::Track
99
-
100
- client.track.*get_chart*(options={}) => [ Sevendigital::ChartItem ]
101
-
102
- client.track.*build_preview_url*(id, options={}) => String
103
-
104
- client.track.*search*(query, options={}) => [ Sevendigital::Track ]
105
-
106
- ---
107
-
108
- client.basket.*get*(basket_id, options={}) => Sevendigital::Basket
109
-
110
- client.basket.*create*(options={}) => Sevendigital::Basket
111
-
112
- client.basket.*add_item*(basket_id, release_id, track_id=nil, options={}) => Sevendigital::Basket
113
-
114
- client.basket.*remove_item*(basket_id, item_id, options={}) => Sevendigital::Basket
115
-
116
- ---
117
-
118
- client.oauth.*get_request_token* => OAuth::RequestToken
119
-
120
- client.oauth.*get_access_token*(request_token) => OAuth::AccessToken
121
-
122
- ---
123
-
124
- client.user.*login*(access_token) => Sevendigital::User
125
-
126
- client.user.*authenticate*(email, password) => Sevendigital::User
127
-
128
- client.user.*get_locker*(token, options={}) => Sevendgital::Locker
129
-
130
- client.user.*purchase*(release_id, track_id, price, token, options={}) => Sevendgital::Locker
131
-
132
- client.user.*get_stream_track_url*(release_id, track_id, token, options={}) => String
133
-
134
- client.user.*get_add_card_url*(return_url, token, options={}) => String
135
-
136
-
1
+ =Ruby wrapper for 7digital API
2
+
3
+ This is a ruby wrapper for the 7digital API.
4
+
5
+ ==About 7digital
6
+
7
+ 7digital.com is an online music store operating in over 16 countries and offering more than 11 million high quality DRM free MP3s (320kbps) from all major labels and wide range of idependent labels and distributors. 7digital API will give you access to the full catalogue including high quality album art, 30s preview clips for all tracks, commissions on sales, integrated purchasing and full length streaming. More details at http://developer.7digital.net
8
+
9
+ ==Installation
10
+
11
+ gem install 7digital
12
+
13
+ ==Quick start example
14
+
15
+
16
+ require "sevendigital"
17
+ api_client = Sevendigital::Client.new(:oauth_consumer_key => "YOUR_KEY_HERE", :country => "GB")
18
+ an_artist = api_client.artist.search("radiohead").first
19
+ a_release = an_artist.releases(:page_size=>100).sort_by{|release| release.year}.last
20
+ puts "the latest #{an_artist.name} release is #{a_release.title} from #{a_release.year}"
21
+ puts "go and buy it at #{a_release.url} !"
22
+
23
+ ==Usage details
24
+
25
+ ===Initializing & configuring an API Client
26
+
27
+ To use the wrapper and access the 7digital API you need a configured instance of Sevendigital::Client. Create one using the standard new method:
28
+
29
+ client = Sevendigital::Client.new
30
+
31
+ This will get you an API client configured with default settings. At very least before making any API calls you will need to update the configuration with your own API key. You can adjust the client's configuration in several ways:
32
+
33
+ 1. In Rails app you can put _sevendigital.yml_ inside your app's config dir and this will be automatically picked up (for a template please see the examples directory)
34
+
35
+ 2. You can provide a custom location of configuration file when instantiating a client
36
+
37
+ client = Sevendigital::Client.new("dir/subdir/my_7d_configuration.yml")
38
+ 3. You can supply a hash of configuration settings when instantiating a client
39
+
40
+ client = Sevendigital::Client.new(:oauth_consumer_key => "YOUR_KEY_HERE", :country => "GB")
41
+ 4. You can update the configuration in block whilst instantiating a client
42
+
43
+ client = Sevendigital::Client.new { |config|
44
+ config.oauth_consumer_key => "YOUR_KEY_HERE"
45
+ config.verbose => true
46
+ }
47
+
48
+ You can also combine all of the above (if the same setting is specified multiple times the last one will be applied)
49
+ An extreme example:
50
+
51
+ client = Sevendigital::Client.new("7digital_default_settings.yml", :oauth_consumer_key => "MY_OTHER_KEY") { |conf|
52
+ conf.country = "SE"
53
+ conf.oauth_consumer_key = "ACTUALLY_USE_THIS_KEY"
54
+ }
55
+
56
+ ===Using the client
57
+
58
+ List of all available API methods and their return types
59
+
60
+ ----
61
+
62
+ Provided by Sevendigital::ArtistManager :
63
+
64
+ client.artist.*get_details*(artist_id, options={}) => Sevendigital::Artist
65
+
66
+ client.artist.*get_releases*(artist_id, options={}) => [ Sevendigital::Release ]
67
+
68
+ client.artist.*get_similar*(artist_id, options={}) => [ Sevendigital::Artist ]
69
+
70
+ client.artist.*get_top_by_tag*(tags, options={}) => [ Sevendigital::Artist ]
71
+
72
+ client.artist.*get_top_tracks*(artist_id, options={}) => [ Sevendigital::Track ]
73
+
74
+ client.artist.*search*(query, options={}) => [ Sevendigital::Artist ]
75
+
76
+ ----
77
+
78
+ Provided by Sevendigital::ReleaseManager :
79
+
80
+ client.release.*get_details*(release_id, options = {}) => Sevendigital::Release
81
+
82
+ client.release.*get_tracks*(release_id, options = {}) => [ Sevendigital::Track ]
83
+
84
+ client.release.*get_chart*(options={}) => [ Sevendigital::ChartItem ]
85
+
86
+ client.release.*get_by_date*(from_date = nil, to_date = nil, options = {}) => [ Sevendigital::Release ]
87
+
88
+ client.release.*get_recommendations*(release_id, options = {}) => [ Sevendigital::Release ]
89
+
90
+ client.release.*get_top_by_tag*(tags, options = {}) => [ Sevendigital::Release ]
91
+
92
+ client.release.*search*(query, options={}) => [ Sevendigital::Release ]
93
+
94
+ ----
95
+
96
+ client.track.*get_details*(id, options={}) => Sevendigital::Track
97
+
98
+ client.track.*get_details_from_release*(track_id, release_id, options={}) => Sevendigital::Track
99
+
100
+ client.track.*get_chart*(options={}) => [ Sevendigital::ChartItem ]
101
+
102
+ client.track.*build_preview_url*(id, options={}) => String
103
+
104
+ client.track.*search*(query, options={}) => [ Sevendigital::Track ]
105
+
106
+ ---
107
+
108
+ client.basket.*get*(basket_id, options={}) => Sevendigital::Basket
109
+
110
+ client.basket.*create*(options={}) => Sevendigital::Basket
111
+
112
+ client.basket.*add_item*(basket_id, release_id, track_id=nil, options={}) => Sevendigital::Basket
113
+
114
+ client.basket.*remove_item*(basket_id, item_id, options={}) => Sevendigital::Basket
115
+
116
+ ---
117
+
118
+ client.oauth.*get_request_token* => OAuth::RequestToken
119
+
120
+ client.oauth.*get_access_token*(request_token) => OAuth::AccessToken
121
+
122
+ ---
123
+
124
+ client.user.*login*(access_token) => Sevendigital::User
125
+
126
+ client.user.*authenticate*(email, password) => Sevendigital::User
127
+
128
+ client.user.*get_locker*(token, options={}) => Sevendgital::Locker
129
+
130
+ client.user.*purchase*(release_id, track_id, price, token, options={}) => Sevendgital::Locker
131
+
132
+ client.user.*get_stream_track_url*(release_id, track_id, token, options={}) => String
133
+
134
+ client.user.*get_add_card_url*(return_url, token, options={}) => String
135
+
136
+
data/lib/sevendigital.rb CHANGED
@@ -1,53 +1,53 @@
1
-
2
- module Sevendigital
3
-
4
- # :stopdoc:
5
- LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
- PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
- # :startdoc:
8
-
9
- # Returns the version string for the library.
10
- #
11
- def self.version
12
- VERSION
13
- end
14
-
15
- # Returns the library path for the module. If any arguments are given,
16
- # they will be joined to the end of the libray path using
17
- # <tt>File.join</tt>.
18
- #
19
- def self.libpath( *args )
20
- args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
21
- end
22
-
23
- # Returns the lpath for the module. If any arguments are given,
24
- # they will be joined to the end of the path using
25
- # <tt>File.join</tt>.
26
- #
27
- def self.path( *args )
28
- args.empty? ? PATH : ::File.join(PATH, args.flatten)
29
- end
30
-
31
- # Utility method used to require all files ending in .rb that lie in the
32
- # directory below this file that has the same name as the filename passed
33
- # in. Optionally, a specific _directory_ name can be passed in such that
34
- # the _filename_ does not have to be equivalent to the directory.
35
- #
36
- def self.require_all_libs_relative_to( fname, dir = nil )
37
- dir ||= ::File.basename(fname, '.*')
38
- search_me = ::File.expand_path(
39
- ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
40
-
41
- Dir.glob(search_me).sort.each {|rb| require rb }
42
- end
43
-
44
- end # module 7digital
45
-
46
- require 'peachy'
47
- Peachy.be_quiet
48
- require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'client_configuration')
49
- require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'management', 'manager')
50
- require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'digestion_tract', 'digestor')
51
- require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'model', 'sevendigital_object')
52
- Sevendigital.require_all_libs_relative_to(__FILE__)
53
-
1
+
2
+ module Sevendigital
3
+
4
+ # :stopdoc:
5
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
+ # :startdoc:
8
+
9
+ # Returns the version string for the library.
10
+ #
11
+ def self.version
12
+ VERSION
13
+ end
14
+
15
+ # Returns the library path for the module. If any arguments are given,
16
+ # they will be joined to the end of the libray path using
17
+ # <tt>File.join</tt>.
18
+ #
19
+ def self.libpath( *args )
20
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
21
+ end
22
+
23
+ # Returns the lpath for the module. If any arguments are given,
24
+ # they will be joined to the end of the path using
25
+ # <tt>File.join</tt>.
26
+ #
27
+ def self.path( *args )
28
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
29
+ end
30
+
31
+ # Utility method used to require all files ending in .rb that lie in the
32
+ # directory below this file that has the same name as the filename passed
33
+ # in. Optionally, a specific _directory_ name can be passed in such that
34
+ # the _filename_ does not have to be equivalent to the directory.
35
+ #
36
+ def self.require_all_libs_relative_to( fname, dir = nil )
37
+ dir ||= ::File.basename(fname, '.*')
38
+ search_me = ::File.expand_path(
39
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
40
+
41
+ Dir.glob(search_me).sort.each {|rb| require rb }
42
+ end
43
+
44
+ end # module 7digital
45
+
46
+ require 'peachy'
47
+ Peachy.be_quiet
48
+ require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'client_configuration')
49
+ require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'management', 'manager')
50
+ require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'digestion_tract', 'digestor')
51
+ require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'model', 'sevendigital_object')
52
+ Sevendigital.require_all_libs_relative_to(__FILE__)
53
+
@@ -1,125 +1,131 @@
1
- module Sevendigital
2
-
3
- require 'net/http'
4
- require 'net/https'
5
- require 'oauth'
6
- require 'uri'
7
- require 'cgi'
8
-
9
- #internal class used for translating ApiRequests into http calls
10
- #deals with OAuth signing requests that require signature, making sure parameters are in correct format etc
11
- class ApiOperator # :nodoc:
12
-
13
- RESERVED_CHARACTERS = /[^a-zA-Z0-9\-\.\_\~]/
14
-
15
- def initialize(client)
16
- @client = client
17
- end
18
-
19
- def call_api(api_request)
20
- api_response = make_http_request_and_digest(api_request)
21
- puts api_response.content.to_s if @client.very_verbose?
22
- api_response
23
- end
24
-
25
- def get_request_uri(api_request)
26
- api_request.signature_scheme = :query_string if api_request.requires_signature?
27
- http_client, http_request = create_http_request(api_request)
28
- path = http_request.instance_variable_get("@path")
29
- host = http_client.instance_variable_get("@address")
30
- port = http_client.instance_variable_get("@port")
31
- scheme = port == 443 ? "https" : "http"
32
- return "#{scheme}://#{host}#{path}"
33
- end
34
-
35
- def make_http_request_and_digest(api_request)
36
- digest_http_response(make_http_request(api_request))
37
- end
38
-
39
- def make_http_request(api_request)
40
-
41
- http_client, http_request = create_http_request(api_request)
42
-
43
- http_client.set_debug_output($stdout) if @client.very_verbose?
44
- log_request(http_request) if @client.verbose?
45
-
46
- http_client.request(http_request)
47
- end
48
-
49
- def digest_http_response(http_response)
50
- api_response = @client.api_response_digestor.from_http_response(http_response)
51
- raise Sevendigital::SevendigitalError.new(api_response.error_code, api_response.error_message), "#{api_response.error_code} - #{api_response.error_message}" if !api_response.ok?
52
- api_response
53
- end
54
-
55
- def create_http_request(api_request)
56
- http_client, http_request = create_standard_http_request(api_request)
57
- if (api_request.requires_signature?) then
58
- oauth_sign_request(http_client, http_request, api_request)
59
- else
60
- end
61
- return http_client, http_request
62
- end
63
-
64
- def oauth_sign_request(http_client, http_request, api_request)
65
- http_request.oauth!( \
66
- http_client, \
67
- @client.oauth_consumer, \
68
- api_request.token, \
69
- {:scheme => api_request.signature_scheme}
70
- )
71
- return http_request
72
- end
73
-
74
- def create_standard_http_request(api_request)
75
- request_uri = create_request_uri(api_request)
76
- http_client = Net::HTTP.new(request_uri.host, request_uri.port)
77
-
78
- request_uri.query += '&oauth_consumer_key=' + @client.configuration.oauth_consumer_key unless api_request.requires_signature?
79
-
80
- http_request = new_http_request(request_uri.request_uri, api_request.http_method)
81
-
82
- ensure_secure_connection(http_client) if api_request.requires_secure_connection?
83
- add_form_parameters(http_request, api_request)
84
-
85
- return http_client, http_request
86
- end
87
-
88
- def ensure_secure_connection(http_client)
89
- http_client.use_ssl = true
90
- http_client.verify_mode = OpenSSL::SSL::VERIFY_NONE
91
- end
92
-
93
- def create_request_uri(api_request)
94
- host, version = @client.api_host_and_version(api_request.api_service)
95
- path = "/#{version}/#{api_request.api_method}"
96
- query = api_request.parameters.map{ |k,v| "#{escape(k)}=#{escape(v)}" }.join("&")
97
- if api_request.requires_secure_connection? then
98
- URI::HTTPS.build(:host => host, :path => path, :query =>query)
99
- else
100
- URI::HTTP.build(:host => host, :path => path, :query =>query)
101
- end
102
- end
103
-
104
- def escape(value)
105
- URI::escape(value.to_s, RESERVED_CHARACTERS)
106
- rescue ArgumentError
107
- URI::escape(value.to_s.force_encoding(Encoding::UTF_8), RESERVED_CHARACTERS)
108
- end
109
-
110
- def new_http_request(request_uri, http_method)
111
- request_type = Kernel.const_get("Net").const_get("HTTP").const_get(http_method.to_s.capitalize)
112
- request_type.new(request_uri, {"user-agent" => @client.user_agent_info})
113
- end
114
-
115
- def add_form_parameters(http_request, api_request)
116
- http_request.set_form_data(api_request.form_parameters)
117
- end
118
-
119
- def log_request(request)
120
- puts "ApiOperator: Calling #{request.inspect}"
121
- end
122
-
123
- end
124
-
1
+ module Sevendigital
2
+
3
+ require 'net/http'
4
+ require 'net/https'
5
+ require 'oauth'
6
+ require 'uri'
7
+ require 'cgi'
8
+
9
+ #@private
10
+ #internal class used for translating ApiRequests into http calls
11
+ #deals with OAuth signing requests that require signature, making sure parameters are in correct format etc
12
+ class ApiOperator # :nodoc:
13
+
14
+ RESERVED_CHARACTERS = /[^a-zA-Z0-9\-\.\_\~]/
15
+
16
+ def initialize(client)
17
+ @client = client
18
+ end
19
+
20
+ def call_api(api_request)
21
+ api_response = make_http_request_and_digest(api_request)
22
+ puts api_response.content.to_s if @client.very_verbose?
23
+ api_response
24
+ end
25
+
26
+ def get_request_uri(api_request)
27
+ api_request.signature_scheme = :query_string if api_request.requires_signature?
28
+ http_client, http_request = create_http_request(api_request)
29
+ path = http_request.instance_variable_get("@path")
30
+ host = http_client.instance_variable_get("@address")
31
+ port = http_client.instance_variable_get("@port")
32
+ scheme = port == 443 ? "https" : "http"
33
+ return "#{scheme}://#{host}#{path}"
34
+ end
35
+
36
+ def make_http_request_and_digest(api_request)
37
+ digest_http_response(make_http_request(api_request))
38
+ end
39
+
40
+ def make_http_request(api_request)
41
+
42
+ http_client, http_request = create_http_request(api_request)
43
+
44
+ http_client.set_debug_output($stdout) if @client.very_verbose?
45
+ log_request(http_request) if @client.verbose?
46
+
47
+ http_client.request(http_request)
48
+ end
49
+
50
+ def digest_http_response(http_response)
51
+ api_response = @client.api_response_digestor.from_http_response(http_response)
52
+ raise Sevendigital::SevendigitalError.new(api_response.error_code, api_response.error_message), "#{api_response.error_code} - #{api_response.error_message}" if !api_response.ok?
53
+ api_response
54
+ end
55
+
56
+ def create_http_request(api_request)
57
+ http_client, http_request = create_standard_http_request(api_request)
58
+ if (api_request.requires_signature?) then
59
+ oauth_sign_request(http_client, http_request, api_request)
60
+ else
61
+ end
62
+ return http_client, http_request
63
+ end
64
+
65
+ def oauth_sign_request(http_client, http_request, api_request)
66
+ http_request.oauth!( \
67
+ http_client, \
68
+ @client.oauth_consumer, \
69
+ api_request.token, \
70
+ {:scheme => api_request.signature_scheme}
71
+ )
72
+ return http_request
73
+ end
74
+
75
+ def create_standard_http_request(api_request)
76
+ request_uri = create_request_uri(api_request)
77
+ http_client = Net::HTTP.new(request_uri.host, request_uri.port)
78
+
79
+ if !api_request.requires_signature? then
80
+ request_uri.query ||= ""
81
+ request_uri.query += "&oauth_consumer_key=#{@client.configuration.oauth_consumer_key}"
82
+ end
83
+
84
+ http_request = new_http_request(request_uri.request_uri, api_request.http_method)
85
+
86
+ ensure_secure_connection(http_client) if api_request.requires_secure_connection?
87
+ add_form_parameters(http_request, api_request)
88
+
89
+ return http_client, http_request
90
+ end
91
+
92
+ def ensure_secure_connection(http_client)
93
+ http_client.use_ssl = true
94
+ http_client.verify_mode = OpenSSL::SSL::VERIFY_NONE
95
+ end
96
+
97
+ def create_request_uri(api_request)
98
+ host, version = @client.api_host_and_version(api_request.api_service)
99
+ path = "/#{version}/#{api_request.api_method}"
100
+ query = api_request.parameters.map{ |k,v| "#{escape(k)}=#{escape(v)}" }.join("&")
101
+ query = nil if query == ""
102
+ if api_request.requires_secure_connection? then
103
+ URI::HTTPS.build(:host => host, :path => path, :query =>query)
104
+ else
105
+ URI::HTTP.build(:host => host, :path => path, :query =>query)
106
+ end
107
+ end
108
+
109
+ def new_http_request(request_uri, http_method)
110
+ request_type = Kernel.const_get("Net").const_get("HTTP").const_get(http_method.to_s.capitalize)
111
+ request_type.new(request_uri, {"user-agent" => @client.user_agent_info})
112
+ end
113
+
114
+ def add_form_parameters(http_request, api_request)
115
+ http_request.body = api_request.form_parameters.map {|k, v| "#{escape(k)}=#{escape(v)}" }.flatten.join('&')
116
+ http_request.content_type = 'application/x-www-form-urlencoded'
117
+ end
118
+
119
+ def escape(value)
120
+ URI::escape(value.to_s, RESERVED_CHARACTERS)
121
+ rescue ArgumentError
122
+ URI::escape(value.to_s.force_encoding(Encoding::UTF_8), RESERVED_CHARACTERS)
123
+ end
124
+
125
+ def log_request(request)
126
+ puts "ApiOperator calling #{request.inspect}" if @client.verbose?
127
+ end
128
+
129
+ end
130
+
125
131
  end