7digital 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -0
- data/lib/peachy_patchy.rb +14 -0
- data/lib/sevendigital.rb +53 -0
- data/lib/sevendigital/api_operator.rb +31 -0
- data/lib/sevendigital/api_operator_cached.rb +23 -0
- data/lib/sevendigital/api_request.rb +24 -0
- data/lib/sevendigital/client.rb +124 -0
- data/lib/sevendigital/default_configuration.yml +2 -0
- data/lib/sevendigital/digestion_tract/api_response_digestor.rb +52 -0
- data/lib/sevendigital/digestion_tract/artist_digestor.rb +31 -0
- data/lib/sevendigital/digestion_tract/chart_item_digestor.rb +27 -0
- data/lib/sevendigital/digestion_tract/digestor.rb +66 -0
- data/lib/sevendigital/digestion_tract/format_digestor.rb +21 -0
- data/lib/sevendigital/digestion_tract/label_digestor.rb +20 -0
- data/lib/sevendigital/digestion_tract/pager_digestor.rb +23 -0
- data/lib/sevendigital/digestion_tract/price_digestor.rb +25 -0
- data/lib/sevendigital/digestion_tract/release_digestor.rb +52 -0
- data/lib/sevendigital/digestion_tract/track_digestor.rb +37 -0
- data/lib/sevendigital/management/artist_manager.rb +39 -0
- data/lib/sevendigital/management/manager.rb +11 -0
- data/lib/sevendigital/management/release_manager.rb +51 -0
- data/lib/sevendigital/management/track_manager.rb +18 -0
- data/lib/sevendigital/model/api_response.rb +13 -0
- data/lib/sevendigital/model/artist.rb +37 -0
- data/lib/sevendigital/model/chart_item.rb +9 -0
- data/lib/sevendigital/model/format.rb +9 -0
- data/lib/sevendigital/model/label.rb +9 -0
- data/lib/sevendigital/model/price.rb +11 -0
- data/lib/sevendigital/model/release.rb +34 -0
- data/lib/sevendigital/model/sevendigital_error.rb +3 -0
- data/lib/sevendigital/model/sevendigital_object.rb +51 -0
- data/lib/sevendigital/model/track.rb +8 -0
- data/lib/sevendigital/pager.rb +17 -0
- data/lib/sevendigital/proxy_police.rb +24 -0
- data/lib/sevendigital/version.rb +3 -0
- data/spec/api_operator_cached_spec.rb +47 -0
- data/spec/api_operator_spec.rb +108 -0
- data/spec/api_request_spec.rb +27 -0
- data/spec/client_spec.rb +46 -0
- data/spec/data/config/sevendigital.yml +5 -0
- data/spec/data/configuration_env_override.yml +5 -0
- data/spec/data/configuration_override.yml +1 -0
- data/spec/digestion_tract/api_response_digestor_spec.rb +74 -0
- data/spec/digestion_tract/artist_digestor_spec.rb +83 -0
- data/spec/digestion_tract/chart_digestor_spec.rb +54 -0
- data/spec/digestion_tract/format_digestor_spec.rb +40 -0
- data/spec/digestion_tract/label_digestor_spec.rb +35 -0
- data/spec/digestion_tract/pager_digestor_spec.rb +52 -0
- data/spec/digestion_tract/price_digestor_spec.rb +57 -0
- data/spec/digestion_tract/release_digestor_spec.rb +102 -0
- data/spec/digestion_tract/track_digestor_spec.rb +107 -0
- data/spec/management/artist_manager_spec.rb +108 -0
- data/spec/management/release_manager_spec.rb +178 -0
- data/spec/management/track_manager_spec.rb +52 -0
- data/spec/model/api_response_spec.rb +32 -0
- data/spec/model/artist_spec.rb +122 -0
- data/spec/model/release_spec.rb +111 -0
- data/spec/pager_spec.rb +8 -0
- data/spec/proxy_police_spec.rb +49 -0
- data/spec/spec_helper.rb +48 -0
- data/spec/test-xml/methods/artist/byTag/top.xml +51 -0
- data/spec/test-xml/methods/artist/details.xml +10 -0
- data/spec/test-xml/methods/artist/releases.xml +545 -0
- data/spec/test-xml/methods/artist/similar.xml +40 -0
- data/spec/test-xml/methods/artist/toptracks.xml +280 -0
- data/spec/test-xml/methods/release/bydate.xml +174 -0
- data/spec/test-xml/methods/release/bytag/top.xml +151 -0
- data/spec/test-xml/methods/release/chart.xml +182 -0
- data/spec/test-xml/methods/release/details.xml +49 -0
- data/spec/test-xml/methods/release/recommend.xml +90 -0
- data/spec/test-xml/methods/release/tracks.xml +29 -0
- data/spec/test-xml/methods/track/chart.xml +150 -0
- data/spec/test-xml/methods/track/details.xml +31 -0
- data/spec/test-xml/objects/artist.xml +7 -0
- data/spec/test-xml/objects/artist_chart_item.xml +8 -0
- data/spec/test-xml/objects/artist_list.xml +23 -0
- data/spec/test-xml/objects/artist_list_empty.xml +5 -0
- data/spec/test-xml/objects/price.xml +8 -0
- data/spec/test-xml/objects/release.xml +40 -0
- data/spec/test-xml/objects/release_chart_item.xml +34 -0
- data/spec/test-xml/objects/release_list.xml +19 -0
- data/spec/test-xml/objects/release_list_empty.xml +5 -0
- data/spec/test-xml/objects/track.xml +34 -0
- data/spec/test-xml/objects/track_chart_item.xml +28 -0
- metadata +151 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
class Class
|
2
|
+
|
3
|
+
def sevendigital_basic_property(*properties)
|
4
|
+
@basic_properties = []
|
5
|
+
properties.each do |property|
|
6
|
+
@basic_properties << "@#{property}".to_sym
|
7
|
+
sevendigital_extended_property property, :get_details
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def sevendigital_extended_property(accessor, get_method = nil)
|
12
|
+
|
13
|
+
get_method ||= "get_#{accessor.to_s}".to_sym
|
14
|
+
demand_method = "demand_#{accessor.to_s}".to_sym
|
15
|
+
|
16
|
+
define_method(demand_method) do |*options|
|
17
|
+
if instance_variable_get("@#{accessor}") == nil then
|
18
|
+
value = send(get_method, *options)
|
19
|
+
instance_variable_set("@#{accessor}", value) if get_method != :get_details
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
define_method("#{accessor}") do |*options|
|
24
|
+
send(demand_method, *options) if instance_variable_get("@#{accessor}").nil? && @api_client.configuration.lazy_load?
|
25
|
+
instance_variable_get("@#{accessor}")
|
26
|
+
end
|
27
|
+
|
28
|
+
define_method("#{accessor}=") do |val|
|
29
|
+
instance_variable_set("@#{accessor}",val)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module Sevendigital
|
35
|
+
|
36
|
+
class SevendigitalObject
|
37
|
+
|
38
|
+
def initialize(api_client)
|
39
|
+
@api_client = api_client
|
40
|
+
end
|
41
|
+
|
42
|
+
def copy_basic_properties_from(other_object)
|
43
|
+
self.class.instance_variable_get(:@basic_properties).each do |property|
|
44
|
+
instance_variable_set(property, other_object.instance_variable_get(property))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "will_paginate/collection"
|
2
|
+
|
3
|
+
module Sevendigital
|
4
|
+
|
5
|
+
class Pager
|
6
|
+
attr_accessor :page, :page_size, :total_items
|
7
|
+
|
8
|
+
def paginate_list(list)
|
9
|
+
paged_list = WillPaginate::Collection.create(@page, @page_size, @total_items) do |pager|
|
10
|
+
pager.replace(list)
|
11
|
+
end
|
12
|
+
return paged_list
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Sevendigital
|
2
|
+
class ProxyPolice
|
3
|
+
|
4
|
+
def ProxyPolice.ensure_is_proxy(xml_or_proxy, element_name)
|
5
|
+
if xml_or_proxy.kind_of? Peachy::Proxy then
|
6
|
+
return xml_or_proxy
|
7
|
+
else
|
8
|
+
return ProxyPolice.create_release_proxy(xml_or_proxy, element_name)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def ProxyPolice.create_release_proxy(xml, element_name)
|
13
|
+
#TODO don't use eval
|
14
|
+
parent_proxy = Peachy::Proxy.new(xml)
|
15
|
+
if element_name
|
16
|
+
# parent_proxy.send(element_name)
|
17
|
+
eval "parent_proxy.#{element_name.to_s}"
|
18
|
+
else
|
19
|
+
parent_proxy
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec"
|
2
|
+
require 'sevendigital'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
describe "ApiOperatorCached" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@client = stub(Sevendigital::Client)
|
9
|
+
@cache = stub(Hash)
|
10
|
+
@cached_operator = Sevendigital::ApiOperatorCached.new(@client, @cache)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not make an http request if response already in cache " do
|
14
|
+
@cached_operator.stub(:create_request_uri).and_return("key")
|
15
|
+
@cache.stub!(:get).with("key").and_return(:something)
|
16
|
+
@cached_operator.should_not_receive(:make_http_request_and_digest)
|
17
|
+
@cached_operator.call_api(@stub_api_request)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should make an http request if response not yet in cache and return the result " do
|
21
|
+
api_response = fake_api_response()
|
22
|
+
|
23
|
+
@cached_operator.stub(:create_request_uri).and_return("key")
|
24
|
+
@cache.stub!(:get).with("key").and_return(nil)
|
25
|
+
@cache.stub!(:set).and_return(nil)
|
26
|
+
@cached_operator.should_receive(:make_http_request_and_digest).with("key").and_return(api_response)
|
27
|
+
|
28
|
+
response = @cached_operator.call_api(@stub_api_request)
|
29
|
+
response.should == api_response
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should cache uncached api response" do
|
33
|
+
api_response = fake_api_response()
|
34
|
+
|
35
|
+
@cached_operator.stub(:create_request_uri).and_return("key")
|
36
|
+
@cache.stub!(:get).with("key").and_return(nil)
|
37
|
+
@cached_operator.stub!(:make_http_request_and_digest).and_return(api_response)
|
38
|
+
|
39
|
+
@cache.should_receive(:set).with("key", api_response).and_return(nil)
|
40
|
+
response = @cached_operator.call_api(@stub_api_request)
|
41
|
+
end
|
42
|
+
|
43
|
+
def fake_api_response
|
44
|
+
return Net::HTTP.new("1.1", 200, "response_body")
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require "spec"
|
2
|
+
require 'sevendigital'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
describe "ApiOperator" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
response_digestor = stub(Sevendigital::ApiResponseDigestor)
|
9
|
+
response_digestor.stub!(:from_http_response).and_return(fake_digested_response)
|
10
|
+
|
11
|
+
stub_api_client(test_configuration, response_digestor)
|
12
|
+
|
13
|
+
Net::HTTP.stub!(:get_response).and_return(fake_api_response)
|
14
|
+
|
15
|
+
@api_operator = Sevendigital::ApiOperator.new(@client)
|
16
|
+
|
17
|
+
@stub_api_request = stub_api_request()
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create request URI based on api method and client configuration" do
|
22
|
+
|
23
|
+
api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
|
24
|
+
|
25
|
+
uri = @api_operator.create_request_uri(api_request)
|
26
|
+
|
27
|
+
uri.kind_of?(URI).should == true
|
28
|
+
uri.to_s.should == "http://base.api.url/version/api/method?oauth_consumer_key=oauth_consumer_key¶m1=value¶mTwo=2&country=sk"
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should make sure country is set before making request" do
|
33
|
+
@client.stub!(:country).and_return("sk")
|
34
|
+
|
35
|
+
@stub_api_request.should_receive(:ensure_country_is_set).with("sk")
|
36
|
+
|
37
|
+
@api_operator.call_api(@stub_api_request)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should make HTTP request and get response" do
|
42
|
+
|
43
|
+
Net::HTTP.should_receive(:get_response).with(@api_operator.create_request_uri(@stub_api_request))
|
44
|
+
|
45
|
+
@api_operator.call_api(@stub_api_request)
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should digest the HTTP response and get it out" do
|
50
|
+
|
51
|
+
http_response = fake_api_response
|
52
|
+
|
53
|
+
Net::HTTP.stub!(:get_response).and_return(http_response)
|
54
|
+
|
55
|
+
@client.api_response_digestor.should_receive(:from_http_response).with(http_response).and_return(fake_digested_response)
|
56
|
+
|
57
|
+
response = @api_operator.call_api(@stub_api_request)
|
58
|
+
|
59
|
+
response.kind_of?(Peachy::Proxy).should == true
|
60
|
+
response.to_s.should == fake_digested_response.to_s
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should throw an exception if response is not ok" do
|
65
|
+
|
66
|
+
Net::HTTP.stub(:get_response).and_return(fake_api_response)
|
67
|
+
failed_response = fake_digested_response(false)
|
68
|
+
@client.api_response_digestor.stub!(:from_http_response).and_return(failed_response)
|
69
|
+
|
70
|
+
running { @api_operator.call_api(@stub_api_request) }.should raise_error Sevendigital::SevendigitalError
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_configuration
|
75
|
+
configuration = OpenStruct.new
|
76
|
+
configuration.api_url = "base.api.url"
|
77
|
+
configuration.api_version = "version"
|
78
|
+
configuration.oauth_consumer_key = "oauth_consumer_key"
|
79
|
+
return configuration
|
80
|
+
end
|
81
|
+
|
82
|
+
def fake_api_response(code = 200, body = "response_body")
|
83
|
+
return Net::HTTP.new("1.1", code, body)
|
84
|
+
end
|
85
|
+
|
86
|
+
def fake_digested_response(is_ok = true)
|
87
|
+
proxy = Peachy::Proxy.new('<response status="ok"><content>test</content></response>')
|
88
|
+
proxy.stub!(:ok?).and_return(is_ok)
|
89
|
+
proxy
|
90
|
+
end
|
91
|
+
|
92
|
+
def stub_api_client(configuration, response_digestor)
|
93
|
+
@client = stub(Sevendigital::Client)
|
94
|
+
@client.stub!(:configuration).and_return(configuration)
|
95
|
+
@client.stub!(:api_response_digestor).and_return(response_digestor)
|
96
|
+
@client.stub!(:country).and_return("sk")
|
97
|
+
end
|
98
|
+
|
99
|
+
def stub_api_request
|
100
|
+
api_request = stub(Sevendigital::ApiRequest)
|
101
|
+
|
102
|
+
api_request.stub!(:parameters).and_return({})
|
103
|
+
api_request.stub!(:api_method).and_return("m")
|
104
|
+
api_request.stub!(:ensure_country_is_set)
|
105
|
+
return api_request
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec'
|
2
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
3
|
+
|
4
|
+
describe "ApiRequest" do
|
5
|
+
|
6
|
+
it "should merge method parameters and options with parameters taking preference" do
|
7
|
+
|
8
|
+
parameters = {:trackId => 123, :releaseId => 456, :country => "CU"}
|
9
|
+
options = {:page => 1, :country => "US", :trackId => "SS"}
|
10
|
+
request = Sevendigital::ApiRequest.new('method', parameters, options)
|
11
|
+
request.parameters[:trackId].should == 123
|
12
|
+
request.parameters[:releaseId].should == 456
|
13
|
+
request.parameters[:country].should == "CU"
|
14
|
+
request.parameters[:page].should == 1
|
15
|
+
request.parameters.keys.size.should == 4 # page_size == null
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should provide paging parameters in 7digital API format" do
|
20
|
+
|
21
|
+
request = Sevendigital::ApiRequest.new('method', {}, {:page => 5, :per_page => 3 })
|
22
|
+
request.parameters[:page].should == 5
|
23
|
+
request.parameters[:pageSize].should == 3
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec"
|
2
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
3
|
+
require 'sevendigital'
|
4
|
+
|
5
|
+
describe "Client" do
|
6
|
+
|
7
|
+
it "should load default configuration" do
|
8
|
+
client = Sevendigital::Client.new
|
9
|
+
client.configuration.api_url.should == 'api.7digital.com'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should override default configuration with configuration hash" do
|
13
|
+
client = Sevendigital::Client.new(:api_url => "test-hash.7digital.com")
|
14
|
+
client.configuration.api_url.should == 'test-hash.7digital.com'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should override default configuration with configuration class" do
|
18
|
+
client = Sevendigital::Client.new(OpenStruct.new(:api_url => "test-openstruct.7digital.com"))
|
19
|
+
client.configuration.api_url.should == 'test-openstruct.7digital.com'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should use simple configuration file" do
|
23
|
+
client = Sevendigital::Client.new(File.join(File.dirname(__FILE__),"data", "configuration_override.yml"))
|
24
|
+
client.configuration.api_url.should == 'test-yml-simple.7digital.com'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should use environment specific configuration file" do
|
28
|
+
client = Sevendigital::Client.new(File.join(File.dirname(__FILE__),"data", "configuration_env_override.yml"))
|
29
|
+
client.configuration.api_url.should == 'test-yml-common.7digital.com'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should use environment specific configuration file with environment specific settings" do
|
33
|
+
Object.const_set(:RAILS_ENV, "development")
|
34
|
+
client = Sevendigital::Client.new(File.join(File.dirname(__FILE__),"data", "configuration_env_override.yml"))
|
35
|
+
client.configuration.api_url.should == 'test-yml-development.7digital.com'
|
36
|
+
Object.instance_eval{ remove_const :RAILS_ENV }
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should use rails/config/sevendigital configuration as default rails settings" do
|
40
|
+
Object.const_set(:RAILS_ROOT, File.join(File.dirname(__FILE__),"data"))
|
41
|
+
client = Sevendigital::Client.new()
|
42
|
+
client.configuration.api_url.should == 'test-yml-rails-common.7digital.com'
|
43
|
+
Object.instance_eval{ remove_const :RAILS_ROOT }
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
api_url: test-yml-simple.7digital.com
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec'
|
2
|
+
require File.join(File.dirname(__FILE__), %w[../spec_helper])
|
3
|
+
|
4
|
+
|
5
|
+
describe "ApiResponseDigestor" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@api_response_digestor = Sevendigital::ApiResponseDigestor.new(nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should create a response with body from http ok response" do
|
12
|
+
|
13
|
+
stub_http_response = stub(Net::HTTPSuccess)
|
14
|
+
stub_http_response.stub!(:is_a?).with(Net::HTTPSuccess).and_return(true)
|
15
|
+
stub_http_response.stub!(:body).and_return('<response status="ok"></response>')
|
16
|
+
|
17
|
+
response = @api_response_digestor.from_http_response(stub_http_response)
|
18
|
+
response.error_code.should == 0
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create an error response from http non-ok response" do
|
22
|
+
expected_message = 'Authorisation failed'
|
23
|
+
expected_error_code = 401
|
24
|
+
|
25
|
+
stub_http_response = stub(Net::HTTPSuccess)
|
26
|
+
stub_http_response.stub!(:is_a?).with(Net::HTTPSuccess).and_return(false)
|
27
|
+
stub_http_response.stub!(:code).and_return(expected_error_code.to_s)
|
28
|
+
stub_http_response.stub!(:body).and_return(expected_message)
|
29
|
+
|
30
|
+
response = @api_response_digestor.from_http_response(stub_http_response)
|
31
|
+
response.error_code.should == 401
|
32
|
+
response.error_message.should == expected_message
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
it "should create a response with body from xml ok response" do
|
39
|
+
|
40
|
+
xml_response = <<XML
|
41
|
+
<response status="ok"><test></test></response>
|
42
|
+
XML
|
43
|
+
response = @api_response_digestor.from_xml(xml_response)
|
44
|
+
response.error_code.should == 0
|
45
|
+
response.content.test.should_not == nil
|
46
|
+
response.content.nothing.should == nil
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
it "should create a response with error details from xml error response" do
|
51
|
+
|
52
|
+
xml_response = '<response status="error"><error code="1000"><errorMessage>expected error message</errorMessage></error></response>'
|
53
|
+
response = @api_response_digestor.from_xml(xml_response)
|
54
|
+
response.error_code.should == 1000
|
55
|
+
response.error_message.should == 'expected error message'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should create a response with error details from invalid xml response" do
|
59
|
+
|
60
|
+
xml_response = '<wrongresponse status="ok"><test /></wrongresponse>'
|
61
|
+
response = @api_response_digestor.from_xml(xml_response)
|
62
|
+
response.error_code.should == 10000
|
63
|
+
response.error_message.should == 'Invalid 7digital API response'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should create a response with error details from valid xml response with invalid status" do
|
67
|
+
|
68
|
+
xml_response = '<response status="unkown"><test></test></response>'
|
69
|
+
response = @api_response_digestor.from_xml(xml_response)
|
70
|
+
response.error_code.should == 10000
|
71
|
+
response.error_message.should == 'Invalid 7digital API response'
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require "spec"
|
2
|
+
require "sevendigital"
|
3
|
+
|
4
|
+
describe "ArtistDigestor" do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@artist_digestor = Sevendigital::ArtistDigestor.new(Sevendigital::Client.new(nil))
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should not digest from invalid xml but throw up (exception)" do
|
11
|
+
|
12
|
+
xml_response = <<XML
|
13
|
+
<release id="123">
|
14
|
+
<name>expected artist name</name>
|
15
|
+
</release>
|
16
|
+
XML
|
17
|
+
|
18
|
+
running {@artist_digestor.from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should digest artist xml and populate minimum available properties" do
|
23
|
+
|
24
|
+
xml_response = <<XML
|
25
|
+
<artist id="123">
|
26
|
+
<name>expected artist name</name>
|
27
|
+
</artist>
|
28
|
+
XML
|
29
|
+
|
30
|
+
artist = @artist_digestor.from_xml(xml_response)
|
31
|
+
artist.id.should == 123
|
32
|
+
artist.name.should == "expected artist name"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should digest artist xml and populate all available properties" do
|
36
|
+
|
37
|
+
xml_response = load_sample_object_xml("artist")
|
38
|
+
|
39
|
+
artist = @artist_digestor.from_xml(xml_response)
|
40
|
+
artist.id.should == 123
|
41
|
+
artist.name.should == "The Expected Artist"
|
42
|
+
artist.sort_name.should == "Expected Artist, The"
|
43
|
+
artist.appears_as.should == "The E.A."
|
44
|
+
artist.image.should == "http://somewhere.com/tea.jpg"
|
45
|
+
artist.url.should == "http://7digital.com/artists/tea?partner=1"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should digest xml containing list of artists and return a paginated array" do
|
49
|
+
|
50
|
+
xml_response = load_sample_object_xml("artist_list")
|
51
|
+
|
52
|
+
artists = @artist_digestor.list_from_xml(xml_response, :artists)
|
53
|
+
artists[0].id.should == 14
|
54
|
+
artists[1].id.should == 20
|
55
|
+
artists[2].id.should == 106
|
56
|
+
artists.size.should == 3
|
57
|
+
artists.total_entries.should == 26
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should digest xml containing empty list of releases and return an empty paginated array" do
|
62
|
+
|
63
|
+
xml_response = load_sample_object_xml("artist_list_empty")
|
64
|
+
|
65
|
+
artists = @artist_digestor.list_from_xml(xml_response, :artists)
|
66
|
+
artists.size.should == 0
|
67
|
+
artists.total_entries.should == 0
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should not digest list from invalid xml but throw up (exception)" do
|
72
|
+
|
73
|
+
xml_response = <<XML
|
74
|
+
<release id="123">
|
75
|
+
<name>expected artist name</name>
|
76
|
+
</release>
|
77
|
+
XML
|
78
|
+
|
79
|
+
running {@artist_digestor.list_from_xml(xml_response)}.should raise_error Sevendigital::DigestiveProblem
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|