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.
- data/LICENSE +9 -0
- data/README.markdown +123 -43
- data/lib/discogs-wrapper.rb +1 -0
- data/lib/discogs.rb +1 -0
- data/lib/wrapper/authentication.rb +56 -0
- data/lib/wrapper/wrapper.rb +732 -43
- data/spec/samples/valid_artist.json +1 -0
- data/spec/samples/valid_artist_releases.json +1 -0
- data/spec/samples/valid_fields.json +48 -0
- data/spec/samples/valid_folder.json +6 -0
- data/spec/samples/valid_identity.json +6 -0
- data/spec/samples/valid_label.json +1 -0
- data/spec/samples/valid_label_releases.json +1 -0
- data/spec/samples/valid_listing.json +1 -0
- data/spec/samples/valid_master_release.json +1 -0
- data/spec/samples/valid_master_release_versions.json +1 -0
- data/spec/samples/valid_order.json +57 -0
- data/spec/samples/valid_order_messages.json +102 -0
- data/spec/samples/valid_orders.json +68 -0
- data/spec/samples/valid_price_suggestions.json +34 -0
- data/spec/samples/valid_release.json +1 -0
- data/spec/samples/valid_search_results.json +1 -0
- data/spec/samples/valid_user.json +1 -0
- data/spec/samples/valid_user_collection.json +1 -0
- data/spec/samples/valid_user_folder.json +6 -0
- data/spec/samples/valid_user_folders.json +16 -0
- data/spec/samples/valid_user_inventory.json +41 -0
- data/spec/samples/valid_user_profile.json +25 -0
- data/spec/samples/valid_user_wantlist.json +1 -0
- data/spec/samples/valid_wantlist_release.json +41 -0
- data/spec/spec_helper.rb +4 -18
- data/spec/wrapper_methods/add_release_to_user_wantlist_spec.rb +42 -0
- data/spec/wrapper_methods/edit_release_in_user_wantlist_spec.rb +38 -0
- data/spec/wrapper_methods/edit_user_spec.rb +36 -0
- data/spec/wrapper_methods/get_artist_releases_spec.rb +49 -0
- data/spec/wrapper_methods/get_artist_spec.rb +15 -75
- data/spec/wrapper_methods/get_identity_spec.rb +35 -0
- data/spec/wrapper_methods/get_label_releases_spec.rb +49 -0
- data/spec/wrapper_methods/get_label_spec.rb +15 -28
- data/spec/wrapper_methods/get_listing_spec.rb +40 -0
- data/spec/wrapper_methods/get_master_release_spec.rb +16 -42
- data/spec/wrapper_methods/get_master_release_versions_spec.rb +49 -0
- data/spec/wrapper_methods/get_order_messages_spec.rb +36 -0
- data/spec/wrapper_methods/get_order_spec.rb +36 -0
- data/spec/wrapper_methods/get_price_suggestions_spec.rb +36 -0
- data/spec/wrapper_methods/get_release_spec.rb +26 -52
- data/spec/wrapper_methods/get_user_collection_spec.rb +41 -0
- data/spec/wrapper_methods/get_user_folder_spec.rb +46 -0
- data/spec/wrapper_methods/get_user_folders_spec.rb +42 -0
- data/spec/wrapper_methods/get_user_inventory_spec.rb +45 -0
- data/spec/wrapper_methods/get_user_spec.rb +45 -0
- data/spec/wrapper_methods/get_user_wantlist_spec.rb +49 -0
- data/spec/wrapper_methods/search_spec.rb +22 -293
- data/spec/wrapper_spec.rb +124 -45
- metadata +162 -67
- data/Rakefile +0 -26
- data/discogs.gemspec +0 -22
- data/lib/wrapper/resource.rb +0 -80
- data/lib/wrapper/resource_mappings.rb +0 -80
- data/lib/wrapper/resources/artist.rb +0 -40
- data/lib/wrapper/resources/artist_release.rb +0 -28
- data/lib/wrapper/resources/format.rb +0 -11
- data/lib/wrapper/resources/generic_list.rb +0 -29
- data/lib/wrapper/resources/image.rb +0 -11
- data/lib/wrapper/resources/label.rb +0 -16
- data/lib/wrapper/resources/label_release.rb +0 -17
- data/lib/wrapper/resources/master_release.rb +0 -19
- data/lib/wrapper/resources/master_release_version.rb +0 -17
- data/lib/wrapper/resources/release.rb +0 -25
- data/lib/wrapper/resources/release_artist.rb +0 -21
- data/lib/wrapper/resources/release_label.rb +0 -10
- data/lib/wrapper/resources/search.rb +0 -61
- data/lib/wrapper/resources/search_result.rb +0 -17
- data/lib/wrapper/resources/track.rb +0 -19
- data/lib/wrapper/resources/user.rb +0 -11
- data/lib/wrapper/resources/video.rb +0 -11
- data/spec/resource_spec.rb +0 -27
- data/spec/resources/artist_release_spec.rb +0 -59
- data/spec/resources/artist_spec.rb +0 -15
- data/spec/resources/format_spec.rb +0 -41
- data/spec/resources/generic_list_spec.rb +0 -66
- data/spec/resources/image_spec.rb +0 -43
- data/spec/resources/label_release_spec.rb +0 -55
- data/spec/resources/label_spec.rb +0 -15
- data/spec/resources/master_release_spec.rb +0 -15
- data/spec/resources/master_release_version_spec.rb +0 -55
- data/spec/resources/release_artist_spec.rb +0 -43
- data/spec/resources/release_label_spec.rb +0 -31
- data/spec/resources/release_spec.rb +0 -15
- data/spec/resources/search_result_spec.rb +0 -47
- data/spec/resources/search_spec.rb +0 -15
- data/spec/resources/track_spec.rb +0 -56
- 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
|
data/lib/wrapper/resource.rb
DELETED
@@ -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,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,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
|