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
@@ -1,21 +0,0 @@
1
- # Represents an release's artist in the Discogs API.
2
-
3
- require File.dirname(__FILE__) + "/track"
4
- require File.dirname(__FILE__) + "/master_release"
5
-
6
- class Discogs::Release::Artist < Discogs::Resource
7
-
8
- map_to_plural :artists, :extraartists
9
-
10
- attr_accessor :name,
11
- :role,
12
- :join,
13
- :anv,
14
- :tracks
15
-
16
- end
17
-
18
- # Define other classes that also replicate this structure.
19
- class Discogs::Release::Track::Artist < Discogs::Release::Artist; end
20
- class Discogs::MasterRelease::Artist < Discogs::Release::Artist; end
21
- class Discogs::MasterRelease::Track::Artist < Discogs::Release::Artist; end
@@ -1,10 +0,0 @@
1
- # Represents a Releases Label in the Discogs API.
2
-
3
- require File.dirname(__FILE__) + "/release"
4
-
5
- class Discogs::Release::Label < Discogs::Resource
6
-
7
- attr_accessor :catno,
8
- :name
9
-
10
- end
@@ -1,61 +0,0 @@
1
- # Represents a search resultset in the Discogs API.
2
-
3
- class Discogs::Search < Discogs::Resource
4
-
5
- no_mapping
6
-
7
- attr_accessor :exactresults,
8
- :searchresults,
9
- :start,
10
- :end,
11
- :numResults
12
-
13
- def total_results
14
- self.numResults.to_i
15
- end
16
-
17
- def current_page
18
- (start.to_i / page_size) + 1
19
- end
20
-
21
- def total_pages
22
- (total_results.to_f / page_size).ceil
23
- end
24
-
25
- def last_page?
26
- current_page == total_pages
27
- end
28
-
29
- def exact(filter=nil)
30
- filter_results(filter, self.exactresults)
31
- end
32
-
33
- def results(filter=nil)
34
- filter_results(filter, self.searchresults)
35
- end
36
-
37
- # Returns the closest exact result for _filter_, or nil.
38
- def closest(filter)
39
- exact(filter)[0] rescue nil
40
- end
41
-
42
- private
43
-
44
- # An easy way for filtering a particular "type" of result (Artist, Release, etc)
45
- def filter_results(filter, results)
46
- results ||= []
47
-
48
- if filter.nil?
49
- results
50
- else
51
- results.find_all do |result|
52
- result.type == filter.to_s
53
- end
54
- end
55
- end
56
-
57
- def page_size
58
- self.end.to_i - (self.start.to_i - 1)
59
- end
60
-
61
- end
@@ -1,17 +0,0 @@
1
- # Represents a single search result in the Discogs API.
2
-
3
- require File.dirname(__FILE__) + "/search"
4
-
5
- class Discogs::Search::Result < Discogs::Resource
6
-
7
- map_to_plural :exactresults, :searchresults
8
-
9
- attr_accessor :num,
10
- :type,
11
- :title,
12
- :uri,
13
- :anv,
14
- :summary,
15
- :thumb
16
-
17
- end
@@ -1,19 +0,0 @@
1
- # Represents a track in the Discogs API.
2
-
3
- require File.dirname(__FILE__) + "/release"
4
- require File.dirname(__FILE__) + "/master_release"
5
-
6
- class Discogs::Release::Track < Discogs::Resource
7
-
8
- map_to_plural :tracklist
9
-
10
- attr_accessor :position,
11
- :title,
12
- :duration,
13
- :artists,
14
- :extraartists
15
-
16
- end
17
-
18
- # Define other classes that also replicate this structure.
19
- class Discogs::MasterRelease::Track < Discogs::Release::Track; end
@@ -1,11 +0,0 @@
1
- # Represents an user in the Discogs API.
2
-
3
- class Discogs::User < Discogs::Resource
4
-
5
- no_mapping
6
-
7
- attr_accessor :username,
8
- :uri,
9
- :name
10
-
11
- end
@@ -1,11 +0,0 @@
1
- # Represents an video in the Discogs API.
2
-
3
- class Discogs::Video < Discogs::Resource
4
-
5
- attr_accessor :duration,
6
- :embed,
7
- :description,
8
- :title,
9
- :src
10
-
11
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Discogs::Resource do
4
-
5
- before do
6
- @resource = Discogs::Resource.new(sample_valid_binary)
7
- end
8
-
9
- it "should have a default element name" do
10
- Discogs::Resource.element_names.should == [ :resource ]
11
- end
12
-
13
- it "should have a default plural element name" do
14
- Discogs::Resource.plural_element_names.should == [ :resources ]
15
- end
16
-
17
- it "should have an original_content method" do
18
- @resource.original_content.should == sample_valid_binary
19
- end
20
-
21
- it "should be able to build the content"
22
-
23
- it "should remove the <resp> element by default"
24
-
25
- it "should leave the <resp> element if told to"
26
-
27
- end
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Discogs::Artist::Release do
4
-
5
- it "should map to release" do
6
- Discogs::Artist::Release.element_names.should == [ :release ]
7
- end
8
-
9
- it "should map to plural releases" do
10
- Discogs::Artist::Release.plural_element_names.should == [ :releases ]
11
- end
12
-
13
- describe "when asking for artist-release information" do
14
-
15
- before do
16
- data = File.read(File.join(File.dirname(__FILE__), "..", "samples", "valid_artist_release.xml"))
17
- @artist_release = Discogs::Artist::Release.new(data)
18
- @artist_release.build!
19
- end
20
-
21
- it "should have a ID attribute" do
22
- @artist_release.id.should == "999333"
23
- end
24
-
25
- it "should have a status attribute" do
26
- @artist_release.status.should == "Accepted"
27
- end
28
-
29
- it "should have a role attribute" do
30
- @artist_release.role.should == "Main"
31
- end
32
-
33
- it "should have a title attribute" do
34
- @artist_release.title.should == "Temple of the Underworld"
35
- end
36
-
37
- it "should have a format attribute" do
38
- @artist_release.format.should == "LP"
39
- end
40
-
41
- it "should have a label attribute" do
42
- @artist_release.label.should == "Monitor Records"
43
- end
44
-
45
- it "should have a year attribute" do
46
- @artist_release.year.should == "1992"
47
- end
48
-
49
- it "should have a trackinfo attribute" do
50
- @artist_release.trackinfo.should be_nil
51
- end
52
-
53
- it "should have an artist attribute" do
54
- @artist_release.artist.should == "ArtIst"
55
- end
56
-
57
- end
58
-
59
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Discogs::Artist do
4
-
5
- it "should map to empty array" do
6
- Discogs::Artist.element_names.should == []
7
- end
8
-
9
- it "should map plural to empty array" do
10
- Discogs::Artist.plural_element_names.should == []
11
- end
12
-
13
- ## See ./spec/wrapper_methods/get_artist_spec.rb for extensive tests of this class.
14
-
15
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Discogs::Release::Format do
4
-
5
- it "should map to format" do
6
- Discogs::Release::Format.element_names.should == [ :format ]
7
- end
8
-
9
- it "should map to plural formats" do
10
- Discogs::Release::Format.plural_element_names.should == [ :formats ]
11
- end
12
-
13
- describe "when asking for format information" do
14
-
15
- before do
16
- data = File.read(File.join(File.dirname(__FILE__), "..", "samples", "valid_format.xml"))
17
- @format = Discogs::Release::Format.new(data)
18
- @format.build!
19
- end
20
-
21
- it "should have a name attribute" do
22
- @format.name.should == "CD"
23
- end
24
-
25
- it "should have a quantity attribute" do
26
- @format.qty.should == "1"
27
- end
28
-
29
- it "should have an array of descriptions" do
30
- @format.descriptions.should be_instance_of(Array)
31
- end
32
-
33
- it "should have built each description" do
34
- @format.descriptions[0].should == "Album"
35
- @format.descriptions[1].should == "Digipak"
36
- @format.descriptions[9].should be_nil
37
- end
38
-
39
- end
40
-
41
- end
@@ -1,66 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Discogs::GenericList do
4
-
5
- it "should map to all generic lists" do
6
- Discogs::GenericList.element_names.should be_instance_of(Array)
7
-
8
- Discogs::GenericList.element_names.include?(:aliases).should be_true
9
- Discogs::GenericList.element_names.include?(:urls).should be_true
10
- end
11
-
12
- it "should map to plural lists" do
13
- Discogs::GenericList.plural_element_names.should == [ :lists ]
14
- end
15
-
16
- describe "when asking for description information" do
17
-
18
- before do
19
- data = File.read(File.join(File.dirname(__FILE__), "..", "samples", "valid_description_list.xml"))
20
- @descriptions = Discogs::GenericList.new(data)
21
- end
22
-
23
- it "should return an array on build" do
24
- @descriptions.build!.should be_instance_of(Array)
25
- end
26
-
27
- it "should have access to the items after build" do
28
- @descriptions.build!
29
-
30
- @descriptions[0].should == "Album"
31
- @descriptions[1].should == "LP"
32
- @descriptions[2].should == "33 rpm"
33
- end
34
-
35
- it "should return nil on unknown index" do
36
- @descriptions[9].should be_nil
37
- end
38
-
39
- end
40
-
41
- describe "when asking for genre information" do
42
-
43
- before do
44
- data = File.read(File.join(File.dirname(__FILE__), "..", "samples", "valid_genre_list.xml"))
45
- @genres = Discogs::GenericList.new(data)
46
- end
47
-
48
- it "should return an array on build" do
49
- @genres.build!.should be_instance_of(Array)
50
- end
51
-
52
- it "should have access to the items after build" do
53
- @genres.build!
54
-
55
- @genres[0].should == "Heavy Metal"
56
- @genres[1].should == "Neofolk"
57
- @genres[2].should == "Medieval folk"
58
- end
59
-
60
- it "should return nil on unknown index" do
61
- @genres[9].should be_nil
62
- end
63
-
64
- end
65
-
66
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Discogs::Image do
4
-
5
- it "should map to image" do
6
- Discogs::Image.element_names.should == [ :image ]
7
- end
8
-
9
- it "should map to plural images" do
10
- Discogs::Image.plural_element_names.should == [ :images ]
11
- end
12
-
13
- describe "when asking for image information" do
14
-
15
- before do
16
- data = File.read(File.join(File.dirname(__FILE__), "..", "samples", "valid_image.xml"))
17
- @image = Discogs::Image.new(data)
18
- @image.build!
19
- end
20
-
21
- it "should have a type attribute" do
22
- @image.type.should == "primary"
23
- end
24
-
25
- it "should have a width attribute" do
26
- @image.width.should == "600"
27
- end
28
-
29
- it "should have a height attribute" do
30
- @image.height.should == "595"
31
- end
32
-
33
- it "should have a uri attribute" do
34
- @image.uri.should == "http://www.discogs.com/image/R-666-1222413500.jpeg"
35
- end
36
-
37
- it "should have a uri150 attribute" do
38
- @image.uri150.should == "http://www.discogs.com/image/R-150-666-1222413500.jpeg"
39
- end
40
-
41
- end
42
-
43
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Discogs::Label::Release do
4
-
5
- it "should map to release" do
6
- Discogs::Label::Release.element_names.should == [ :release ]
7
- end
8
-
9
- it "should map to plural releases" do
10
- Discogs::Label::Release.plural_element_names.should == [ :releases ]
11
- end
12
-
13
- describe "when asking for label-release information" do
14
-
15
- before do
16
- data = File.read(File.join(File.dirname(__FILE__), "..", "samples", "valid_label_release.xml"))
17
- @label_release = Discogs::Label::Release.new(data)
18
- @label_release.build!
19
- end
20
-
21
- it "should have a ID attribute" do
22
- @label_release.id.should == "116322"
23
- end
24
-
25
- it "should have a status attribute" do
26
- @label_release.status.should == "Accepted"
27
- end
28
-
29
- it "should have a catno attribute" do
30
- @label_release.catno.should == "SMB09"
31
- end
32
-
33
- it "should have an artist attribute" do
34
- @label_release.artist.should == "Morrior"
35
- end
36
-
37
- it "should have a title attribute" do
38
- @label_release.title.should == "Death Metal Session"
39
- end
40
-
41
- it "should have a format attribute" do
42
- @label_release.format.should == "12\""
43
- end
44
-
45
- it "should have a year attribute" do
46
- @label_release.year.should == "1991"
47
- end
48
-
49
- it "should have a trackinfo attribute" do
50
- @label_release.trackinfo.should == "Side A, track 4"
51
- end
52
-
53
- end
54
-
55
- end