discogs-wrapper 1.1.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/LICENSE +9 -0
  2. data/README.markdown +123 -43
  3. data/lib/discogs-wrapper.rb +1 -0
  4. data/lib/discogs.rb +1 -0
  5. data/lib/wrapper/authentication.rb +56 -0
  6. data/lib/wrapper/wrapper.rb +732 -43
  7. data/spec/samples/valid_artist.json +1 -0
  8. data/spec/samples/valid_artist_releases.json +1 -0
  9. data/spec/samples/valid_fields.json +48 -0
  10. data/spec/samples/valid_folder.json +6 -0
  11. data/spec/samples/valid_identity.json +6 -0
  12. data/spec/samples/valid_label.json +1 -0
  13. data/spec/samples/valid_label_releases.json +1 -0
  14. data/spec/samples/valid_listing.json +1 -0
  15. data/spec/samples/valid_master_release.json +1 -0
  16. data/spec/samples/valid_master_release_versions.json +1 -0
  17. data/spec/samples/valid_order.json +57 -0
  18. data/spec/samples/valid_order_messages.json +102 -0
  19. data/spec/samples/valid_orders.json +68 -0
  20. data/spec/samples/valid_price_suggestions.json +34 -0
  21. data/spec/samples/valid_release.json +1 -0
  22. data/spec/samples/valid_search_results.json +1 -0
  23. data/spec/samples/valid_user.json +1 -0
  24. data/spec/samples/valid_user_collection.json +1 -0
  25. data/spec/samples/valid_user_folder.json +6 -0
  26. data/spec/samples/valid_user_folders.json +16 -0
  27. data/spec/samples/valid_user_inventory.json +41 -0
  28. data/spec/samples/valid_user_profile.json +25 -0
  29. data/spec/samples/valid_user_wantlist.json +1 -0
  30. data/spec/samples/valid_wantlist_release.json +41 -0
  31. data/spec/spec_helper.rb +4 -18
  32. data/spec/wrapper_methods/add_release_to_user_wantlist_spec.rb +42 -0
  33. data/spec/wrapper_methods/edit_release_in_user_wantlist_spec.rb +38 -0
  34. data/spec/wrapper_methods/edit_user_spec.rb +36 -0
  35. data/spec/wrapper_methods/get_artist_releases_spec.rb +49 -0
  36. data/spec/wrapper_methods/get_artist_spec.rb +15 -75
  37. data/spec/wrapper_methods/get_identity_spec.rb +35 -0
  38. data/spec/wrapper_methods/get_label_releases_spec.rb +49 -0
  39. data/spec/wrapper_methods/get_label_spec.rb +15 -28
  40. data/spec/wrapper_methods/get_listing_spec.rb +40 -0
  41. data/spec/wrapper_methods/get_master_release_spec.rb +16 -42
  42. data/spec/wrapper_methods/get_master_release_versions_spec.rb +49 -0
  43. data/spec/wrapper_methods/get_order_messages_spec.rb +36 -0
  44. data/spec/wrapper_methods/get_order_spec.rb +36 -0
  45. data/spec/wrapper_methods/get_price_suggestions_spec.rb +36 -0
  46. data/spec/wrapper_methods/get_release_spec.rb +26 -52
  47. data/spec/wrapper_methods/get_user_collection_spec.rb +41 -0
  48. data/spec/wrapper_methods/get_user_folder_spec.rb +46 -0
  49. data/spec/wrapper_methods/get_user_folders_spec.rb +42 -0
  50. data/spec/wrapper_methods/get_user_inventory_spec.rb +45 -0
  51. data/spec/wrapper_methods/get_user_spec.rb +45 -0
  52. data/spec/wrapper_methods/get_user_wantlist_spec.rb +49 -0
  53. data/spec/wrapper_methods/search_spec.rb +22 -293
  54. data/spec/wrapper_spec.rb +124 -45
  55. metadata +162 -67
  56. data/Rakefile +0 -26
  57. data/discogs.gemspec +0 -22
  58. data/lib/wrapper/resource.rb +0 -80
  59. data/lib/wrapper/resource_mappings.rb +0 -80
  60. data/lib/wrapper/resources/artist.rb +0 -40
  61. data/lib/wrapper/resources/artist_release.rb +0 -28
  62. data/lib/wrapper/resources/format.rb +0 -11
  63. data/lib/wrapper/resources/generic_list.rb +0 -29
  64. data/lib/wrapper/resources/image.rb +0 -11
  65. data/lib/wrapper/resources/label.rb +0 -16
  66. data/lib/wrapper/resources/label_release.rb +0 -17
  67. data/lib/wrapper/resources/master_release.rb +0 -19
  68. data/lib/wrapper/resources/master_release_version.rb +0 -17
  69. data/lib/wrapper/resources/release.rb +0 -25
  70. data/lib/wrapper/resources/release_artist.rb +0 -21
  71. data/lib/wrapper/resources/release_label.rb +0 -10
  72. data/lib/wrapper/resources/search.rb +0 -61
  73. data/lib/wrapper/resources/search_result.rb +0 -17
  74. data/lib/wrapper/resources/track.rb +0 -19
  75. data/lib/wrapper/resources/user.rb +0 -11
  76. data/lib/wrapper/resources/video.rb +0 -11
  77. data/spec/resource_spec.rb +0 -27
  78. data/spec/resources/artist_release_spec.rb +0 -59
  79. data/spec/resources/artist_spec.rb +0 -15
  80. data/spec/resources/format_spec.rb +0 -41
  81. data/spec/resources/generic_list_spec.rb +0 -66
  82. data/spec/resources/image_spec.rb +0 -43
  83. data/spec/resources/label_release_spec.rb +0 -55
  84. data/spec/resources/label_spec.rb +0 -15
  85. data/spec/resources/master_release_spec.rb +0 -15
  86. data/spec/resources/master_release_version_spec.rb +0 -55
  87. data/spec/resources/release_artist_spec.rb +0 -43
  88. data/spec/resources/release_label_spec.rb +0 -31
  89. data/spec/resources/release_spec.rb +0 -15
  90. data/spec/resources/search_result_spec.rb +0 -47
  91. data/spec/resources/search_spec.rb +0 -15
  92. data/spec/resources/track_spec.rb +0 -56
  93. data/spec/resources/video_spec.rb +0 -43
data/Rakefile DELETED
@@ -1,26 +0,0 @@
1
- require 'rake'
2
- require 'rspec'
3
- require 'rspec/core/rake_task'
4
- require 'rubygems/package_task'
5
-
6
-
7
-
8
- desc "Run all specs in spec directory"
9
- RSpec::Core::RakeTask.new(:spec) do |t|
10
- t.rspec_opts = ["--colour"]
11
- t.pattern = 'spec/**/*_spec.rb'
12
- end
13
-
14
- desc "Run all specs and generate simplecov report"
15
- task :cov do |t|
16
- ENV['COVERAGE'] = 'true'
17
- Rake::Task["spec"].execute
18
- `open coverage/index.html`
19
- end
20
-
21
- spec = eval(File.read("discogs.gemspec"))
22
-
23
- Gem::PackageTask.new(spec) do |pkg|
24
- # pkg.need_zip = true
25
- # pkg.need_tar = true
26
- end
data/discogs.gemspec DELETED
@@ -1,22 +0,0 @@
1
- Gem::Specification.new do |s|
2
-
3
- s.name = "discogs-wrapper"
4
- s.version = "1.1.4"
5
- s.date = "2013-08-13"
6
- s.summary = "Discogs::Wrapper is a full wrapper for the http://www.discogs.com API V2"
7
- s.homepage = "http://www.github.com/buntine/discogs"
8
- s.email = "info@andrewbuntine.com"
9
- s.authors = ["Andrew Buntine", "Many more contributors"]
10
-
11
- s.description = "Discogs::Wrapper is a full wrapper for the http://www.discogs.com API V2"
12
-
13
- s.files = ["lib/wrapper", "lib/wrapper/resource_mappings.rb", "lib/wrapper/wrapper.rb", "lib/wrapper/resource.rb", "lib/wrapper/resources", "lib/wrapper/resources/format.rb", "lib/wrapper/resources/search.rb", "lib/wrapper/resources/label_release.rb", "lib/wrapper/resources/artist.rb", "lib/wrapper/resources/release_artist.rb", "lib/wrapper/resources/artist_release.rb", "lib/wrapper/resources/release_label.rb", "lib/wrapper/resources/generic_list.rb", "lib/wrapper/resources/search_result.rb", "lib/wrapper/resources/label.rb", "lib/wrapper/resources/image.rb", "lib/wrapper/resources/track.rb", "lib/wrapper/resources/release.rb", "lib/wrapper/resources/master_release.rb", "lib/wrapper/resources/master_release_version.rb", "lib/wrapper/resources/video.rb", "./lib/wrapper/resources/user.rb", "lib/discogs.rb", "Rakefile", "README.markdown", "discogs.gemspec"]
14
-
15
- s.test_files = ["spec/wrapper_methods/get_release_spec.rb", "spec/wrapper_methods/get_master_release_spec.rb", "spec/wrapper_methods/search_spec.rb", "spec/wrapper_methods/get_artist_spec.rb", "spec/wrapper_methods/get_label_spec.rb", "spec/resource_spec.rb", "spec/resources/label_spec.rb", "spec/resources/generic_list_spec.rb", "spec/resources/artist_release_spec.rb", "spec/resources/artist_spec.rb", "spec/resources/release_artist_spec.rb", "spec/resources/search_spec.rb", "spec/resources/label_release_spec.rb", "spec/resources/release_label_spec.rb", "spec/resources/release_spec.rb", "spec/resources/master_release_spec.rb", "spec/resources/master_release_version_spec.rb", "spec/resources/video_spec.rb", "spec/resources/search_result_spec.rb", "spec/resources/image_spec.rb", "spec/resources/track_spec.rb", "spec/resources/format_spec.rb", "spec/wrapper_spec.rb", "spec/spec_helper.rb"]
16
-
17
- s.platform = Gem::Platform::RUBY
18
-
19
- s.add_development_dependency "rspec", "= 2.12.0"
20
- s.add_development_dependency "simplecov", "= 0.7.1"
21
-
22
- end
@@ -1,80 +0,0 @@
1
- # Represents a generic resource in the Discogs API.
2
-
3
- require File.dirname(__FILE__) + "/resource_mappings"
4
-
5
- class Discogs::Resource
6
-
7
- include Discogs::ResourceMappings
8
-
9
- def initialize(content)
10
- @content = content
11
- end
12
-
13
- def original_content
14
- @content
15
- end
16
-
17
- # Builds the resource with it's content.
18
- def build!(remove_resp=true)
19
- document = REXML::Document.new(@content, :ignore_whitespace_nodes => :all)
20
- root_node = document.root
21
-
22
- # Ignore the <resp> element if necessary.
23
- if remove_resp and document.root.expanded_name == "resp"
24
- root_node = root_node[0]
25
- end
26
-
27
- set_accessors_from_attributes(root_node)
28
-
29
- # Traverse node children.
30
- root_node.each_element do |element|
31
- name = element.expanded_name.to_sym
32
- setter = (name.to_s + "=").to_sym
33
-
34
- singular = find_resource_for_name(name, :singular)
35
- plural = singular ? nil : find_resource_for_name(name, :plural)
36
-
37
- # Create an instance of the named resource and build it.
38
- if !singular.nil?
39
- nested_object = singular.send(:new, element.to_s)
40
- self.send(setter, nested_object.build!)
41
-
42
- # Setup an array and build each child.
43
- elsif !plural.nil?
44
- set_accessors_from_attributes(element)
45
-
46
- self.send(setter, [])
47
- element.each_element do |sub_element|
48
- nested_object = plural.send(:new, sub_element.to_s)
49
- self.send(name) << nested_object.build!
50
- end
51
-
52
- elsif self.respond_to? setter
53
- self.send(setter, element.text)
54
- end
55
- end
56
-
57
- self
58
- end
59
-
60
- def build_with_resp!
61
- build!(false)
62
- end
63
-
64
- private
65
-
66
- # Sets accessors on _self_ from the attributes of the given element.
67
- def set_accessors_from_attributes(element)
68
- element.attributes.each_attribute do |attribute|
69
- setter = (attribute.expanded_name + "=").to_sym
70
-
71
- if self.respond_to? setter
72
- self.send(setter, attribute.value)
73
- end
74
- end
75
- end
76
-
77
- end
78
-
79
- # Load in all of the resource definitions.
80
- Dir[File.join(File.dirname(__FILE__), "resources", "*.rb")].each { |file| require file }
@@ -1,80 +0,0 @@
1
- # Abstracts the resource-mapping class methods.
2
- #
3
- # Each "resource" in the wrapper maps to one or more elements
4
- # in the API response. This way they can be recursively built
5
- # without having to manually specify it in each class.
6
-
7
- module Discogs::ResourceMappings
8
-
9
- def self.included(base)
10
- base.extend ClassMethods
11
- end
12
-
13
- module ClassMethods
14
-
15
- # Helper method to map resource to an element in the API response.
16
- def map_to(*elements)
17
- self.class_eval <<-EOF
18
- def self.element_names
19
- #{elements.inspect}
20
- end
21
- EOF
22
- end
23
-
24
- # Helper method to map pluralised resource to element in API response.
25
- def map_to_plural(*elements)
26
- self.class_eval <<-EOF
27
- def self.plural_element_names
28
- #{elements.inspect}
29
- end
30
- EOF
31
- end
32
-
33
- # Used by root classes (Discogs::Artist, etc) that should be built internally.
34
- def no_mapping
35
- self.class_eval <<-EOF
36
- def self.element_names; []; end
37
- def self.plural_element_names; []; end
38
- EOF
39
- end
40
-
41
- # Element defaults to prevent excess boilerplate code.
42
- def element_names
43
- [ self.to_s.split("::")[-1].downcase.to_sym ]
44
- end
45
- def plural_element_names
46
- [ (self.element_names[0].to_s + "s").to_sym ]
47
- end
48
-
49
- end
50
-
51
- private
52
-
53
- def find_resource_for_name(name, type=:singular)
54
- method = (type == :singular) ? :element_names : :plural_element_names
55
-
56
- find_resource do |klass|
57
- klass.constants.find do |const|
58
- if klass.const_get(const).respond_to? method
59
- klass.const_get(const).send(method).any? { |element| element.eql?(name) }
60
- end
61
- end
62
- end
63
- end
64
-
65
- # Look in _namespace_ for a matching resource class.
66
- # First looks in the children of _self_ namespace, and then looks more
67
- # generally. Returns nil if nothing is found.
68
- def find_resource(namespace=self.class, &matcher)
69
- match = matcher.call(namespace)
70
-
71
- if match
72
- match = namespace.const_get(match)
73
- elsif namespace == self.class
74
- match = find_resource(Discogs, &matcher)
75
- end
76
-
77
- return match
78
- end
79
-
80
- end
@@ -1,40 +0,0 @@
1
- # Represents an artist in the Discogs API.
2
-
3
- class Discogs::Artist < Discogs::Resource
4
-
5
- no_mapping
6
-
7
- attr_accessor :id,
8
- :name,
9
- :realname,
10
- :images,
11
- :urls,
12
- :namevariations,
13
- :aliases,
14
- :members,
15
- :releases,
16
- :profile,
17
- :data_quality
18
-
19
- def main_releases
20
- filter_releases("Main")
21
- end
22
-
23
- def bootlegs
24
- filter_releases("UnofficialRelease")
25
- end
26
-
27
- def appearances
28
- filter_releases("Appearance")
29
- end
30
-
31
- private
32
-
33
- # Simple helper for filtering a particular role of release.
34
- def filter_releases(role)
35
- self.releases.find_all do |release|
36
- release.role == role
37
- end
38
- end
39
-
40
- end
@@ -1,28 +0,0 @@
1
- # Represents an artist's release in the Discogs API.
2
-
3
- require File.dirname(__FILE__) + "/artist"
4
-
5
- class Discogs::Artist::Release < Discogs::Resource
6
-
7
- attr_accessor :id,
8
- :status,
9
- :role,
10
- :title,
11
- :artist,
12
- :format,
13
- :year,
14
- :label,
15
- :thumb,
16
- :trackinfo,
17
- :main_release
18
-
19
- # Will return either "master" or "release".
20
- def release_type
21
- if original_content =~ /^\<(\w+)\s/
22
- $1
23
- else
24
- "release"
25
- end
26
- end
27
-
28
- end
@@ -1,11 +0,0 @@
1
- # Represents a release format in the Discogs API.
2
-
3
- require File.dirname(__FILE__) + "/release"
4
-
5
- class Discogs::Release::Format < Discogs::Resource
6
-
7
- attr_accessor :name,
8
- :qty,
9
- :descriptions
10
-
11
- end
@@ -1,29 +0,0 @@
1
- # Represents a generic list of items in the Discogs API.
2
-
3
- class Discogs::GenericList < Discogs::Resource
4
-
5
- map_to :descriptions, :genres, :aliases, :namevariations, :styles, :urls, :members, :sublabels
6
-
7
- map_to_plural :lists
8
-
9
- # Overload build method to provide custom process for
10
- # converting contents into something useful.
11
- def build!
12
- @items = []
13
- document = REXML::Document.new(@content)
14
-
15
- document.root.each_element do |element|
16
- @items << element.text
17
- end
18
-
19
- @items
20
- end
21
-
22
- # Provides post-build access to the list.
23
- def [](index)
24
- if @items.is_a?(Array)
25
- @items[index]
26
- end
27
- end
28
-
29
- end
@@ -1,11 +0,0 @@
1
- # Represents an image in the Discogs API.
2
-
3
- class Discogs::Image < Discogs::Resource
4
-
5
- attr_accessor :uri,
6
- :uri150,
7
- :width,
8
- :height,
9
- :type
10
-
11
- end
@@ -1,16 +0,0 @@
1
- # Represents a label in the Discogs API.
2
-
3
- class Discogs::Label < Discogs::Resource
4
-
5
- no_mapping
6
-
7
- attr_accessor :name,
8
- :contactinfo,
9
- :profile,
10
- :parentlabel,
11
- :images,
12
- :urls,
13
- :sublabels,
14
- :releases
15
-
16
- end
@@ -1,17 +0,0 @@
1
- # Represents a labels release in the Discogs API.
2
-
3
- require File.dirname(__FILE__) + "/label"
4
-
5
- class Discogs::Label::Release < Discogs::Resource
6
-
7
- attr_accessor :id,
8
- :status,
9
- :type,
10
- :catno,
11
- :artist,
12
- :title,
13
- :format,
14
- :year,
15
- :trackinfo
16
-
17
- end
@@ -1,19 +0,0 @@
1
- # Represents a master release in the Discogs API.
2
-
3
- class Discogs::MasterRelease < Discogs::Resource
4
-
5
- no_mapping
6
-
7
- attr_accessor :id,
8
- :styles,
9
- :genres,
10
- :main_release,
11
- :notes,
12
- :year,
13
- :images,
14
- :videos,
15
- :tracklist,
16
- :artists,
17
- :versions
18
-
19
- end
@@ -1,17 +0,0 @@
1
- # Represents an master release version in the Discogs API.
2
-
3
- require File.dirname(__FILE__) + "/master_release"
4
-
5
- class Discogs::MasterRelease::Version < Discogs::Resource
6
-
7
- attr_accessor :id,
8
- :status,
9
- :title,
10
- :format,
11
- :label,
12
- :catno,
13
- :country,
14
- :released,
15
- :thumb
16
-
17
- end
@@ -1,25 +0,0 @@
1
- # Represents a release in the Discogs API.
2
-
3
- class Discogs::Release < Discogs::Resource
4
-
5
- no_mapping
6
-
7
- attr_accessor :id,
8
- :master_id,
9
- :status,
10
- :title,
11
- :country,
12
- :released,
13
- :notes,
14
- :images,
15
- :videos,
16
- :artists,
17
- :extraartists,
18
- :labels,
19
- :formats,
20
- :styles,
21
- :genres,
22
- :tracklist,
23
- :identifiers
24
-
25
- end