7digital 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. data/README.rdoc +9 -7
  2. data/lib/sevendigital.rb +54 -53
  3. data/lib/sevendigital/api_operator.rb +33 -30
  4. data/lib/sevendigital/api_operator_cached.rb +23 -23
  5. data/lib/sevendigital/api_request.rb +23 -23
  6. data/lib/sevendigital/client.rb +136 -124
  7. data/lib/sevendigital/default_configuration.yml +2 -2
  8. data/lib/sevendigital/digestion_tract/api_response_digestor.rb +52 -52
  9. data/lib/sevendigital/digestion_tract/artist_digestor.rb +31 -31
  10. data/lib/sevendigital/digestion_tract/chart_item_digestor.rb +27 -27
  11. data/lib/sevendigital/digestion_tract/digestor.rb +66 -66
  12. data/lib/sevendigital/digestion_tract/format_digestor.rb +21 -21
  13. data/lib/sevendigital/digestion_tract/label_digestor.rb +19 -19
  14. data/lib/sevendigital/digestion_tract/pager_digestor.rb +23 -23
  15. data/lib/sevendigital/digestion_tract/price_digestor.rb +24 -24
  16. data/lib/sevendigital/digestion_tract/release_digestor.rb +52 -52
  17. data/lib/sevendigital/digestion_tract/track_digestor.rb +37 -37
  18. data/lib/sevendigital/management/artist_manager.rb +45 -39
  19. data/lib/sevendigital/management/manager.rb +11 -11
  20. data/lib/sevendigital/management/release_manager.rb +57 -50
  21. data/lib/sevendigital/management/track_manager.rb +28 -17
  22. data/lib/sevendigital/model/api_response.rb +24 -12
  23. data/lib/sevendigital/model/artist.rb +46 -36
  24. data/lib/sevendigital/model/chart_item.rb +9 -9
  25. data/lib/sevendigital/model/format.rb +9 -9
  26. data/lib/sevendigital/model/label.rb +9 -9
  27. data/lib/sevendigital/model/price.rb +11 -11
  28. data/lib/sevendigital/model/release.rb +33 -33
  29. data/lib/sevendigital/model/sevendigital_error.rb +3 -3
  30. data/lib/sevendigital/model/sevendigital_object.rb +51 -51
  31. data/lib/sevendigital/model/track.rb +28 -7
  32. data/lib/sevendigital/pager.rb +16 -16
  33. data/lib/sevendigital/peachy_patch.rb +19 -0
  34. data/lib/sevendigital/proxy_police.rb +23 -23
  35. data/spec/api_operator_cached_spec.rb +47 -46
  36. data/spec/api_operator_spec.rb +114 -107
  37. data/spec/api_request_spec.rb +26 -27
  38. data/spec/client_spec.rb +75 -45
  39. data/spec/data/config/sevendigital.yml +5 -5
  40. data/spec/data/configuration_env_override.yml +5 -5
  41. data/spec/digestion_tract/api_response_digestor_spec.rb +78 -74
  42. data/spec/digestion_tract/artist_digestor_spec.rb +81 -82
  43. data/spec/digestion_tract/chart_digestor_spec.rb +52 -53
  44. data/spec/digestion_tract/format_digestor_spec.rb +38 -39
  45. data/spec/digestion_tract/label_digestor_spec.rb +33 -34
  46. data/spec/digestion_tract/pager_digestor_spec.rb +50 -51
  47. data/spec/digestion_tract/price_digestor_spec.rb +57 -57
  48. data/spec/digestion_tract/release_digestor_spec.rb +101 -102
  49. data/spec/digestion_tract/track_digestor_spec.rb +104 -106
  50. data/spec/management/artist_manager_spec.rb +128 -107
  51. data/spec/management/release_manager_spec.rb +222 -178
  52. data/spec/management/track_manager_spec.rb +88 -52
  53. data/spec/model/api_response_spec.rb +44 -31
  54. data/spec/model/artist_spec.rb +166 -121
  55. data/spec/model/release_spec.rb +109 -110
  56. data/spec/model/track_spec.rb +140 -0
  57. data/spec/pager_spec.rb +7 -8
  58. data/spec/peachy_spec_helper_patch.rb +7 -0
  59. data/spec/proxy_police_spec.rb +47 -48
  60. data/spec/spec_helper.rb +52 -48
  61. data/spec/test-xml/methods/artist/byTag/top.xml +50 -50
  62. data/spec/test-xml/methods/artist/details.xml +9 -9
  63. data/spec/test-xml/methods/artist/releases.xml +544 -544
  64. data/spec/test-xml/methods/artist/search.xml +19 -0
  65. data/spec/test-xml/methods/artist/similar.xml +39 -39
  66. data/spec/test-xml/methods/artist/toptracks.xml +279 -279
  67. data/spec/test-xml/methods/release/bydate.xml +173 -173
  68. data/spec/test-xml/methods/release/bytag/top.xml +150 -150
  69. data/spec/test-xml/methods/release/chart.xml +181 -181
  70. data/spec/test-xml/methods/release/details.xml +48 -48
  71. data/spec/test-xml/methods/release/recommend.xml +89 -89
  72. data/spec/test-xml/methods/release/search.xml +195 -0
  73. data/spec/test-xml/methods/release/tracks.xml +28 -28
  74. data/spec/test-xml/methods/track/chart.xml +149 -149
  75. data/spec/test-xml/methods/track/details.xml +30 -30
  76. data/spec/test-xml/methods/track/search.xml +160 -0
  77. data/spec/test-xml/objects/artist.xml +6 -6
  78. data/spec/test-xml/objects/artist_chart_item.xml +7 -7
  79. data/spec/test-xml/objects/artist_list.xml +22 -22
  80. data/spec/test-xml/objects/artist_list_empty.xml +4 -4
  81. data/spec/test-xml/objects/price.xml +7 -7
  82. data/spec/test-xml/objects/release.xml +40 -40
  83. data/spec/test-xml/objects/release_chart_item.xml +39 -34
  84. data/spec/test-xml/objects/release_list.xml +18 -18
  85. data/spec/test-xml/objects/release_list_empty.xml +4 -4
  86. data/spec/test-xml/objects/response.xml +39 -0
  87. data/spec/test-xml/objects/track.xml +33 -33
  88. data/spec/test-xml/objects/track_chart_item.xml +27 -27
  89. metadata +10 -5
  90. data/lib/peachy_patchy.rb +0 -14
  91. data/lib/sevendigital/version.rb +0 -3
@@ -1,7 +1,9 @@
1
- Ruby wrapper for 7digital API
2
-
3
- Example usage:
4
- sevendigital_client = Sevendigital::Client.new(:oauth_consumer_key => "YOUR_KEY_HERE", :country => "GB")
5
- artist = sevendigital_client.artist.get_details(1)
6
- puts artist.name
7
-
1
+ Ruby wrapper for 7digital API
2
+
3
+ Example usage:
4
+ require "sevendigital"
5
+
6
+ sevendigital_client = Sevendigital::Client.new(:oauth_consumer_key => "YOUR_KEY_HERE", :country => "GB")
7
+ artist = sevendigital_client.artist.get_details(1)
8
+ puts artist.name
9
+
@@ -1,53 +1,54 @@
1
-
2
- module Sevendigital
3
-
4
- # :stopdoc:
5
- VERSION = '0.0.1'
6
- LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
- PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
- # :startdoc:
9
-
10
- # Returns the version string for the library.
11
- #
12
- def self.version
13
- VERSION
14
- end
15
-
16
- # Returns the library path for the module. If any arguments are given,
17
- # they will be joined to the end of the libray path using
18
- # <tt>File.join</tt>.
19
- #
20
- def self.libpath( *args )
21
- args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
22
- end
23
-
24
- # Returns the lpath for the module. If any arguments are given,
25
- # they will be joined to the end of the path using
26
- # <tt>File.join</tt>.
27
- #
28
- def self.path( *args )
29
- args.empty? ? PATH : ::File.join(PATH, args.flatten)
30
- end
31
-
32
- # Utility method used to require all files ending in .rb that lie in the
33
- # directory below this file that has the same name as the filename passed
34
- # in. Optionally, a specific _directory_ name can be passed in such that
35
- # the _filename_ does not have to be equivalent to the directory.
36
- #
37
- def self.require_all_libs_relative_to( fname, dir = nil )
38
- dir ||= ::File.basename(fname, '.*')
39
- search_me = ::File.expand_path(
40
- ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
41
-
42
- Dir.glob(search_me).sort.each {|rb| require rb }
43
- end
44
-
45
- end # module 7digital
46
-
47
- require 'peachy'
48
- require File.join( File.dirname( File.expand_path(__FILE__)), 'peachy_patchy')
49
- require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'management', 'manager')
50
- require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'digestion_tract', 'digestor')
51
- require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'model', 'sevendigital_object')
52
- Sevendigital.require_all_libs_relative_to(__FILE__)
53
-
1
+
2
+ module Sevendigital
3
+
4
+ # :stopdoc:
5
+ VERSION = '0.0.1'
6
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
+ # :startdoc:
9
+
10
+ # Returns the version string for the library.
11
+ #
12
+ def self.version
13
+ VERSION
14
+ end
15
+
16
+ # Returns the library path for the module. If any arguments are given,
17
+ # they will be joined to the end of the libray path using
18
+ # <tt>File.join</tt>.
19
+ #
20
+ def self.libpath( *args )
21
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
22
+ end
23
+
24
+ # Returns the lpath for the module. If any arguments are given,
25
+ # they will be joined to the end of the path using
26
+ # <tt>File.join</tt>.
27
+ #
28
+ def self.path( *args )
29
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
30
+ end
31
+
32
+ # Utility method used to require all files ending in .rb that lie in the
33
+ # directory below this file that has the same name as the filename passed
34
+ # in. Optionally, a specific _directory_ name can be passed in such that
35
+ # the _filename_ does not have to be equivalent to the directory.
36
+ #
37
+ def self.require_all_libs_relative_to( fname, dir = nil )
38
+ dir ||= ::File.basename(fname, '.*')
39
+ search_me = ::File.expand_path(
40
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
41
+
42
+ Dir.glob(search_me).sort.each {|rb| require rb }
43
+ end
44
+
45
+ end # module 7digital
46
+
47
+ require 'peachy'
48
+ require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'peachy_patch')
49
+ Peachy.be_quiet
50
+ require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'management', 'manager')
51
+ require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'digestion_tract', 'digestor')
52
+ require File.join( File.dirname( File.expand_path(__FILE__)), 'sevendigital', 'model', 'sevendigital_object')
53
+ Sevendigital.require_all_libs_relative_to(__FILE__)
54
+
@@ -1,31 +1,34 @@
1
- module Sevendigital
2
-
3
- require 'net/http'
4
-
5
- class ApiOperator
6
-
7
- def initialize(client)
8
- @client = client
9
- end
10
-
11
- def call_api(api_request)
12
- make_http_request_and_digest(create_request_uri(api_request))
13
- end
14
-
15
- def make_http_request_and_digest(uri)
16
- http_response = Net::HTTP.get_response(uri)
17
- api_response = @client.api_response_digestor.from_http_response(http_response)
18
- raise Sevendigital::SevendigitalError, "#{api_response.error_code} - #{api_response.error_message}" if !api_response.ok?
19
- api_response
20
- end
21
-
22
- def create_request_uri(api_request)
23
- api_request.ensure_country_is_set(@client.country)
24
- params = api_request.parameters.collect{ |a,v| "&#{a}=#{v}" }.join
25
- URI.parse("http://#{@client.configuration.api_url}/#{@client.configuration.api_version}/#{api_request.api_method}"+
26
- "?oauth_consumer_key=#{@client.configuration.oauth_consumer_key}#{params}")
27
- end
28
-
29
- end
30
-
1
+ module Sevendigital
2
+
3
+ require 'net/http'
4
+
5
+ class ApiOperator
6
+
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def call_api(api_request)
12
+ api_response = make_http_request_and_digest(create_request_uri(api_request))
13
+ puts api_response if @client.very_verbose?
14
+ api_response
15
+ end
16
+
17
+ def make_http_request_and_digest(uri)
18
+ puts "ApiOperator: Calling #{uri}" if @client.verbose?
19
+ http_response = Net::HTTP.get_response(uri)
20
+ api_response = @client.api_response_digestor.from_http_response(http_response)
21
+ raise Sevendigital::SevendigitalError, "#{api_response.error_code} - #{api_response.error_message}" if !api_response.ok?
22
+ api_response
23
+ end
24
+
25
+ def create_request_uri(api_request)
26
+ api_request.ensure_country_is_set(@client.country)
27
+ params = api_request.parameters.collect{ |a,v| "&#{a}=#{v}" }.join
28
+ URI.parse("http://#{@client.configuration.api_url}/#{@client.configuration.api_version}/#{api_request.api_method}"+
29
+ "?oauth_consumer_key=#{@client.configuration.oauth_consumer_key}#{params}")
30
+ end
31
+
32
+ end
33
+
31
34
  end
@@ -1,23 +1,23 @@
1
- module Sevendigital
2
-
3
- class ApiOperatorCached < ApiOperator
4
-
5
- def initialize(client, cache)
6
- @cache = cache
7
- super(client)
8
- end
9
-
10
- def call_api(api_request)
11
- uri = create_request_uri(api_request)
12
- api_response = @cache.get(uri.to_s)
13
- #puts "got from cache #{uri}" if api_response
14
- if (!api_response) then
15
- #puts "calling #{uri}"
16
- api_response = make_http_request_and_digest(uri)
17
- @cache.set(uri.to_s, api_response)
18
- end
19
- api_response
20
- end
21
- end
22
-
23
- end
1
+ module Sevendigital
2
+
3
+ class ApiOperatorCached < ApiOperator
4
+
5
+ def initialize(client, cache)
6
+ @cache = cache
7
+ super(client)
8
+ end
9
+
10
+ def call_api(api_request)
11
+ uri = create_request_uri(api_request)
12
+ api_response = @cache.get(uri.to_s)
13
+ puts "ApiOperatorCached: Got from cache #{uri}" if api_response if @client.verbose?
14
+ if (!api_response) then
15
+ api_response = make_http_request_and_digest(uri)
16
+ @cache.set(uri.to_s, api_response)
17
+ end
18
+ puts api_response if @client.very_verbose?
19
+ api_response
20
+ end
21
+ end
22
+
23
+ end
@@ -1,24 +1,24 @@
1
- module Sevendigital
2
-
3
- class ApiRequest
4
-
5
- attr_reader :api_method, :parameters
6
-
7
- def initialize(api_method, parameters, options = {})
8
- @api_method = api_method
9
- @parameters = comb_parameters(options.merge(parameters))
10
- end
11
-
12
- def comb_parameters(parameters)
13
- page_size = parameters[:page_size] || parameters[:per_page]
14
- parameters[:pageSize] ||= page_size if page_size
15
- return parameters
16
- end
17
-
18
- def ensure_country_is_set(country)
19
- @parameters[:country] ||= country
20
- end
21
-
22
- end
23
-
1
+ module Sevendigital
2
+
3
+ class ApiRequest
4
+
5
+ attr_reader :api_method, :parameters
6
+
7
+ def initialize(api_method, parameters, options = {})
8
+ @api_method = api_method
9
+ @parameters = comb_parameters(options.merge(parameters))
10
+ end
11
+
12
+ def comb_parameters(parameters)
13
+ page_size = parameters[:page_size] || parameters[:per_page]
14
+ parameters[:pageSize] ||= page_size if page_size
15
+ return parameters
16
+ end
17
+
18
+ def ensure_country_is_set(country)
19
+ @parameters[:country] ||= country
20
+ end
21
+
22
+ end
23
+
24
24
  end
@@ -1,124 +1,136 @@
1
- require 'ostruct'
2
- require 'yaml'
3
-
4
-
5
- module Sevendigital
6
-
7
- DEFAULT_CONFIGURATION = {
8
- :api_url => "api.7digital.com",
9
- :api_version => "1.2"
10
- }
11
-
12
- class Client
13
-
14
- def load_configuration_from_yml(file_name, environment=nil)
15
- plain_settings = YAML.load_file(file_name)
16
- if (plain_settings["common"] || (environment && plain_settings[environment])) then
17
- environment_settings = plain_settings["common"] || {}
18
- environment_settings.update(plain_settings[environment]) if environment
19
- environment_settings
20
- else
21
- plain_settings
22
- end
23
- end
24
-
25
- def load_configurations(configuration)
26
-
27
- default_settings = Sevendigital::DEFAULT_CONFIGURATION
28
-
29
- if (configuration.kind_of? String) then
30
- yml_configuration_file = configuration
31
- else
32
- yml_configuration_file ="#{RAILS_ROOT}/config/sevendigital.yml" if defined?(RAILS_ROOT)
33
- explicit_settings = configuration if configuration.kind_of? Hash
34
- explicit_settings = configuration.marshal_dump if configuration.kind_of? OpenStruct
35
- end
36
-
37
- environment = defined?(RAILS_ENV) ? RAILS_ENV : nil
38
- yml_settings = load_configuration_from_yml(yml_configuration_file, environment) if yml_configuration_file
39
-
40
- settings = default_settings
41
- settings.update(yml_settings) if yml_settings
42
- settings.update(explicit_settings) if explicit_settings
43
-
44
- return OpenStruct.new(settings)
45
- end
46
-
47
- #Code here
48
-
49
- def initialize(configuration=nil, api_operator=nil)
50
- @configuration = load_configurations(configuration)
51
- @api_operator = api_operator || hire_api_operator
52
- end
53
-
54
- def hire_api_operator
55
- @configuration.cache ? ApiOperatorCached.new(self, @configuration.cache) : ApiOperator.new(self)
56
- end
57
-
58
- def artist
59
- @artist_manager ||= ArtistManager.new(self)
60
- end
61
-
62
- def artist_digestor
63
- @artist_digestor ||= ArtistDigestor.new(self)
64
- end
65
-
66
- def release
67
- @release_manager ||= ReleaseManager.new(self)
68
- end
69
-
70
- def release_digestor
71
- @release_digestor ||= ReleaseDigestor.new(self)
72
- end
73
-
74
- def label_digestor
75
- @label_digestor ||= LabelDigestor.new(self)
76
- end
77
-
78
- def format_digestor
79
- @format_digestor ||= FormatDigestor.new(self)
80
- end
81
-
82
- def price_digestor
83
- @price_digestor ||= PriceDigestor.new(self)
84
- end
85
-
86
- def pager_digestor
87
- @pager_digestor ||= PagerDigestor.new(self)
88
- end
89
-
90
- def track
91
- @track_manager ||= TrackManager.new(self)
92
- end
93
-
94
- def track_digestor
95
- @track_digestor ||= TrackDigestor.new(self)
96
- end
97
-
98
- def api_response_digestor
99
- @api_response_digestor ||= ApiResponseDigestor.new(self)
100
- end
101
-
102
- def chart_item_digestor
103
- @chart_item_digestor ||= ChartItemDigestor.new(self)
104
- end
105
-
106
- def configuration
107
- return @configuration
108
- end
109
-
110
- def operator
111
- @api_operator
112
- end
113
-
114
- def country
115
- @country || @configuration.country
116
- end
117
-
118
- def country=(country_code)
119
- @country = country_code
120
- end
121
-
122
- end
123
-
124
- end
1
+ require 'ostruct'
2
+ require 'yaml'
3
+
4
+
5
+ module Sevendigital
6
+
7
+ DEFAULT_CONFIGURATION = {
8
+ :api_url => "api.7digital.com",
9
+ :api_version => "1.2"
10
+ }
11
+
12
+ class Client
13
+
14
+ def load_configuration_from_yml(file_name, environment=nil)
15
+ plain_settings = YAML.load_file(file_name)
16
+ if (plain_settings["common"] || (environment && plain_settings[environment])) then
17
+ environment_settings = plain_settings["common"] || {}
18
+ environment_settings.update(plain_settings[environment]) if environment
19
+ environment_settings
20
+ else
21
+ plain_settings
22
+ end
23
+ end
24
+
25
+ def load_configurations(configuration)
26
+
27
+ default_settings = Sevendigital::DEFAULT_CONFIGURATION
28
+
29
+ if (configuration.kind_of? String) then
30
+ yml_configuration_file = configuration
31
+ else
32
+ yml_configuration_file ="#{RAILS_ROOT}/config/sevendigital.yml" if defined?(RAILS_ROOT)
33
+ explicit_settings = configuration if configuration.kind_of? Hash
34
+ explicit_settings = configuration.marshal_dump if configuration.kind_of? OpenStruct
35
+ end
36
+
37
+ environment = defined?(RAILS_ENV) ? RAILS_ENV : nil
38
+ yml_settings = load_configuration_from_yml(yml_configuration_file, environment) if yml_configuration_file
39
+
40
+ settings = default_settings
41
+ settings.update(yml_settings) if yml_settings
42
+ settings.update(explicit_settings) if explicit_settings
43
+
44
+ return OpenStruct.new(settings)
45
+ end
46
+
47
+ #Code here
48
+
49
+ def initialize(configuration=nil, api_operator=nil)
50
+ @configuration = load_configurations(configuration)
51
+ @api_operator = api_operator || hire_api_operator
52
+ end
53
+
54
+ def hire_api_operator
55
+ @configuration.cache ? ApiOperatorCached.new(self, @configuration.cache) : ApiOperator.new(self)
56
+ end
57
+
58
+ def artist
59
+ @artist_manager ||= ArtistManager.new(self)
60
+ end
61
+
62
+ def artist_digestor
63
+ @artist_digestor ||= ArtistDigestor.new(self)
64
+ end
65
+
66
+ def release
67
+ @release_manager ||= ReleaseManager.new(self)
68
+ end
69
+
70
+ def release_digestor
71
+ @release_digestor ||= ReleaseDigestor.new(self)
72
+ end
73
+
74
+ def label_digestor
75
+ @label_digestor ||= LabelDigestor.new(self)
76
+ end
77
+
78
+ def format_digestor
79
+ @format_digestor ||= FormatDigestor.new(self)
80
+ end
81
+
82
+ def price_digestor
83
+ @price_digestor ||= PriceDigestor.new(self)
84
+ end
85
+
86
+ def pager_digestor
87
+ @pager_digestor ||= PagerDigestor.new(self)
88
+ end
89
+
90
+ def track
91
+ @track_manager ||= TrackManager.new(self)
92
+ end
93
+
94
+ def track_digestor
95
+ @track_digestor ||= TrackDigestor.new(self)
96
+ end
97
+
98
+ def api_response_digestor
99
+ @api_response_digestor ||= ApiResponseDigestor.new(self)
100
+ end
101
+
102
+ def chart_item_digestor
103
+ @chart_item_digestor ||= ChartItemDigestor.new(self)
104
+ end
105
+
106
+ def configuration
107
+ return @configuration
108
+ end
109
+
110
+ def operator
111
+ @api_operator
112
+ end
113
+
114
+ def country
115
+ @country || @configuration.country
116
+ end
117
+
118
+ def country=(country_code)
119
+ @country = country_code
120
+ end
121
+
122
+ def verbose?
123
+ !(@verbose || @configuration.verbose).nil?
124
+ end
125
+
126
+ def very_verbose?
127
+ verbose? && (@verbose || @configuration.verbose).to_s == "very_verbose"
128
+ end
129
+
130
+ def verbose=(verbosity)
131
+ @verbose = verbosity
132
+ end
133
+
134
+ end
135
+
136
+ end