Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

more "refactoring" - getting rid of last peachy leftovers

  • Loading branch information...
commit 29edccf0ad54026cdd9e1bb17a209b89f14b33f9 1 parent ba9968b
filip authored
Showing with 408 additions and 384 deletions.
  1. +6 −0 Gemfile
  2. +27 −49 lib/sevendigital/digestion_tract/api_response_digestor.rb
  3. +1 −1  lib/sevendigital/digestion_tract/chart_item_digestor.rb
  4. +14 −41 lib/sevendigital/digestion_tract/digestor.rb
  5. +9 −11 lib/sevendigital/management/artist_manager.rb
  6. +4 −4 lib/sevendigital/management/basket_manager.rb
  7. +2 −2 lib/sevendigital/management/oauth_manager.rb
  8. +9 −11 lib/sevendigital/management/release_manager.rb
  9. +1 −1  lib/sevendigital/management/tag_manager.rb
  10. +3 −3 lib/sevendigital/management/track_manager.rb
  11. +2 −2 lib/sevendigital/management/user_card_manager.rb
  12. +4 −4 lib/sevendigital/management/user_manager.rb
  13. +12 −4 lib/sevendigital/model/api_response.rb
  14. +1 −1  lib/sevendigital/model/release.rb
  15. +1 −1  lib/sevendigital/pager.rb
  16. +0 −28 lib/sevendigital/proxy_police.rb
  17. +1 −2  spec/api_operator_cached_spec.rb
  18. +3 −3 spec/api_operator_spec.rb
  19. +26 −22 spec/digestion_tract/api_response_digestor_spec.rb
  20. +3 −3 spec/digestion_tract/artist_digestor_spec.rb
  21. +2 −2 spec/digestion_tract/basket_digestor_spec.rb
  22. +2 −2 spec/digestion_tract/basket_item_digestor_spec.rb
  23. +4 −4 spec/digestion_tract/chart_digestor_spec.rb
  24. +1 −1  spec/digestion_tract/digestor_spec.rb
  25. +2 −2 spec/digestion_tract/download_url_digestor_spec.rb
  26. +2 −2 spec/digestion_tract/format_digestor_spec.rb
  27. +2 −2 spec/digestion_tract/label_digestor_spec.rb
  28. +2 −2 spec/digestion_tract/locker_digestor_spec.rb
  29. +2 −2 spec/digestion_tract/locker_release_digestor_spec.rb
  30. +2 −2 spec/digestion_tract/locker_track_digestor_spec.rb
  31. +2 −2 spec/digestion_tract/oauth_access_token_digestor_spec.rb
  32. +2 −2 spec/digestion_tract/oauth_request_token_digestor_spec.rb
  33. +3 −3 spec/digestion_tract/pager_digestor_spec.rb
  34. +4 −4 spec/digestion_tract/price_digestor_spec.rb
  35. +16 −2 spec/digestion_tract/release_digestor_spec.rb
  36. +3 −3 spec/digestion_tract/tag_digestor_spec.rb
  37. +3 −3 spec/digestion_tract/track_digestor_spec.rb
  38. +3 −3 spec/digestion_tract/user_card_digestor_spec.rb
  39. +3 −3 spec/digestion_tract/user_digestor_spec.rb
  40. +86 −0 spec/integration/artist_spec.rb
  41. +34 −0 spec/integration/release_spec.rb
  42. +1 −1  spec/{ → integration}/sevendigital_spec.yml
  43. +32 −11 spec/management/artist_manager_spec.rb
  44. +4 −4 spec/management/basket_manager_spec.rb
  45. +4 −4 spec/management/oauth_manager_spec.rb
  46. +13 −13 spec/management/release_manager_spec.rb
  47. +1 −1  spec/management/tag_manager_spec.rb
  48. +4 −4 spec/management/track_manager_spec.rb
  49. +2 −2 spec/management/user_card_manager_spec.rb
  50. +4 −4 spec/management/user_manager_spec.rb
  51. +3 −3 spec/model/api_response_spec.rb
  52. +0 −7 spec/peachy_spec_helper_patch.rb
  53. +0 −70 spec/proxy_police_spec.rb
  54. +0 −12 spec/sevendigital_spec.rb
  55. +8 −9 spec/spec_helper.rb
  56. +23 −0 spec/test-xml/objects/nested_release_list.xml
View
6 Gemfile
@@ -0,0 +1,6 @@
+source 'http://rubygems.org'
+
+gem 'rspec'
+gem 'oauth'
+gem 'nokogiri'
+gem 'will_paginate'
View
76 lib/sevendigital/digestion_tract/api_response_digestor.rb
@@ -1,3 +1,5 @@
+require 'nokogiri'
+
module Sevendigital
#@private
@@ -5,67 +7,43 @@ class ApiResponseDigestor < Digestor # :nodoc:
def default_element_name; :response end
- def from_xml_doc(xml_node)
- return from_invalid_xml unless xml_node
-
- status = get_optional_attribute(xml_node, "status")
-
- return from_ok_response(xml_node) if status == 'ok'
-
- return from_error_response(xml_node) if status == 'error'
-
- from_invalid_xml
- end
-
- def from_invalid_xml
- response = ApiResponse.new
-
- response.error_code = 10000
- response.error_message = 'Invalid 7digital API response'
-
- response
- end
-
- def from_error_response(xml_node)
-
- error_node = get_required_node(xml_node, "error")
-
+ def from_http_response(http_response)
response = ApiResponse.new
+ response.headers = http_response.header
+ response.content = http_response.body.to_s
- response.error_code = get_required_attribute(error_node, "code").to_i
- response.error_message = get_required_value(error_node, "errorMessage")
+ parse_xml_doc(response.content, response)
+ if response.error_code >= 10000 && !http_response.is_a?(Net::HTTPSuccess)
+ response.error_code = Integer(http_response.code)
+ response.error_message= http_response.body.to_s
+ end
response
end
- def from_ok_response(response_content)
- response = ApiResponse.new
-
- response.error_code = 0
- response.content = response_content
+ def parse_xml_doc(xml, response)
- response
- end
+ xml_doc = Nokogiri::XML(xml)
- def from_http_response(http_response)
- if http_response.is_a?(Net::HTTPSuccess) then
- response = from_xml_nokogiri(http_response.body.to_s)
+ response_node = xml_doc.at_xpath("./response")
+ response_status = nil
+ response_status = get_optional_attribute(response_node, "status") if response_node
+ puts xml.inspect
+ if response_status == 'ok' then
+ response.error_code = 0
else
- response = from_invalid_http_response(http_response)
+ if response_status == 'error'
+ error_node = get_required_node(response_node, "error")
+ response.error_code = get_required_attribute(error_node, "code").to_i
+ response.error_message = get_required_value(error_node, "errorMessage")
+ else
+ response.error_code = 10001
+ response.error_message = 'Invalid 7digital API response'
+ end
end
- response.headers = http_response.header
- response
- end
-
- def from_invalid_http_response(http_response)
- response = ApiResponse.new
- response.error_code = Integer(http_response.code)
- response.error_message= http_response.body.to_s
-
- response
end
-
+
end
end
View
2  lib/sevendigital/digestion_tract/chart_item_digestor.rb
@@ -8,7 +8,7 @@ def default_list_element_name; :chart end
def from_proxy(chart_item_proxy)
- from_xml_nokogiri(chart_item_proxy.to_s)
+ from_xml_string(chart_item_proxy.to_s)
end
View
55 lib/sevendigital/digestion_tract/digestor.rb
@@ -10,28 +10,11 @@ def initialize(api_client)
@api_client = api_client
end
- def from_xml(xml_or_proxy, element_name = default_element_name)
- from_proxy(ProxyPolice.ensure_is_proxy(xml_or_proxy, element_name))
- end
-
- def from_xml_nokogiri(xml, element_name = default_element_name)
+ def from_xml_string(xml, element_name = default_element_name)
xml_doc = Nokogiri::XML(xml)
- puts xml_doc.inspect
- puts "XML #{element_name}"
- puts xml_doc.at_xpath("./#{element_name}").inspect
from_xml_doc(xml_doc.at_xpath("./#{element_name}"))
end
- def list_from_proxy(object_list_proxy)
- make_sure_not_eating_nil(object_list_proxy)
- list = []
- return list if object_list_proxy.kind_of?(Peachy::SimpleContent)
- if object_list_proxy.send(default_element_name) then
- object_list_proxy.send(default_element_name).each { |object_proxy| list << from_proxy(object_proxy) }
- end
- paginate_results(object_list_proxy, list)
- end
-
def list_from_xml_string(xml, list_element_name = default_list_element_name)
xml_doc = Nokogiri::XML(xml)
list_from_xml_doc(xml_doc.at_xpath("./#{list_element_name}"))
@@ -41,43 +24,33 @@ def list_from_xml_doc(list_node)
make_sure_eating_nokogiri_node(list_node)
list = []
list_node.xpath("./#{default_element_name}").each { |node| list << from_xml_doc(node)}
- paginate_results_nokogiri(list_node, list)
+ paginate_results(list_node, list)
end
#nested parsing for api methods that return standard object inside containers with no additional (useful) information
#e.g. tagged_item.artist, recommendation.release, search_result.track, etc
- def nested_list_from_xml(xml_or_proxy, container_element_name, list_element_name = default_list_element_name)
- nested_list_from_proxy(ProxyPolice.ensure_is_proxy(xml_or_proxy, list_element_name), container_element_name)
+ def nested_list_from_xml_string(xml, container_element_name, list_element_name = default_list_element_name)
+ xml_doc = Nokogiri::XML(xml)
+ nested_list_from_xml_doc(xml_doc.at_xpath("./#{container_element_name}"), list_element_name)
end
- def nested_list_from_proxy(object_list_proxy, container_element_name)
- make_sure_not_eating_nil(object_list_proxy)
+ def nested_list_from_xml_doc(list_node, list_element_name = default_list_element_name, element_name = default_element_name)
+ puts list_element_name
+ puts element_name
+ puts list_node.inspect
+ make_sure_eating_nokogiri_node(list_node)
list = []
- if object_list_proxy.send(container_element_name) then
- object_list_proxy.send(container_element_name).each do
- |object_proxy| list << from_proxy(object_proxy.send(default_element_name))
- end
- end
- return paginate_results(object_list_proxy, list)
+ list_node.xpath("./#{list_element_name}/#{element_name}").each { |node| list << from_xml_doc(node)}
+ paginate_results(list_node, list)
end
- def paginate_results(xml_results, list)
- pager = @api_client.pager_digestor.from_xml(xml_results)
+ def paginate_results(results_xml_node, list)
+ pager = @api_client.pager_digestor.from_xml_doc(results_xml_node)
return list if !pager
pager.paginate_list(list)
end
- def paginate_results_nokogiri(xml_results, list)
- pager = @api_client.pager_digestor.from_xml_doc(xml_results)
- return list if !pager
- pager.paginate_list(list)
- end
-
- def make_sure_not_eating_nil(xml)
- raise DigestiveProblem, "There's nothing i can digest" unless xml
- end
-
def make_sure_eating_nokogiri_node(xml)
raise DigestiveProblem, "There's nothing i can digest" unless xml
raise DigestiveProblem, "I'm not eating this! It's not a Nokogiri XML node.'" unless xml.kind_of?(Nokogiri::XML::Node)
View
20 lib/sevendigital/management/artist_manager.rb
@@ -1,5 +1,3 @@
-require "peachy"
-
module Sevendigital
# provides access to Artist related API methods (artist/*)
@@ -12,7 +10,7 @@ class ArtistManager < Manager
# @return [Artist]
def get_details(artist_id, options={})
api_response = @api_client.make_api_request(:GET, "artist/details", {:artistId => artist_id}, options)
- @api_client.artist_digestor.from_xml(api_response.content.artist)
+ @api_client.artist_digestor.from_xml_doc(api_response.item_xml("artist"))
end
# calls *artist/releases* API method and returns Release array
@@ -22,7 +20,7 @@ def get_details(artist_id, options={})
# @return [[Artist]]
def get_releases(artist_id, options={})
api_response = @api_client.make_api_request(:GET, "artist/releases", {:artistId => artist_id}, options)
- @api_client.release_digestor.list_from_xml(api_response.content.releases)
+ @api_client.release_digestor.list_from_xml_doc(api_response.item_xml("releases"))
end
# calls *artist/toptracks* API method and returns Track array
@@ -32,7 +30,7 @@ def get_releases(artist_id, options={})
# @return [Array<Track>]
def get_top_tracks(artist_id, options={})
api_response = @api_client.make_api_request(:GET, "artist/topTracks", {:artistId => artist_id}, options)
- @api_client.track_digestor.list_from_xml(api_response.content.tracks)
+ @api_client.track_digestor.list_from_xml_doc(api_response.item_xml("tracks"))
end
# calls *artist/similar* API method and returns Artist array
@@ -42,7 +40,7 @@ def get_top_tracks(artist_id, options={})
# @return [Array<Artist>]
def get_similar(artist_id, options={})
api_response = @api_client.make_api_request(:GET, "artist/similar", {:artistId => artist_id}, options)
- @api_client.artist_digestor.list_from_xml(api_response.content.artists)
+ @api_client.artist_digestor.list_from_xml_doc(api_response.item_xml("artists"))
end
# calls *artist/byTag/top* API method and returns Artist array
@@ -52,7 +50,7 @@ def get_similar(artist_id, options={})
# @return [Array<Artist>]
def get_top_by_tag(tags, options={})
api_response = @api_client.make_api_request(:GET, "artist/byTag/top", {:tags => tags}, options)
- @api_client.artist_digestor.nested_list_from_xml(api_response.content.tagged_results, :tagged_item, :tagged_results)
+ @api_client.artist_digestor.nested_list_from_xml_doc(api_response.item_xml("taggedResults"), :taggedItem, :artist)
end
# calls *artist/search* API method and returns Artist array
@@ -62,7 +60,7 @@ def get_top_by_tag(tags, options={})
# @return [Array<Artist>]
def search(query, options={})
api_response = @api_client.make_api_request(:GET, "artist/search", {:q => query}, options)
- @api_client.artist_digestor.nested_list_from_xml(api_response.content.search_results, :search_result, :search_results)
+ @api_client.artist_digestor.nested_list_from_xml_doc(api_response.item_xml("searchResults"), :searchResult, :artist)
end
# calls *artist/browse* API method and returns Artist array
@@ -72,7 +70,7 @@ def search(query, options={})
# @return [Array<Artist>]
def browse(letter, options={})
api_response = @api_client.make_api_request(:GET, "artist/browse", {:letter => letter}, options)
- @api_client.artist_digestor.list_from_xml(api_response.content.artists)
+ @api_client.artist_digestor.list_from_xml_doc(api_response.item_xml("artists"))
end
# calls *artist/chart* API method and returns Artist array
@@ -80,7 +78,7 @@ def browse(letter, options={})
# @param [Hash] options optional hash of additional API parameters, e.g. page_size => 50, etc
def get_chart(options={})
api_response = @api_client.make_api_request(:GET, "artist/chart", {}, options)
- @api_client.chart_item_digestor.list_from_xml(api_response.content.chart)
+ @api_client.chart_item_digestor.list_from_xml_doc(api_response.item_xml("chart"))
end
# calls *artist/tags* API method and returns Tag array
@@ -90,7 +88,7 @@ def get_chart(options={})
# @return [Array<Tag>]
def get_tags(artist_id, options={})
api_response = @api_client.make_api_request(:GET, "artist/tags", {:artistId => artist_id}, options)
- @api_client.tag_digestor.list_from_xml(api_response.content.tags)
+ @api_client.tag_digestor.list_from_xml_doc(api_response.item_xml("tags"))
end
View
8 lib/sevendigital/management/basket_manager.rb
@@ -4,23 +4,23 @@ class BasketManager < Manager
def get(basket_id, options={})
api_response = @api_client.make_api_request(:GET, "basket", {:basketId => basket_id}, options)
- @api_client.basket_digestor.from_xml(api_response.content.basket)
+ @api_client.basket_digestor.from_xml_doc(api_response.item_xml("basket"))
end
def create(options={})
api_response = @api_client.make_api_request(:GET, "basket/create", {}, options)
- @api_client.basket_digestor.from_xml(api_response.content.basket)
+ @api_client.basket_digestor.from_xml_doc(api_response.item_xml("basket"))
end
def add_item(basket_id, release_id, track_id=nil, options={})
api_response = @api_client.make_api_request(:GET, "basket/addItem", {:basketId => basket_id, :releaseId => release_id, :trackId => track_id}, options)
- @api_client.basket_digestor.from_xml(api_response.content.basket)
+ @api_client.basket_digestor.from_xml_doc(api_response.item_xml("basket"))
end
def remove_item(basket_id, item_id, options={})
api_response = @api_client.make_api_request(:GET, "basket/removeItem", {:basketId => basket_id, :itemId => item_id}, options)
- @api_client.basket_digestor.from_xml(api_response.content.basket)
+ @api_client.basket_digestor.from_xml_doc(api_response.item_xml("basket"))
end
View
4 lib/sevendigital/management/oauth_manager.rb
@@ -4,12 +4,12 @@ class OAuthManager < Manager
def get_request_token
api_response = @api_client.make_signed_api_request(:GET, "oauth/requestToken", {})
- @api_client.oauth_request_token_digestor.from_xml(api_response.content.oauth_request_token, :oauth_request_token)
+ @api_client.oauth_request_token_digestor.from_xml_doc(api_response.item_xml("oauth_request_token"), :oauth_request_token)
end
def get_access_token(request_token)
api_response = @api_client.make_signed_api_request(:GET, "oauth/accessToken", {}, {}, request_token)
- @api_client.oauth_access_token_digestor.from_xml(api_response.content.oauth_access_token, :oauth_access_token)
+ @api_client.oauth_access_token_digestor.from_xml_doc(api_response.item_xml("oauth_access_token"), :oauth_access_token)
end
def authorise_request_token(username, password, request_token)
View
20 lib/sevendigital/management/release_manager.rb
@@ -1,23 +1,21 @@
-require "peachy"
-
module Sevendigital
class ReleaseManager < Manager
def get_details(release_id, options = {})
api_response = @api_client.make_api_request(:GET, "release/details", {:releaseId => release_id}, options)
- @api_client.release_digestor.from_xml(api_response.content.release)
+ @api_client.release_digestor.from_xml_doc(api_response.item_xml("release"))
end
def get_tracks(release_id, options = {})
options[:page_size] ||= 100
api_response = @api_client.make_api_request(:GET, "release/tracks", {:releaseId => release_id}, options)
- @api_client.track_digestor.list_from_xml(api_response.content.tracks)
+ @api_client.track_digestor.list_from_xml_doc(api_response.item_xml("tracks"))
end
def get_chart(options={})
api_response = @api_client.make_api_request(:GET, "release/chart", {}, options)
- @api_client.chart_item_digestor.list_from_xml(api_response.content.chart)
+ @api_client.chart_item_digestor.list_from_xml_doc(api_response.item_xml("chart"))
end
def get_by_date(from_date = nil, to_date = nil, options = {})
@@ -26,30 +24,30 @@ def get_by_date(from_date = nil, to_date = nil, options = {})
parameters[:toDate] = to_date.strftime("%Y%m%d") if to_date
api_response = @api_client.make_api_request(:GET, "release/byDate", parameters, options)
- @api_client.release_digestor.list_from_xml(api_response.content.releases)
+ @api_client.release_digestor.list_from_xml_doc(api_response.item_xml("releases"))
end
def get_recommendations(release_id, options = {})
api_response = @api_client.make_api_request(:GET, "release/recommend", {:releaseId => release_id}, options)
- @api_client.release_digestor.nested_list_from_xml(api_response.content.recommendations, :recommended_item, :recommendations)
+ @api_client.release_digestor.nested_list_from_xml_doc(api_response.item_xml("recommendations"), :recommendedItem, :release)
end
def get_top_by_tag(tags, options = {})
api_response = @api_client.make_api_request(:GET, "release/byTag/top", {:tags => tags}, options)
- @api_client.release_digestor.nested_list_from_xml( \
- api_response.content.tagged_results, :tagged_item, :tagged_results )
+ @api_client.release_digestor.nested_list_from_xml_doc( \
+ api_response.item_xml("taggedResults"), :taggedItem, :release )
end
def search(query, options={})
api_response = @api_client.make_api_request(:GET, "release/search", {:q => query}, options)
- @api_client.release_digestor.nested_list_from_xml(api_response.content.search_results, :search_result, :search_results)
+ @api_client.release_digestor.nested_list_from_xml_doc(api_response.item_xml("searchResults"), :searchResult, :release)
end
def get_tags(release_id, options = {})
api_response = @api_client.make_api_request(:GET, "release/tags", {:releaseId => release_id}, options)
- @api_client.tag_digestor.list_from_xml(api_response.content.tags)
+ @api_client.tag_digestor.list_from_xml_doc(api_response.item_xml("tags"))
end
end
View
2  lib/sevendigital/management/tag_manager.rb
@@ -4,7 +4,7 @@ class TagManager < Manager
def get_tag_list(options={})
api_response = @api_client.make_api_request(:GET, "tag", {}, options)
- @api_client.tag_digestor.list_from_xml(api_response.content.tags)
+ @api_client.tag_digestor.list_from_xml_doc(api_response.item_xml("tags"))
end
end
View
6 lib/sevendigital/management/track_manager.rb
@@ -4,7 +4,7 @@ class TrackManager < Manager
def get_details(id, options={})
api_response = @api_client.make_api_request(:GET, "track/details", {:trackId => id}, options)
- @api_client.track_digestor.from_xml(api_response.content.track)
+ @api_client.track_digestor.from_xml_doc(api_response.item_xml("track"))
end
def get_details_from_release(track_id, release_id, options={})
@@ -13,7 +13,7 @@ def get_details_from_release(track_id, release_id, options={})
def get_chart(options={})
api_response = @api_client.make_api_request(:GET, "track/chart", {}, options)
- @api_client.chart_item_digestor.list_from_xml(api_response.content.chart)
+ @api_client.chart_item_digestor.list_from_xml_doc(api_response.item_xml("chart"))
end
def build_preview_url(id, options={})
@@ -23,7 +23,7 @@ def build_preview_url(id, options={})
def search(query, options={})
api_response = @api_client.make_api_request(:GET, "track/search", {:q => query}, options)
- @api_client.track_digestor.nested_list_from_xml(api_response.content.search_results, :search_result, :search_results)
+ @api_client.track_digestor.nested_list_from_xml_doc(api_response.item_xml("searchResults"), :searchResult, :track)
end
end
end
View
4 lib/sevendigital/management/user_card_manager.rb
@@ -4,7 +4,7 @@ class UserCardManager < Manager
def get_card_list(token, options={})
api_response = @api_client.make_signed_api_request(:GET, "user/payment/card", {}, options, token)
- @api_client.user_card_digestor.list_from_xml(api_response.content.cards)
+ @api_client.user_card_digestor.list_from_xml_doc(api_response.item_xml("cards"))
end
def add_card(card_number, card_type, card_holder_name, card_start_date, card_expiry_date, card_issue_number,
@@ -14,7 +14,7 @@ def add_card(card_number, card_type, card_holder_name, card_start_date, card_exp
:cardStartDate => card_start_date, :cardExpiryDate => card_expiry_date, :cardIssueNumber => card_issue_number,
:cardVerificationCode => card_verification_code, :cardPostCode => card_post_code, :cardCountry => card_country
}, options, token)
- @api_client.user_card_digestor.from_xml(api_response.content.card)
+ @api_client.user_card_digestor.from_xml_doc(api_response.item_xml("card"))
end
def select_card(card_id, token, options={})
View
8 lib/sevendigital/management/user_manager.rb
@@ -20,14 +20,14 @@ def authenticate(email, password)
def sign_up(email, password, options={})
api_response = @api_client.make_signed_api_request(:POST, "user/signUp", \
{:emailAddress => email, :password=> password}, options)
- user = @api_client.user_digestor.from_xml(api_response.content.user)
+ user = @api_client.user_digestor.from_xml_doc(api_response.item_xml("user"))
user.oauth_access_token = authenticate(email, password).oauth_access_token
user
end
def get_locker(token, options={})
api_response = @api_client.make_signed_api_request(:GET, "user/locker", {}, options, token)
- @locker = @api_client.locker_digestor.from_xml(api_response.content.locker)
+ @locker = @api_client.locker_digestor.from_xml_doc(api_response.item_xml("locker"))
end
# <b>DEPRECATED:</b> Please use <tt>purchase_item</tt> instead.
@@ -39,13 +39,13 @@ def purchase(release_id, track_id, price, token, options={})
def purchase_item(release_id, track_id, price, token, options={})
api_response = @api_client.make_signed_api_request(:GET, "user/purchase/item", \
{:releaseId => release_id, :trackId => track_id, :price => price}, options, token)
- @api_client.locker_digestor.from_xml(api_response.content.purchase)
+ @api_client.locker_digestor.from_xml_doc(api_response.item_xml("purchase"))
end
def purchase_basket(basket_id, token, options={})
api_response = @api_client.make_signed_api_request(:GET, "user/purchase/basket", \
{:basketId => basket_id}, options, token)
- @api_client.locker_digestor.from_xml(api_response.content.purchase)
+ @api_client.locker_digestor.from_xml_doc(api_response.item_xml("purchase"))
end
def get_stream_track_url(release_id, track_id, token, options={})
View
16 lib/sevendigital/model/api_response.rb
@@ -7,17 +7,25 @@ class ApiResponse
#True if no API error has been returned
def ok?
- return (@error_code == 0 && !@content.nil?)
+ (@error_code == 0 && !@content.nil?)
+ end
+
+ def content_xml
+ puts @content
+ @content_xml ||= Nokogiri::XML(@content)
+ end
+
+ def item_xml(element_name)
+ content_xml.at_xpath("./response/#{element_name}")
end
def _dump(depth)
- Marshal.dump([@error_code, @error_message, @headers, @content.to_s])
+ Marshal.dump([@error_code, @error_message, @headers, @content])
end
def self._load(properties)
response = ApiResponse.new
- response.error_code, response.error_message, response.headers, content_xml = Marshal.load(properties)
- response.content = Peachy::Proxy.new(content_xml).response
+ response.error_code, response.error_message, response.headers, response.content = Marshal.load(properties)
response
end
View
2  lib/sevendigital/model/release.rb
@@ -37,7 +37,7 @@ def demand_price(options={})
def price(options={})
begin
demand_price(options) if @api_client.configuration.lazy_load
- rescue
+ rescue Sevendigital::SevendigitalError => error
puts "Error whilst lazyloading price - #{error.error_code} #{error.error_message}" if @api_client.verbose?
raise error if !@api_client.configuration.ignorant_lazy_load
end
View
2  lib/sevendigital/pager.rb
@@ -16,7 +16,7 @@ def paginate_list(list)
paged_list = WillPaginate::Collection.create(@page, @page_size, @total_items) do |pager|
pager.replace(list)
end
- return paged_list
+ paged_list
end
end
View
28 lib/sevendigital/proxy_police.rb
@@ -1,28 +0,0 @@
-module Sevendigital
-
- #@private
- #internal class used to ensure the XML being processed is a Peachy::Proxy object
- #if not it checks the expected element name matches the supplied XML string and converts it to Peachy::Proxy
- class ProxyPolice # :nodoc:
-
- def ProxyPolice.ensure_is_proxy(xml_or_proxy, element_name)
- if xml_or_proxy.kind_of?(Peachy::Proxy) || xml_or_proxy.kind_of?(Peachy::SimpleContent) then
- return xml_or_proxy
- else
- return ProxyPolice.create_release_proxy(xml_or_proxy, element_name)
- end
- end
-
- def ProxyPolice.create_release_proxy(xml, element_name)
- #TODO don't use eval
- parent_proxy = Peachy::Proxy.new(xml)
- if element_name
-# parent_proxy.send(element_name)
- eval "parent_proxy.#{element_name.to_s}"
- else
- parent_proxy
- end
- end
-
- end
-end
View
3  spec/api_operator_cached_spec.rb
@@ -152,8 +152,7 @@ def fake_http_response
end
def stub_http_response
- http_response = stub(Net::HTTP)
- http_response
+ stub(Net::HTTP)
end
def stub_time(time)
View
6 spec/api_operator_spec.rb
@@ -304,9 +304,9 @@ def fake_api_response(code = 200, body = "response_body")
end
def fake_digested_response(is_ok = true)
- proxy = stub(Peachy::Proxy)#.new('<response status="ok"><content>test</content></response>')
- proxy.stub!(:ok?).and_return(is_ok)
- proxy
+ r = stub(Sevendigital::ApiResponse)
+ r.stub(:ok?).and_return(is_ok)
+ r
end
def stub_api_client(configuration, response_digestor)
View
48 spec/digestion_tract/api_response_digestor_spec.rb
@@ -7,14 +7,13 @@
end
it "should create a response with body from http ok response" do
+ body = '<response status="ok"></response>'
- stub_http_response = stub(Net::HTTPSuccess)
- stub_http_response.stub!(:is_a?).with(Net::HTTPSuccess).and_return(true)
- stub_http_response.stub!(:body).and_return('<response status="ok"></response>')
- stub_http_response.stub!(:header).and_return(nil)
+ stub_http_response = stub_ok_http_response(body)
response = @api_response_digestor.from_http_response(stub_http_response)
response.error_code.should == 0
+ response.content.should == body
end
it "should create an error response from http non-ok response" do
@@ -36,9 +35,7 @@
it "should store headers from http response" do
- stub_http_response = stub(Net::HTTPSuccess)
- stub_http_response.stub!(:is_a?).with(Net::HTTPSuccess).and_return(true)
- stub_http_response.stub!(:body).and_return('<response status="ok"></response>')
+ stub_http_response = stub_ok_http_response('<response status="ok"></response>')
stub_http_response.stub!(:header).and_return({"cache-control" => "test", "date" => "now"})
response = @api_response_digestor.from_http_response(stub_http_response)
@@ -48,42 +45,49 @@
it "should create a response with body from xml ok response" do
-
- xml_response = "<response status=\"ok\">body</response>"
- response = @api_response_digestor.from_xml_nokogiri(xml_response)
+ xml_response = stub_ok_http_response("<response status=\"ok\">body</response>")
+ response = @api_response_digestor.from_http_response(xml_response)
response.error_code.should == 0
- response.content.to_s.should == xml_response
end
it "should create a response with error details from xml error response" do
- xml_response = '<response status="error"><error code="1000"><errorMessage>expected error message</errorMessage></error></response>'
- response = @api_response_digestor.from_xml_nokogiri(xml_response)
+ xml_response = stub_ok_http_response(
+ '<response status="error"><error code="1000"><errorMessage>expected error message</errorMessage></error></response>')
+ response = @api_response_digestor.from_http_response(xml_response)
response.error_code.should == 1000
response.error_message.should == 'expected error message'
end
it "should create a response with error details from invalid xml response" do
- xml_response = '<wrongresponse status="ok"><test /></wrongresponse>'
- response = @api_response_digestor.from_xml_nokogiri(xml_response)
- response.error_code.should == 10000
+ xml_response = stub_ok_http_response('<wrongresponse status="ok"><test /></wrongresponse>')
+ response = @api_response_digestor.from_http_response(xml_response)
+ response.error_code.should == 10001
response.error_message.should == 'Invalid 7digital API response'
- xml_response = '<response><test /></response>'
- response = @api_response_digestor.from_xml_nokogiri(xml_response)
- response.error_code.should == 10000
+ xml_response = stub_ok_http_response('<response><test /></response>')
+ response = @api_response_digestor.from_http_response(xml_response)
+ response.error_code.should == 10001
response.error_message.should == 'Invalid 7digital API response'
end
it "should create a response with error details from valid xml response with invalid status" do
- xml_response = '<response status="unkown"><test></test></response>'
- response = @api_response_digestor.from_xml_nokogiri(xml_response)
- response.error_code.should == 10000
+ xml_response = stub_ok_http_response('<response status="unkown"><test></test></response>')
+ response = @api_response_digestor.from_http_response(xml_response)
+ response.error_code.should == 10001
response.error_message.should == 'Invalid 7digital API response'
+ end
+
+ def stub_ok_http_response(body)
+ stub_http_response = stub(Net::HTTPSuccess)
+ stub_http_response.stub!(:is_a?).with(Net::HTTPSuccess).and_return(true)
+ stub_http_response.stub!(:body).and_return(body)
+ stub_http_response.stub!(:header).and_return(nil)
+ stub_http_response
end
end
View
6 spec/digestion_tract/artist_digestor_spec.rb
@@ -14,7 +14,7 @@
</release>
XML
- running {@artist_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@artist_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
@@ -26,7 +26,7 @@
</artist>
XML
- artist = @artist_digestor.from_xml_nokogiri(xml_response)
+ artist = @artist_digestor.from_xml_string(xml_response)
artist.id.should == 123
artist.name.should == "expected artist name"
end
@@ -34,7 +34,7 @@
it "should digest artist xml and populate all available properties" do
xml_response = load_sample_object_xml("artist")
- artist = @artist_digestor.from_xml_nokogiri(xml_response)
+ artist = @artist_digestor.from_xml_string(xml_response)
artist.id.should == 123
artist.name.should == "The Expected Artist"
artist.sort_name.should == "Expected Artist, The"
View
4 spec/digestion_tract/basket_digestor_spec.rb
@@ -16,14 +16,14 @@
</zzz>
XML
- running {@basket_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@basket_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should parse from Basket xml and populate all properties" do
xml_response = load_sample_object_xml("basket")
- basket = @basket_digestor.from_xml_nokogiri(xml_response)
+ basket = @basket_digestor.from_xml_string(xml_response)
basket.id.should == "00000000-0000-0000-0000-000000000000"
basket.basket_items.size == 1
basket.basket_items[0].id == 15284882
View
4 spec/digestion_tract/basket_item_digestor_spec.rb
@@ -16,14 +16,14 @@
</artist>
XML
- running {@basket_item_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@basket_item_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should digest basket item xml and populate all properties" do
xml_response = load_sample_object_xml("basket_item")
- basket_item = @basket_item_digestor.from_xml_nokogiri(xml_response)
+ basket_item = @basket_item_digestor.from_xml_string(xml_response)
basket_item.id.should == 15284882
basket_item.type.should == :track
basket_item.item_name.should == "Test"
View
8 spec/digestion_tract/chart_digestor_spec.rb
@@ -14,13 +14,13 @@
</release>
XML
- running {@chart_item_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@chart_item_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should digest artist chart item" do
xml_response = load_sample_object_xml("artist_chart_item")
- chart_item = @chart_item_digestor.from_xml_nokogiri(xml_response)
+ chart_item = @chart_item_digestor.from_xml_string(xml_response)
chart_item.position.should == 2
chart_item.change.should == :up
chart_item.item.id.should == 33154
@@ -31,7 +31,7 @@
it "should digest release chart item" do
xml_response = load_sample_object_xml("release_chart_item")
- chart_item = @chart_item_digestor.from_xml_nokogiri(xml_response)
+ chart_item = @chart_item_digestor.from_xml_string(xml_response)
chart_item.position.should == 1
chart_item.change.should == :up
chart_item.item.id.should == 932151
@@ -42,7 +42,7 @@
xml_response = load_sample_object_xml("track_chart_item")
- chart_item = @chart_item_digestor.from_xml_nokogiri(xml_response)
+ chart_item = @chart_item_digestor.from_xml_string(xml_response)
chart_item.position.should == 99
chart_item.change.should == :down
chart_item.item.id.should == 2825304
View
2  spec/digestion_tract/digestor_spec.rb
@@ -28,7 +28,7 @@
result = @digestor.get_optional_value(Nokogiri::XML(xml), "release") {|v| v.to_i}
result.should == 123
- end
+ end
end
View
4 spec/digestion_tract/download_url_digestor_spec.rb
@@ -16,7 +16,7 @@
</zzz>
XML
- running {@download_url_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@download_url_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should parse from xml and populate all properties" do
@@ -32,7 +32,7 @@
</downloadUrl>
XML
- download_url = @download_url_digestor.from_xml_nokogiri(xml_response)
+ download_url = @download_url_digestor.from_xml_string(xml_response)
download_url.url.should == "http://media3.7digital.com/media/user/downloadtrack?"
download_url.format.id.should == 17
download_url.format.file_format.should == :MP3
View
4 spec/digestion_tract/format_digestor_spec.rb
@@ -16,7 +16,7 @@
</zzz>
XML
- running {@format_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@format_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should parse from xml and populate all properties" do
@@ -29,7 +29,7 @@
</format>
XML
- format = @format_digestor.from_xml_nokogiri(xml_response)
+ format = @format_digestor.from_xml_string(xml_response)
format.id.should == 17
format.file_format.should == :MP3
format.bit_rate.should == 320
View
4 spec/digestion_tract/label_digestor_spec.rb
@@ -15,7 +15,7 @@
</release>
XML
- running {@label_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@label_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should digest label xml and populate all properties" do
@@ -26,7 +26,7 @@
</label>
XML
- label = @label_digestor.from_xml_nokogiri(xml_response)
+ label = @label_digestor.from_xml_string(xml_response)
label.id.should == 123
label.name.should == "expected label name"
end
View
4 spec/digestion_tract/locker_digestor_spec.rb
@@ -16,14 +16,14 @@
</zzz>
XML
- running {@locker_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@locker_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should parse from xml and populate all properties" do
xml_response = load_sample_object_xml("locker")
- locker = @locker_digestor.from_xml_nokogiri(xml_response)
+ locker = @locker_digestor.from_xml_string(xml_response)
locker.locker_releases.size.should == 1
locker.locker_releases[0].release.id.should == 302123
end
View
4 spec/digestion_tract/locker_release_digestor_spec.rb
@@ -16,14 +16,14 @@
</artist>
XML
- running {@locker_release_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@locker_release_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should digest locker release xml and populate all available properties" do
xml_response = load_sample_object_xml("locker_release")
- locker_release = @locker_release_digestor.from_xml_nokogiri(xml_response)
+ locker_release = @locker_release_digestor.from_xml_string(xml_response)
locker_release.release.id.should == 302123
locker_release.release.title.should == "Original Album Classics"
View
4 spec/digestion_tract/locker_track_digestor_spec.rb
@@ -16,14 +16,14 @@
</artist>
XML
- running {@locker_track_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@locker_track_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should digest locker track xml and populate all available properties" do
xml_response = load_sample_object_xml("locker_track")
- locker_track = @locker_track_digestor.from_xml_nokogiri(xml_response)
+ locker_track = @locker_track_digestor.from_xml_string(xml_response)
locker_track.track.id.should == 3544116
locker_track.track.title.should == "Gloria"
View
4 spec/digestion_tract/oauth_access_token_digestor_spec.rb
@@ -18,14 +18,14 @@
</release>
XML
- running {@token_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@token_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should digest access token xml and populate all properties" do
xml_response = load_sample_object_xml("oauth_access_token")
- token = @token_digestor.from_xml_nokogiri(xml_response, :oauth_access_token)
+ token = @token_digestor.from_xml_string(xml_response, :oauth_access_token)
token.kind_of?(OAuth::AccessToken).should == true
token.token.should == "E3w4FV3oirRfj4KfT7alOpa893mmn4HJ"
token.secret.should == "923kj3Kspa304n4Oamd3201pLkgjeM32"
View
4 spec/digestion_tract/oauth_request_token_digestor_spec.rb
@@ -18,14 +18,14 @@
</release>
XML
- running {@token_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@token_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should digest request token xml and populate all properties" do
xml_response = load_sample_object_xml("oauth_request_token")
- token = @token_digestor.from_xml_nokogiri(xml_response, :oauth_request_token)
+ token = @token_digestor.from_xml_string(xml_response, :oauth_request_token)
token.kind_of?(OAuth::RequestToken).should == true
token.token.should == "yu87230J29DT7tyuGslO98wrR43e39Of"
token.secret.should == "d2I8uj7yaoa39KKdu3upasybu98f89fln"
View
6 spec/digestion_tract/pager_digestor_spec.rb
@@ -15,7 +15,7 @@
</release>
XML
- running {@pager_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@pager_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should not digest if paging info is missing from xml but spit out nil" do
@@ -28,7 +28,7 @@
</results>
XML
- pager = @pager_digestor.from_xml_nokogiri(xml_response, :results)
+ pager = @pager_digestor.from_xml_string(xml_response, :results)
pager.should == nil
end
@@ -42,7 +42,7 @@
</pager>
XML
- pager = @pager_digestor.from_xml_nokogiri(xml_response, :pager)
+ pager = @pager_digestor.from_xml_string(xml_response, :pager)
pager.page.should == 3
pager.page_size.should == 22
pager.total_items.should == 99
View
8 spec/digestion_tract/price_digestor_spec.rb
@@ -15,7 +15,7 @@
</xxx>
XML
- running {@price_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@price_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should parse from xml and populate minimum available properties" do
@@ -29,7 +29,7 @@
</price>
XML
- price = @price_digestor.from_xml_nokogiri(xml_response)
+ price = @price_digestor.from_xml_string(xml_response)
price.currency_code.should == :GBP
price.currency_symbol.should == "£"
price.value.should == 1.79
@@ -48,7 +48,7 @@
</price>
XML
- price = @price_digestor.from_xml_nokogiri(xml_response)
+ price = @price_digestor.from_xml_string(xml_response)
price.currency_code.should == :GBP
price.currency_symbol.should == "£"
price.value.should == nil
@@ -60,7 +60,7 @@
xml_response = load_sample_object_xml("price")
- price = @price_digestor.from_xml_nokogiri(xml_response)
+ price = @price_digestor.from_xml_string(xml_response)
price.currency_code.should == :GBP
price.currency_symbol.should == "£"
price.value.should == 1.79
View
18 spec/digestion_tract/release_digestor_spec.rb
@@ -31,7 +31,7 @@
</release>
XML
- release = @release_digestor.from_xml_nokogiri(xml_response)
+ release = @release_digestor.from_xml_string(xml_response)
release.id.should == 123
release.title.should == "expected release title"
release.artist.id.should == 345
@@ -43,7 +43,7 @@
xml_response = load_sample_object_xml("release")
- release = @release_digestor.from_xml_nokogiri(xml_response)
+ release = @release_digestor.from_xml_string(xml_response)
release.id.should == 155408
release.title.should == "Dreams"
@@ -98,4 +98,18 @@
end
+ it "should digest xml containing nested list of releases and return a paginated array" do
+
+ xml_response = load_sample_object_xml("nested_release_list")
+
+ releases = @release_digestor.nested_list_from_xml_string(xml_response, :results, :result)
+ releases[0].id.should == 123
+ releases[0].artist.id.should == 345
+ releases[1].id.should == 456
+ releases[1].artist.id.should == 789
+ releases.size.should == 2
+ releases.total_entries.should == 50
+
+ end
+
end
View
6 spec/digestion_tract/tag_digestor_spec.rb
@@ -15,7 +15,7 @@
</xxx>
XML
- running {@tag_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@tag_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should parse from xml and populate minimum available properties" do
@@ -26,7 +26,7 @@
</tag>
XML
- tag = @tag_digestor.from_xml_nokogiri(xml_response)
+ tag = @tag_digestor.from_xml_string(xml_response)
tag.id.should == 'rock'
tag.text.should == "ROCK"
@@ -36,7 +36,7 @@
xml_response = load_sample_object_xml("tag")
- tag = @tag_digestor.from_xml_nokogiri(xml_response)
+ tag = @tag_digestor.from_xml_string(xml_response)
tag.id.should == "pop"
tag.text.should == "pop"
tag.url.should == "http://www.7digital.com/tags/pop?partner=123"
View
6 spec/digestion_tract/track_digestor_spec.rb
@@ -16,7 +16,7 @@
</artist>
XML
- running {@track_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@track_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should digest track xml and populate minimum available properties" do
@@ -31,7 +31,7 @@
</track>
XML
- track = @track_digestor.from_xml_nokogiri(xml_response)
+ track = @track_digestor.from_xml_string(xml_response)
track.id.should == 123
track.title.should == "expected track title"
track.artist.id.should == 345
@@ -43,7 +43,7 @@
xml_response = load_sample_object_xml("track")
- track = @track_digestor.from_xml_nokogiri(xml_response)
+ track = @track_digestor.from_xml_string(xml_response)
track.id.should == 1628015
track.title.should == "Burning"
track.version.should == ""
View
6 spec/digestion_tract/user_card_digestor_spec.rb
@@ -15,7 +15,7 @@
</xxx>
XML
- running {@card_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@card_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should parse from xml and populate minimum available properties" do
@@ -27,7 +27,7 @@
</card>
XML
- card = @card_digestor.from_xml_nokogiri(xml_response)
+ card = @card_digestor.from_xml_string(xml_response)
card.type.should == "MasterCard"
card.last_4_digits.should == "1234"
@@ -37,7 +37,7 @@
xml_response = load_sample_object_xml("user_payment_card")
- card = @card_digestor.from_xml_nokogiri(xml_response)
+ card = @card_digestor.from_xml_string(xml_response)
card.id.should == 9876
card.type.should == "VISA"
card.last_4_digits.should == "2345"
View
6 spec/digestion_tract/user_digestor_spec.rb
@@ -15,7 +15,7 @@
</xxx>
XML
- running {@user_digestor.from_xml_nokogiri(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
+ running {@user_digestor.from_xml_string(xml_response)}.should raise_error(Sevendigital::DigestiveProblem)
end
it "should parse from xml and populate minimum available properties" do
@@ -26,7 +26,7 @@
</user>
XML
- user = @user_digestor.from_xml_nokogiri(xml_response)
+ user = @user_digestor.from_xml_string(xml_response)
user.type.should == :"7digital"
end
@@ -35,7 +35,7 @@
xml_response = load_sample_object_xml("user")
- user = @user_digestor.from_xml_nokogiri(xml_response)
+ user = @user_digestor.from_xml_string(xml_response)
user.id.should == "123456"
user.type.should == :"7digital"
user.email_address.should == "user@example.com"
View
86 spec/integration/artist_spec.rb
@@ -0,0 +1,86 @@
+# encoding: UTF-8
+require File.expand_path('../../spec_helper', __FILE__)
+
+describe "Artist integration test" do
+
+ before do
+ @api_client = Sevendigital::Client.new(
+ File.join(File.dirname(__FILE__),"sevendigital_spec.yml"),
+ :verbose => "verbose"
+ )
+
+ end
+
+ it "should browse artists" do
+ artists = @api_client.artist.browse("KEA")
+ artists.current_page.should == 1
+ artists.total_entries.should >= 1
+ artists.each do |artist|
+ artist.name[0..2].should == "Kea"
+ artist.id.should >= 1
+ artist.url.should =~ VALID_7DIGITAL_URL
+ end
+ end
+
+ it "should get artist chart" do
+ chart = @api_client.artist.get_chart(:period => :year, :toDate => 20111231)
+ chart.current_page.should == 1
+ chart.total_entries.should >= 20
+ chart.first.position.should == 1
+ chart.last.position.should == 10
+ chart.first.item.id.should == 142111
+ chart.first.item.name.should == "Adele"
+ end
+
+ it "should get artist details" do
+ artist = @api_client.artist.get_details(1)
+ artist.name.should == "Keane"
+ artist.id.should == 1
+ end
+
+ it "should get artist releases" do
+ releases = @api_client.artist.get_details(1).get_releases(:type => :single)
+ releases.current_page.should == 1
+ releases.total_entries.should >= 1
+ releases.each do |release|
+ release.artist.name.should == "Keane"
+ release.id.should >= 1
+ release.title.should_not be_empty
+ release.label.should_not be_nil
+ release.year.should >= 1990
+ release.type.should == :single
+ end
+ end
+
+ it "should search and find an artist" do
+ artists = @api_client.artist.search("keane")
+ artists.current_page.should == 1
+ artists.total_entries.should >= 1
+ artists.first.name.should == "Keane"
+ artists.first.id.should == 1
+ end
+
+ it "should get top tracks" do
+ tracks = @api_client.artist.get_details(1).get_top_tracks
+ tracks.current_page.should == 1
+ tracks.total_entries.should >= 1
+ tracks.each do |track|
+ track.artist.name.should == "Keane"
+ track.id.should >= 1
+ track.title.should_not be_empty
+ track.release.should_not be_nil
+ end
+ end
+
+ it "should get similar artists" do
+ artists = @api_client.artist.get_details(1).get_similar
+ artists.current_page.should == 1
+ artists.total_entries.should >= 1
+ artists.each do |artist|
+ artist.name.should_not be_empty
+ artist.id.should >= 1
+ artist.url.should =~ VALID_7DIGITAL_URL
+ end
+ end
+
+end
View
34 spec/integration/release_spec.rb
@@ -0,0 +1,34 @@
+# encoding: UTF-8
+require File.expand_path('../../spec_helper', __FILE__)
+require 'date'
+
+describe "Relase integration tests" do
+
+ before do
+ @api_client = Sevendigital::Client.new(
+ File.join(File.dirname(__FILE__),"sevendigital_spec.yml"),
+ :verbose => "verbose"
+ )
+
+ end
+
+ it "should get releases by date" do
+ releases = @api_client.release.get_by_date(Date.today, Date.today)
+ releases.each do |release|
+ release.id.should >= 1
+ release.title.should_not be_empty
+ release.artist.should_not be_nil
+ release.price.value.should >= 0
+ release.release_date.to_date.should == Date.today
+ end
+ end
+
+ it "should search and find releases" do
+ releases = @api_client.release.search("love", :page_size => 20, :page=>2)
+ releases.size.should == 20
+ releases.current_page.should == 2
+ releases.total_entries.should > 100
+ releases.first.price.value.should > 0
+ end
+
+end
View
2  spec/sevendigital_spec.yml → spec/integration/sevendigital_spec.yml
@@ -2,4 +2,4 @@
oauth_consumer_key: "YOUR_KEY_HERE"
oauth_consumer_secret: "YOUR_SECRET_HERE"
-lazy_load: true
+lazy_load: false
View
43 spec/management/artist_manager_spec.rb
@@ -11,10 +11,10 @@
it "get_details should call artist/details api method and return digested artist" do
an_artist_id = 123
an_artist = Sevendigital::Artist.new(@client)
- an_api_response = fake_api_response("release/details")
+ an_api_response = fake_api_response("artist/details")
mock_client_digestor(@client, :artist_digestor) \
- .should_receive(:from_xml).with(an_api_response.content.artist).and_return(an_artist)
+ .should_receive(:from_xml_doc).with(an_api_response.item_xml("artist")).and_return(an_artist)
@client.should_receive(:make_api_request) \
.with(:GET, "artist/details", {:artistId => an_artist_id}, {}) \
@@ -30,7 +30,7 @@
an_api_response = fake_api_response("artist/releases")
mock_client_digestor(@client, :release_digestor) \
- .should_receive(:list_from_xml).with(an_api_response.content.releases).and_return(a_list_of_releases)
+ .should_receive(:list_from_xml_doc).with(an_api_response.item_xml("releases")).and_return(a_list_of_releases)
@client.should_receive(:make_api_request) \
.with(:GET, "artist/releases", {:artistId => an_artist_id}, {}) \
@@ -46,7 +46,7 @@
an_api_response = fake_api_response("artist/toptracks")
mock_client_digestor(@client, :track_digestor) \
- .should_receive(:list_from_xml).with(an_api_response.content.tracks).and_return(a_top_tracks_list)
+ .should_receive(:list_from_xml_doc).with(an_api_response.item_xml("tracks")).and_return(a_top_tracks_list)
@client.should_receive(:make_api_request) \
.with(:GET, "artist/topTracks", {:artistId => an_artist_id}, {}) \
@@ -63,7 +63,7 @@
an_api_response = fake_api_response("artist/similar")
mock_client_digestor(@client, :artist_digestor) \
- .should_receive(:list_from_xml).with(an_api_response.content.artists).and_return(a_similar_artists_list)
+ .should_receive(:list_from_xml_doc).with(an_api_response.item_xml("artists")).and_return(a_similar_artists_list)
@client.should_receive(:make_api_request) \
.with(:GET, "artist/similar", {:artistId => an_artist_id}, {}) \
@@ -81,8 +81,8 @@
a_release_list = []
mock_client_digestor(@client, :artist_digestor) \
- .should_receive(:nested_list_from_xml) \
- .with(an_api_response.content.tagged_results, :tagged_item, :tagged_results) \
+ .should_receive(:nested_list_from_xml_doc) \
+ .with(an_api_response.item_xml("taggedResults"), :taggedItem, :artist) \
.and_return(a_release_list)
@client.should_receive(:make_api_request) \
@@ -94,6 +94,27 @@
end
+ it "search should call artist/search api method and digest the nested artist list from response" do
+
+ query = "radiohead"
+ api_response = fake_api_response("artist/search")
+ an_artist_list = []
+
+ mock_client_digestor(@client, :artist_digestor) \
+ .should_receive(:nested_list_from_xml_doc) \
+ .with(api_response.item_xml("searchResults"), :searchResult, :artist) \
+ .and_return(an_artist_list)
+
+ @client.should_receive(:make_api_request) \
+ .with(:GET, "artist/search", {:q => query}, {}) \
+ .and_return(api_response)
+
+ artists = @artist_manager.search(query)
+ artists.should == an_artist_list
+
+ end
+
+
it "browse should call artist/browse api method and digest the artist list from response" do
letter = "ra"
@@ -101,8 +122,8 @@
an_artist_list = []
mock_client_digestor(@client, :artist_digestor) \
- .should_receive(:list_from_xml) \
- .with(an_api_response.content.artists) \
+ .should_receive(:list_from_xml_doc) \
+ .with(an_api_response.item_xml("artists")) \
.and_return(an_artist_list)
@client.should_receive(:make_api_request) \
@@ -121,7 +142,7 @@
a_chart = [Sevendigital::ChartItem.new(@client)]
mock_client_digestor(@client, :chart_item_digestor) \
- .should_receive(:list_from_xml).with(api_response.content.chart).and_return(a_chart)
+ .should_receive(:list_from_xml_doc).with(api_response.item_xml("chart")).and_return(a_chart)
@client.should_receive(:make_api_request) \
.with(:GET, "artist/chart", {}, {}) \
@@ -139,7 +160,7 @@
options = {:page => 1}
mock_client_digestor(@client, :tag_digestor) \
- .should_receive(:list_from_xml).with(an_api_response.content.tags).and_return(a_list_of_tags)
+ .should_receive(:list_from_xml_doc).with(an_api_response.item_xml("tags")).and_return(a_list_of_tags)
@client.should_receive(:make_api_request) \
.with(:GET, "artist/tags", {:artistId => an_artist_id}, options) \
View
8 spec/management/basket_manager_spec.rb
@@ -14,7 +14,7 @@
an_api_response = fake_api_response("basket/index")
mock_client_digestor(@client, :basket_digestor) \
- .should_receive(:from_xml).with(an_api_response.content.basket).and_return(a_basket)
+ .should_receive(:from_xml_doc).with(an_api_response.item_xml("basket")).and_return(a_basket)
@client.should_receive(:make_api_request) \
.with(:GET, "basket", {:basketId => a_basket_id}, {}) \
@@ -29,7 +29,7 @@
an_api_response = fake_api_response("basket/create")
mock_client_digestor(@client, :basket_digestor) \
- .should_receive(:from_xml).with(an_api_response.content.basket).and_return(a_basket)
+ .should_receive(:from_xml_doc).with(an_api_response.item_xml("basket")).and_return(a_basket)
@client.should_receive(:make_api_request) \
.with(:GET, "basket/create", {}, {}) \
@@ -47,7 +47,7 @@
an_api_response = fake_api_response("basket/additem")
mock_client_digestor(@client, :basket_digestor) \
- .should_receive(:from_xml).with(an_api_response.content.basket).and_return(a_basket)
+ .should_receive(:from_xml_doc).with(an_api_response.item_xml("basket")).and_return(a_basket)
@client.should_receive(:make_api_request) \
.with(:GET, "basket/addItem", {:basketId => a_basket_id, :releaseId => a_release_id, :trackId => a_track_id}, {}) \
@@ -64,7 +64,7 @@
an_api_response = fake_api_response("basket/removeitem")
mock_client_digestor(@client, :basket_digestor) \
- .should_receive(:from_xml).with(an_api_response.content.basket).and_return(a_basket)
+ .should_receive(:from_xml_doc).with(an_api_response.item_xml("basket")).and_return(a_basket)
@client.should_receive(:make_api_request) \
.with(:GET, "basket/removeItem", {:basketId => a_basket_id, :itemId => an_item_id}, {}) \
View
8 spec/management/oauth_manager_spec.rb
@@ -17,8 +17,8 @@
digestor = mock(Sevendigital::OAuthRequestTokenDigestor)
@client.stub!(:oauth_request_token_digestor).and_return(digestor)
- digestor.should_receive(:from_xml) \
- .with(an_api_response.content.oauth_request_token, :oauth_request_token) \
+ digestor.should_receive(:from_xml_doc) \
+ .with(an_api_response.item_xml("oauth_request_token"), :oauth_request_token) \
.and_return(fake_token)
@client.should_receive(:make_signed_api_request) \
@@ -39,8 +39,8 @@
digestor = mock(Sevendigital::OAuthAccessTokenDigestor)
@client.stub!(:oauth_access_token_digestor).and_return(digestor)
- digestor.should_receive(:from_xml) \
- .with(an_api_response.content.oauth_access_token, :oauth_access_token) \
+ digestor.should_receive(:from_xml_doc) \
+ .with(an_api_response.item_xml("oauth_access_token"), :oauth_access_token) \
.and_return(fake_token)
@client.should_receive(:make_signed_api_request) \
View
26 spec/management/release_manager_spec.rb
@@ -18,7 +18,7 @@
a_release = Sevendigital::Release.new(@client)
mock_client_digestor(@client, :release_digestor) \
- .should_receive(:from_xml).with(api_response.content.release).and_return(a_release)
+ .should_receive(:from_xml_doc).with(api_response.item_xml("release")).and_return(a_release)
@client.should_receive(:make_api_request) \
.with(:GET, "release/details", {:releaseId => expected_release_id}, {}) \
@@ -35,7 +35,7 @@
a_track_list = []
mock_client_digestor(@client, :track_digestor) \
- .should_receive(:list_from_xml).with(api_response.content.tracks).and_return(a_track_list)
+ .should_receive(:list_from_xml_doc).with(api_response.item_xml("tracks")).and_return(a_track_list)
@client.should_receive(:make_api_request) \
.with(:GET, "release/tracks", {:releaseId=>a_release_id}, expected_options) \
@@ -53,7 +53,7 @@
a_track_list = []
mock_client_digestor(@client, :track_digestor) \
- .should_receive(:list_from_xml).with(api_response.content.tracks).and_return(a_track_list)
+ .should_receive(:list_from_xml_doc).with(api_response.item_xml("tracks")).and_return(a_track_list)
@client.should_receive(:make_api_request) \
.with(:GET, "release/tracks", {:releaseId => a_release_id}, {:page_size => 100}) \
@@ -71,7 +71,7 @@
a_chart = []
mock_client_digestor(@client, :chart_item_digestor) \
- .should_receive(:list_from_xml).with(api_response.content.chart).and_return(a_chart)
+ .should_receive(:list_from_xml_doc).with(api_response.item_xml("chart")).and_return(a_chart)
@client.should_receive(:make_api_request) \
.with(:GET, "release/chart", {}, {}) \
@@ -89,7 +89,7 @@
a_release_list = []
mock_client_digestor(@client, :release_digestor) \
- .should_receive(:list_from_xml).with(api_response.content.releases).and_return(a_release_list)
+ .should_receive(:list_from_xml_doc).with(api_response.item_xml("releases")).and_return(a_release_list)
@client.should_receive(:make_api_request) \
.with(:GET, "release/byDate", {:fromDate => from_date.strftime("%Y%m%d"), :toDate => to_date.strftime("%Y%m%d")}, {}) \
@@ -106,7 +106,7 @@
a_release_list = []
mock_client_digestor(@client, :release_digestor) \
- .should_receive(:list_from_xml).with(api_response.content.releases).and_return(a_release_list)
+ .should_receive(:list_from_xml_doc).with(api_response.item_xml("releases")).and_return(a_release_list)
@client.should_receive(:make_api_request) \
.with(:GET, "release/byDate", {}, {}) \
@@ -124,8 +124,8 @@
a_release_list = []
mock_client_digestor(@client, :release_digestor) \
- .should_receive(:nested_list_from_xml) \
- .with(api_response.content.recommendations, :recommended_item, :recommendations) \
+ .should_receive(:nested_list_from_xml_doc) \
+ .with(api_response.item_xml("recommendations"), :recommendedItem, :release) \
.and_return(a_release_list)
@client.should_receive(:make_api_request) \
@@ -144,8 +144,8 @@
a_release_list = []
mock_client_digestor(@client, :release_digestor) \
- .should_receive(:nested_list_from_xml) \
- .with(api_response.content.tagged_results, :tagged_item, :tagged_results) \
+ .should_receive(:nested_list_from_xml_doc) \
+ .with(api_response.item_xml("taggedResults"), :taggedItem, :release) \
.and_return(a_release_list)
@client.should_receive(:make_api_request) \
@@ -164,8 +164,8 @@
a_release_list = []
mock_client_digestor(@client, :release_digestor) \
- .should_receive(:nested_list_from_xml) \
- .with(api_response.content.search_results, :search_result, :search_results) \
+ .should_receive(:nested_list_from_xml_doc) \
+ .with(api_response.item_xml("searchResults"), :searchResult, :release) \
.and_return(a_release_list)
@client.should_receive(:make_api_request) \
@@ -184,7 +184,7 @@
a_tag_list = []
mock_client_digestor(@client, :tag_digestor) \
- .should_receive(:list_from_xml).with(api_response.content.tags).and_return(a_tag_list)
+ .should_receive(:list_from_xml_doc).with(api_response.item_xml("tags")).and_return(a_tag_list)
@client.should_receive(:make_api_request) \
.with(:GET, "release/tags", {:releaseId=>a_release_id}, expected_options) \
View
2  spec/management/tag_manager_spec.rb
@@ -19,7 +19,7 @@
a_tag_list = [Sevendigital::Tag.new]
mock_client_digestor(@client, :tag_digestor) \
- .should_receive(:list_from_xml).with(an_api_response.content.tags).and_return(a_tag_list)
+ .should_receive(:list_from_xml_doc).with(an_api_response.item_xml("tags") ).and_return(a_tag_list)
@client.should_receive(:make_api_request) \
.with(:GET, "tag", {}, {}) \
View
8 spec/management/track_manager_spec.rb
@@ -18,7 +18,7 @@
a_track = Sevendigital::Track.new(@client)
mock_client_digestor(@client, :track_digestor) \
- .should_receive(:from_xml).with(an_api_response.content.track).and_return(a_track)
+ .should_receive(:from_xml_doc).with(an_api_response.item_xml("track")).and_return(a_track)
@client.should_receive(:make_api_request) \
.with(:GET, "track/details", {:trackId => a_track_id}, {}) \
@@ -54,7 +54,7 @@
a_chart = []
mock_client_digestor(@client, :chart_item_digestor) \
- .should_receive(:list_from_xml).with(an_api_response.content.chart).and_return(a_chart)
+ .should_receive(:list_from_xml_doc).with(an_api_response.item_xml("chart")).and_return(a_chart)
@client.should_receive(:make_api_request) \
.with(:GET, "track/chart", {}, {}) \
@@ -90,8 +90,8 @@
a_track_list = [Sevendigital::Track.new(@client)]
mock_client_digestor(@client, :track_digestor) \
- .should_receive(:nested_list_from_xml) \
- .with(an_api_response.content.search_results, :search_result, :search_results) \
+ .should_receive(:nested_list_from_xml_doc) \
+ .with(an_api_response.item_xml("searchResults"), :searchResult, :track) \
.and_return(a_track_list)
@client.should_receive(:make_api_request) \
View
4 spec/management/user_card_manager_spec.rb
@@ -15,7 +15,7 @@
options = {:pagesize => 20 }
mock_client_digestor(@client, :user_card_digestor) \
- .should_receive(:list_from_xml).with(an_api_response.content.cards).and_return(a_card_list)
+ .should_receive(:list_from_xml_doc).with(an_api_response.item_xml("cards")).and_return(a_card_list)
@client.should_receive(:make_signed_api_request) \
.with(:GET, "user/payment/card", {}, options, a_token) \
@@ -41,7 +41,7 @@
options = {:pagesize => 20 }
mock_client_digestor(@client, :user_card_digestor) \
- .should_receive(:from_xml).with(an_api_response.content.card).and_return(a_card)
+ .should_receive(:from_xml_doc).with(an_api_response.item_xml("card")).and_return(a_card)
@client.should_receive(:make_signed_api_request) \
.with(:POST, "user/payment/card/add", {
View
8 spec/management/user_manager_spec.rb
@@ -39,7 +39,7 @@
options = {:country => "XX"}
mock_client_digestor(@client, :user_digestor) \
- .should_receive(:from_xml).with(an_api_response.content.user).and_return(fake_user)
+ .should_receive(:from_xml_doc).with(an_api_response.item_xml("user")).and_return(fake_user)
@client.should_receive(:make_signed_api_request) \
.with(:POST, "user/signUp", {:emailAddress => @an_email, :password => @a_password}, options) \
@@ -101,7 +101,7 @@ def fake_access_token
options = {:sort => "random"}
mock_client_digestor(@client, :locker_digestor) \
- .should_receive(:from_xml).with(an_api_response.content.locker).and_return(fake_locker)
+ .should_receive(:from_xml_doc).with(an_api_response.item_xml("locker")).and_return(fake_locker)
@client.should_receive(:make_signed_api_request) \
.with(:GET, "user/locker", {}, options, a_token) \
@@ -120,7 +120,7 @@ def fake_access_token
fake_locker = [Sevendigital::LockerRelease.new(@client)]
mock_client_digestor(@client, :locker_digestor) \
- .should_receive(:from_xml).with(an_api_response.content.purchase).and_return(fake_locker)
+ .should_receive(:from_xml_doc).with(an_api_response.item_xml("purchase")).and_return(fake_locker)
@client.should_receive(:make_signed_api_request) \
.with(:GET, "user/purchase/item", \
@@ -139,7 +139,7 @@ def fake_access_token
fake_locker = [Sevendigital::LockerRelease.new(@client)]
mock_client_digestor(@client, :locker_digestor) \
- .should_receive(:from_xml).with(an_api_response.content.purchase).and_return(fake_locker)
+ .should_receive(:from_xml_doc).with(an_api_response.item_xml("purchase")).and_return(fake_locker)
@client.should_receive(:make_signed_api_request) \
.with(:GET, "user/purchase/basket", \
View
6 spec/model/api_response_spec.rb
@@ -30,8 +30,8 @@
end
it "should be serializable" do
- original_response = Sevendigital::ApiResponseDigestor.new(@client).from_xml\
- ("<response status='ok'><testElement id='123'>value</testElement></response>")
+ original_response = Sevendigital::ApiResponse.new
+ original_response.content = "<response status='ok'><testElement id='123'>value</testElement></response>"
original_response.error_code = 99
original_response.headers = {"header" => "value"}
@@ -41,7 +41,7 @@
restored_response.error_code.should == original_response.error_code
restored_response.content.to_s.should == original_response.content.to_s
- restored_response.content.test_element.value.should == "value"
+ restored_response.item_xml("response").to_s == "value"
restored_response.headers.should == original_response.headers
end
View
7 spec/peachy_spec_helper_patch.rb
@@ -1,7 +0,0 @@
-module Peachy
- class Proxy
- def ==(other_proxy)
- (to_s == other_proxy.to_s)
- end
- end
-end
View
70 spec/proxy_police_spec.rb
@@ -1,70 +0,0 @@
-# encoding: UTF-8
-require 'date'
-require "spec_helper"
-
-describe "Proxy Police" do
-
- it "should create a Peachy proxy from xml string with root element with given name" do
-
- xml = <<XML
- <rootElement id="123">
- <subElement>expected value</subElement>
- </rootElement>
-XML
-
- proxy = Sevendigital::ProxyPolice.create_release_proxy(xml, :root_element)
- proxy.kind_of?(Peachy::Proxy).should == true
- proxy.sub_element.value.should == "expected value"
- end
-
- it "should create a Peachy proxy from root of the xml string if no element name given" do
-
- xml = <<XML
- <rootElement id="123">
- <subElement>expected value</subElement>
- </rootElement>
-XML
-
- proxy = Sevendigital::ProxyPolice.create_release_proxy(xml, nil)
- proxy.kind_of?(Peachy::Proxy).should == true
- proxy.root_element.sub_element.value.should == "expected value"
-
- end
-
- it "should not create a Peachy proxy from xml string without root element with given name" do
-
- xml = <<XML
- <rootElement id="123">
- <subElement>expected value</subElement>
- </rootElement>
-XML
-
- proxy = Sevendigital::ProxyPolice.create_release_proxy(xml, :different_element)
- proxy.should == nil
-
- end
-
- it "should just return the input if passed in Peachy proxy " do
-
- xml = <<XML
- <rootElement id="123">
- <subElement>expected value</subElement>
- </rootElement>
-XML
- proxy = Peachy::Proxy.new(xml)
- checked_proxy = Sevendigital::ProxyPolice.ensure_is_proxy(proxy, nil)
- checked_proxy.should == proxy
-
- end
-
- it "should just return the input if passed in Peachy SimpleContent " do
-
- xml = "<element/>"
- proxy = Peachy::SimpleContent.new(xml)
- checked_proxy = Sevendigital::ProxyPolice.ensure_is_proxy(proxy, nil)
- checked_proxy.should == proxy
-
- end
-
-
-end
View
12 spec/sevendigital_spec.rb
@@ -11,18 +11,6 @@
end
- it "should find an artist" do
- @api_client.artist.search("keane").first.name.should == "Keane"
- end
-
- it "should find at least 20 releases" do
- releases = @api_client.release.search("love", :page_size => 20, :page=>2)
- releases.size.should == 20
- releases.current_page.should == 2
- releases.total_entries.should > 100
- releases.first.price.value.should > 0
- end
-
it "should find a track with price" do
track = @api_client.track.search("radiohead creep").first
track.artist.appears_as.should == "Radiohead"
View
17 spec/spec_helper.rb
@@ -2,25 +2,18 @@
#$: << 'spec'
=begin
-
require 'simplecov'
-
SimpleCov.start do
add_group 'Management', 'lib/sevendigital/management'
add_group 'Digestion', 'lib/sevendigital/digestion_tract'
add_group 'Model', 'lib/sevendigital/model'
end
-
=end
require 'rspec'
require File.expand_path(
File.join(File.dirname(__FILE__), %w[.. lib sevendigital]))
-require "peachy_spec_helper_patch"
-
-Peachy.whine
-
Rspec.configure do |config|
# == Mock Framework
#
@@ -34,6 +27,8 @@
alias running lambda
+ VALID_7DIGITAL_URL = /http\:\/\/.+7digital\..+partner=[\d]+/
+
def load_sample_method_xml(method_name)
method_name = "test-xml/methods/" + method_name + ".xml"
IO.read( File.join(File.dirname(__FILE__), method_name.split('/')))
@@ -45,11 +40,15 @@ def load_sample_object_xml(method_name)
end
def fake_api_response(method_name)
- Sevendigital::ApiResponseDigestor.new(nil).from_xml(load_sample_method_xml(method_name))
+ response = Sevendigital::ApiResponse.new
+ response.content = load_sample_method_xml(method_name)
+ response.stub(:ok?).and_return true
+# Sevendigital::ApiResponseDigestor.new(nil).from_xml_string(load_sample_method_xml(method_name))
+ response
end
def fake_api_error_response(code)
- Sevendigital::ApiResponseDigestor.new(nil).from_xml("<response status=\"error\"><error code=\"#{code}\"></error></response>")
+ Sevendigital::ApiResponseDigestor.new(nil).from_xml_string("<response status=\"error\"><error code=\"#{code}\"></error></response>")
end
def mock_client_digestor(client, digestor_class)
View
23 spec/test-xml/objects/nested_release_list.xml
@@ -0,0 +1,23 @@
+<results>
+ <page>1</page>
+ <pageSize>2</pageSize>
+ <totalItems>50</totalItems>
+ <result>
+ <release id="123">
+ <title>expected release title</title>
+ <artist id="345">
+ <name>expected artist name</name>
+ <appearsAs>expected displayed artist name</appearsAs>
+ </artist>
+ </release>
+ </result>
+ <result>
+ <release id="456">
+ <title>expected release title</title>
+ <artist id="789">
+ <name>expected artist name</name>
+ <appearsAs>expected displayed artist name</appearsAs>
+ </artist>
+ </release>
+ </result>
+</results>
Please sign in to comment.
Something went wrong with that request. Please try again.