discogs-wrapper 2.1.4 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe2e0b555db6b6594e278c843c7f3f6d8b0a4cd1
4
- data.tar.gz: e11044282bf2d59bfb2bae694abbdbdb5d5684c0
3
+ metadata.gz: ae13ebef40ffcfb33e23eae6023cc0f53e2415d0
4
+ data.tar.gz: 089c0a08632d61a606ffe83d64c5e1e92c2c4179
5
5
  SHA512:
6
- metadata.gz: d9c291ac7fcd4aef06b7585fd5bd6f52d92dacb67fd7ec80c80baefd13b1b894e98a393720afe6e0a87d50f37840e2a53ae65fb4256e5acb81bdde91977818f8
7
- data.tar.gz: 82685658025abeb2b4588b8023942252a51c96989540a96e06a1b387bbdf5788cdc0bbb76a5b3c99dd84acf3cdc6adc8cfb5c2a1dacd9a330e891beff0312ea1
6
+ metadata.gz: 2e193879c585f4418a3c3c0c3bd7e4bf587d52bd5dfffd73c64f12bfc7dd6229a3f10e77ca29f6ec3b6ddcf994fe77902c413a9337031a481db8b6e3d44a29f5
7
+ data.tar.gz: 2e6f5a9fb1cb72a75eee77c0f006a07869b5df0d5926835a050af43f56e9d6de23ff6f760c0e806412f8f68561a90223440a726be30f32ce2890fe07b196ca5d
@@ -4,8 +4,7 @@
4
4
  ##
5
5
  ## This library provides full access to the Discogs.com API v2.0
6
6
  ##
7
- ## Please file all bug reports at http://www.github.com/buntine/discogs, or
8
- ## email me at info@andrewbuntine.com.
7
+ ## Please file all bug reports at https://www.github.com/buntine/discogs.
9
8
  ##
10
9
  ## Enjoy!
11
10
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'hashie'
4
4
  require 'json'
5
- require 'net/http'
5
+ require 'httparty'
6
6
  require 'stringio'
7
7
  require 'uri'
8
8
  require 'cgi'
@@ -116,7 +116,7 @@ class Discogs::Wrapper
116
116
  # @macro uses_pagination
117
117
  # @return [Hash] the user with provided username
118
118
  def get_user_collection(username, pagination={})
119
- get_user_folder_releases(username, 0)
119
+ get_user_folder_releases(username, 0, pagination)
120
120
  end
121
121
 
122
122
  # Retrieve a list of user-defined collection notes fields. These fields are available on every release in the collection.
@@ -488,7 +488,7 @@ class Discogs::Wrapper
488
488
  # * +No Cover+
489
489
  # @option data [Float (Required)] :price The price of the item (in the seller's currency).
490
490
  # @option data [String (Optional)] :comments Any remarks about the item that will be displayed to buyers.
491
- # @option data [Boolean (Optional)] :allow_buffers (false) Whether or not to allow buyers to make offers on the item. Defaults to +false+.
491
+ # @option data [Boolean (Optional)] :allow_offers (false) Whether or not to allow buyers to make offers on the item. Defaults to +false+.
492
492
  # @option data [String (Optional)] :status (+For Sale+) The status of the listing. Defaults to For Sale. Must *EXACTLY* match one of:
493
493
  # * +For Sale+ - the listing is ready to be shown on the Marketplace
494
494
  # * +Draft+ - the listing is not ready for public display
@@ -701,6 +701,12 @@ class Discogs::Wrapper
701
701
  end
702
702
  end
703
703
 
704
+ # Perform a search.
705
+ #
706
+ # @macro need_auth
707
+ #
708
+ # @param [String (Required)] term to search.
709
+ # @return [Hash] search results
704
710
  def search(term, params={})
705
711
  authenticated? do
706
712
  parameters = {:q => term}.merge(params)
@@ -708,6 +714,10 @@ class Discogs::Wrapper
708
714
  end
709
715
  end
710
716
 
717
+ # Fetch response from API using a fully-qualified URL.
718
+ #
719
+ # @param [String (Required)] API endpoint
720
+ # @return [Hash] API response
711
721
  def raw(url)
712
722
  uri = URI.parse(url)
713
723
  params = CGI.parse(uri.query.to_s)
@@ -720,9 +730,13 @@ class Discogs::Wrapper
720
730
  def query_and_build(path, params={}, method=:get, body=nil)
721
731
  parameters = {:f => "json"}.merge(params)
722
732
  data = query_api(path, params, method, body)
723
- hash = JSON.parse(data)
724
733
 
725
- Hashie::Mash.new(hash)
734
+ if data != ""
735
+ hash = JSON.parse(data)
736
+ Hashie::Mash.new(hash)
737
+ else
738
+ Hashie::Mash.new
739
+ end
726
740
  end
727
741
 
728
742
  # Queries the API and handles the response.
@@ -732,25 +746,25 @@ class Discogs::Wrapper
732
746
  raise_unknown_resource(path) if response.code == "404"
733
747
  raise_authentication_error(path) if response.code == "401"
734
748
  raise_internal_server_error if response.code == "500"
735
-
749
+
736
750
  # Unzip the response data, or just read it in directly
737
751
  # if the API responds without gzipping.
738
752
  response_body = nil
739
753
  begin
740
- inflated_data = Zlib::GzipReader.new(StringIO.new(response.body))
754
+ inflated_data = Zlib::GzipReader.new(StringIO.new(response.body.to_s))
741
755
  response_body = inflated_data.read
742
756
  rescue Zlib::GzipFile::Error
743
757
  response_body = response.body
744
758
  end
745
759
 
746
- response_body
760
+ response_body.to_s
747
761
  end
748
762
 
749
763
  # Generates a HTTP request and returns the response.
750
764
  def make_request(path, params, method, body)
751
765
  full_params = params.merge(auth_params)
752
766
  uri = build_uri(path, full_params)
753
- formatted = "#{uri.path}?#{uri.query}"
767
+ formatted = "#{uri.path}?#{uri.query}"
754
768
  output_format = full_params.fetch(:f, "json")
755
769
  headers = {"Accept" => "application/#{output_format}",
756
770
  "Accept-Encoding" => "gzip,deflate",
@@ -764,17 +778,8 @@ class Discogs::Wrapper
764
778
  @access_token.send(method, formatted, headers)
765
779
  end
766
780
  else
767
- # All non-authenticated endpoints are GET.
768
- request = Net::HTTP::Get.new(formatted)
769
-
770
- headers.each do |h, v|
771
- request.add_field(h, v)
772
- end
773
-
774
- Net::HTTP.start(uri.host, uri.port,
775
- :use_ssl => uri.scheme == 'https') do |http|
776
- http.request(request)
777
- end
781
+ # All non-authenticated endpoints are GET.
782
+ HTTParty.get(uri, headers: headers)
778
783
  end
779
784
  end
780
785
 
@@ -28,3 +28,12 @@ def sample_invalid_data
28
28
  </resp>
29
29
  EOF
30
30
  end
31
+
32
+ def mock_httparty(sample)
33
+ @http_response = double(HTTParty::Response)
34
+ @http_request = class_double(HTTParty).as_stubbed_const
35
+
36
+ allow(@http_response).to receive_messages(:code => "200", :body => read_sample(sample))
37
+
38
+ @http_request.should_receive(:get).and_return(@http_response)
39
+ end
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe Discogs::Wrapper do
4
4
 
5
5
  before do
6
- @oauth_access_token = mock(OAuth::AccessToken)
7
- @wrapper = Discogs::Wrapper.new("some_user_agent", @oauth_access_token)
6
+ @oauth_access_token = double(OAuth::AccessToken)
7
+ @wrapper = Discogs::Wrapper.new("some_user_agent", :access_token => @oauth_access_token)
8
8
 
9
9
  @username = "abuntine"
10
10
  @release_id = "1"
@@ -13,10 +13,16 @@ describe Discogs::Wrapper do
13
13
  describe ".add_release_to_user_wantlist" do
14
14
 
15
15
  before do
16
- @oauth_response = mock(OAuth::AccessToken, :code => "200", :body => read_sample("wantlist_release"))
17
- @oauth_response_as_file = mock(StringIO, :read => read_sample("wantlist_release"))
18
- Zlib::GzipReader.should_receive(:new).and_return(@oauth_response_as_file)
19
- @oauth_access_token.should_receive(:put).and_return(@oauth_response)
16
+ @oauth_response = double(OAuth::AccessToken)
17
+
18
+ allow(@oauth_response).to receive_messages(:code => "200", :body => read_sample("wantlist_release"))
19
+
20
+ @oauth_response_as_file = double(StringIO)
21
+
22
+ allow(@oauth_response_as_file).to receive_messages(:read => read_sample("wantlist_release"))
23
+
24
+ expect(Zlib::GzipReader).to receive(:new).and_return(@oauth_response_as_file)
25
+ expect(@oauth_access_token).to receive(:put).and_return(@oauth_response)
20
26
 
21
27
  @wantlist_release = @wrapper.add_release_to_user_wantlist(@username, @release_id)
22
28
  end
@@ -24,15 +30,15 @@ describe Discogs::Wrapper do
24
30
  describe "when calling simple wantlist release attributes" do
25
31
 
26
32
  it "should have an id" do
27
- @wantlist_release.id.should == 1
33
+ expect(@wantlist_release.id).to eq(1)
28
34
  end
29
35
 
30
36
  it "should have a rating" do
31
- @wantlist_release.rating.should == 0
37
+ expect(@wantlist_release.rating).to eq(0)
32
38
  end
33
39
 
34
40
  it "should have some basic information" do
35
- @wantlist_release.basic_information.title.should == "Stockholm"
41
+ expect(@wantlist_release.basic_information.title).to eq("Stockholm")
36
42
  end
37
43
 
38
44
  end
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe Discogs::Wrapper do
4
4
 
5
5
  before do
6
- @oauth_access_token = mock(OAuth::AccessToken)
7
- @wrapper = Discogs::Wrapper.new("some_user_agent", @oauth_access_token)
6
+ @oauth_access_token = double(OAuth::AccessToken)
7
+ @wrapper = Discogs::Wrapper.new("some_user_agent", :access_token => @oauth_access_token)
8
8
 
9
9
  @username = "abuntine"
10
10
  @release_id = "1"
@@ -13,10 +13,16 @@ describe Discogs::Wrapper do
13
13
  describe ".edit_release_in_user_wantlist" do
14
14
 
15
15
  before do
16
- @oauth_response = mock(OAuth::AccessToken, :code => "200", :body => read_sample("wantlist_release"))
17
- @oauth_response_as_file = mock(StringIO, :read => read_sample("wantlist_release"))
18
- Zlib::GzipReader.should_receive(:new).and_return(@oauth_response_as_file)
19
- @oauth_access_token.should_receive(:post).and_return(@oauth_response)
16
+ @oauth_response = double(OAuth::AccessToken)
17
+
18
+ allow(@oauth_response).to receive_messages(:code => "200", :body => read_sample("wantlist_release"))
19
+
20
+ @oauth_response_as_file = double(StringIO)
21
+
22
+ allow(@oauth_response_as_file).to receive_messages(:read => read_sample("wantlist_release"))
23
+
24
+ expect(Zlib::GzipReader).to receive(:new).and_return(@oauth_response_as_file)
25
+ expect(@oauth_access_token).to receive(:post).and_return(@oauth_response)
20
26
 
21
27
  @wantlist_release = @wrapper.edit_release_in_user_wantlist(@username, @release_id, {:notes => "This is a note"})
22
28
  end
@@ -24,11 +30,11 @@ describe Discogs::Wrapper do
24
30
  describe "when calling simple wantlist release attributes" do
25
31
 
26
32
  it "should have an id" do
27
- @wantlist_release.id.should == 1
33
+ expect(@wantlist_release.id).to eq(1)
28
34
  end
29
35
 
30
36
  it "should have a some notes" do
31
- @wantlist_release.notes.should == "This is a note"
37
+ expect(@wantlist_release.notes).to eq("This is a note")
32
38
  end
33
39
 
34
40
  end
@@ -3,18 +3,25 @@ require 'spec_helper'
3
3
  describe Discogs::Wrapper do
4
4
 
5
5
  before do
6
- @oauth_access_token = mock(OAuth::AccessToken)
7
- @wrapper = Discogs::Wrapper.new("some_user_agent", @oauth_access_token)
6
+ @oauth_access_token = double(OAuth::AccessToken)
7
+ @wrapper = Discogs::Wrapper.new("some_user_agent", :access_token => @oauth_access_token)
8
+
8
9
  @username = "abuntine"
9
10
  end
10
11
 
11
12
  describe ".edit_user" do
12
13
 
13
14
  before do
14
- @oauth_response = mock(OAuth::AccessToken, :code => "200", :body => read_sample("user_profile"))
15
- @oauth_response_as_file = mock(StringIO, :read => read_sample("user_profile"))
16
- Zlib::GzipReader.should_receive(:new).and_return(@oauth_response_as_file)
17
- @oauth_access_token.should_receive(:post).and_return(@oauth_response)
15
+ @oauth_response = double(OAuth::AccessToken)
16
+
17
+ allow(@oauth_response).to receive_messages(:code => "200", :body => read_sample("user_profile"))
18
+
19
+ @oauth_response_as_file = double(StringIO)
20
+
21
+ allow(@oauth_response_as_file).to receive_messages(:read => read_sample("user_profile"))
22
+
23
+ expect(Zlib::GzipReader).to receive(:new).and_return(@oauth_response_as_file)
24
+ expect(@oauth_access_token).to receive(:post).and_return(@oauth_response)
18
25
 
19
26
  @user_profile = @wrapper.edit_user(@username, {:profile => "This is a new profile"})
20
27
  end
@@ -22,11 +29,11 @@ describe Discogs::Wrapper do
22
29
  describe "when calling simple user profile attributes" do
23
30
 
24
31
  it "should have a username" do
25
- @user_profile.username.should == "abuntine"
32
+ expect(@user_profile.username).to eq("abuntine")
26
33
  end
27
34
 
28
35
  it "should have a new profile" do
29
- @user_profile.profile.should == "This is a new profile"
36
+ expect(@user_profile.profile).to eq("This is a new profile")
30
37
  end
31
38
 
32
39
  end
@@ -10,12 +10,7 @@ describe Discogs::Wrapper do
10
10
  describe ".get_artists_releases" do
11
11
 
12
12
  before do
13
- @http_request = mock(Net::HTTP)
14
- @http_response = mock(Net::HTTPResponse, :code => "200", :body => read_sample("artist_releases"))
15
- @http_response_as_file = mock(StringIO, :read => read_sample("artist_releases"))
16
- Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
17
- @http_request.should_receive(:start).and_return(@http_response)
18
- Net::HTTP.should_receive(:new).and_return(@http_request)
13
+ mock_httparty("artist_releases")
19
14
 
20
15
  @artist_releases = @wrapper.get_artist_releases(@artist_id)
21
16
  end
@@ -23,23 +18,23 @@ describe Discogs::Wrapper do
23
18
  describe "when calling simple releases attributes" do
24
19
 
25
20
  it "should have 37 releases per page" do
26
- @artist_releases.releases.length.should == 37
21
+ expect(@artist_releases.releases.length).to eq(37)
27
22
  end
28
23
 
29
24
  it "should have 37 releases total" do
30
- @artist_releases.pagination.items.should == 37
25
+ expect(@artist_releases.pagination.items).to eq(37)
31
26
  end
32
27
 
33
28
  it "should have a first release with a title" do
34
- @artist_releases.releases.first.title.should == "Frost And Fire"
29
+ expect(@artist_releases.releases.first.title).to eq("Frost And Fire")
35
30
  end
36
31
 
37
32
  it "should have a first release with a type" do
38
- @artist_releases.releases.first.type.should == "master"
33
+ expect(@artist_releases.releases.first.type).to eq("master")
39
34
  end
40
35
 
41
36
  it "should not have a bogus attribute" do
42
- @artist_releases.bogus_attr.should be_nil
37
+ expect(@artist_releases.bogus_attr).to be_nil
43
38
  end
44
39
 
45
40
  end
@@ -10,12 +10,7 @@ describe Discogs::Wrapper do
10
10
  describe ".get_artist" do
11
11
 
12
12
  before do
13
- @http_request = mock(Net::HTTP)
14
- @http_response = mock(Net::HTTPResponse, :code => "200", :body => read_sample("artist"))
15
- @http_response_as_file = mock(StringIO, :read => read_sample("artist"))
16
- Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
17
- @http_request.should_receive(:start).and_return(@http_response)
18
- Net::HTTP.should_receive(:new).and_return(@http_request)
13
+ mock_httparty("artist")
19
14
 
20
15
  @artist = @wrapper.get_artist(@artist_id)
21
16
  end
@@ -39,7 +34,7 @@ describe Discogs::Wrapper do
39
34
  end
40
35
 
41
36
  it "should have one or more members" do
42
- @artist.members.should be_instance_of(Array)
37
+ @artist.members.should be_instance_of(Hashie::Array)
43
38
  @artist.members[0].name.should == "Greg Lindstrom"
44
39
  end
45
40
 
@@ -52,13 +47,13 @@ describe Discogs::Wrapper do
52
47
  describe "when calling complex artist attributes" do
53
48
 
54
49
  it "should have a traversible list of URLs" do
55
- @artist.urls.should be_instance_of(Array)
50
+ @artist.urls.should be_instance_of(Hashie::Array)
56
51
  @artist.urls[0].should == "http://www.truemetal.org/cirithungol"
57
52
  @artist.urls[1].should == "http://www.myspace.com/cirithungol"
58
53
  end
59
54
 
60
55
  it "should have a traversible list of images" do
61
- @artist.images.should be_instance_of(Array)
56
+ @artist.images.should be_instance_of(Hashie::Array)
62
57
  end
63
58
 
64
59
  it "should have specifications for each image" do
@@ -3,17 +3,23 @@ require 'spec_helper'
3
3
  describe Discogs::Wrapper do
4
4
 
5
5
  before do
6
- @oauth_access_token = mock(OAuth::AccessToken)
7
- @wrapper = Discogs::Wrapper.new("some_user_agent", @oauth_access_token)
6
+ @oauth_access_token = double(OAuth::AccessToken)
7
+ @wrapper = Discogs::Wrapper.new("some_user_agent", :access_token => @oauth_access_token)
8
8
  end
9
9
 
10
10
  describe ".get_identity" do
11
11
 
12
12
  before do
13
- @oauth_response = mock(OAuth::AccessToken, :code => "200", :body => read_sample("identity"))
14
- @oauth_response_as_file = mock(StringIO, :read => read_sample("identity"))
15
- Zlib::GzipReader.should_receive(:new).and_return(@oauth_response_as_file)
16
- @oauth_access_token.should_receive(:get).and_return(@oauth_response)
13
+ @oauth_response = double(OAuth::AccessToken)
14
+
15
+ allow(@oauth_response).to receive_messages(:code => "200", :body => read_sample("identity"))
16
+
17
+ @oauth_response_as_file = double(StringIO)
18
+
19
+ allow(@oauth_response_as_file).to receive_messages(:read => read_sample("identity"))
20
+
21
+ expect(Zlib::GzipReader).to receive(:new).and_return(@oauth_response_as_file)
22
+ expect(@oauth_access_token).to receive(:get).and_return(@oauth_response)
17
23
 
18
24
  @identity = @wrapper.get_identity
19
25
  end
@@ -21,11 +27,11 @@ describe Discogs::Wrapper do
21
27
  describe "when calling simple identity attributes" do
22
28
 
23
29
  it "should have a username" do
24
- @identity.username.should == "example"
30
+ expect(@identity.username).to eq("example")
25
31
  end
26
32
 
27
33
  it "should have a consumer_name" do
28
- @identity.consumer_name.should == "Your Application Name"
34
+ expect(@identity.consumer_name).to eq("Your Application Name")
29
35
  end
30
36
 
31
37
  end
@@ -10,12 +10,7 @@ describe Discogs::Wrapper do
10
10
  describe ".get_labels_releases" do
11
11
 
12
12
  before do
13
- @http_request = mock(Net::HTTP)
14
- @http_response = mock(Net::HTTPResponse, :code => "200", :body => read_sample("label_releases"))
15
- @http_response_as_file = mock(StringIO, :read => read_sample("label_releases"))
16
- Zlib::GzipReader.should_receive(:new).and_return(@http_response_as_file)
17
- @http_request.should_receive(:start).and_return(@http_response)
18
- Net::HTTP.should_receive(:new).and_return(@http_request)
13
+ mock_httparty("label_releases")
19
14
 
20
15
  @label_releases = @wrapper.get_label_releases(@label_id)
21
16
  end
@@ -23,23 +18,23 @@ describe Discogs::Wrapper do
23
18
  describe "when calling simple releases attributes" do
24
19
 
25
20
  it "should have 8 releases per page" do
26
- @label_releases.releases.length.should == 8
21
+ expect(@label_releases.releases.length).to eq(8)
27
22
  end
28
23
 
29
24
  it "should have 8 releases total" do
30
- @label_releases.pagination.items.should == 8
25
+ expect(@label_releases.pagination.items).to eq(8)
31
26
  end
32
27
 
33
28
  it "should have a first release with a Cat No" do
34
- @label_releases.releases.first.catno.should == "SSS 001"
29
+ expect(@label_releases.releases.first.catno).to eq("SSS 001")
35
30
  end
36
31
 
37
32
  it "should have a first release with a status" do
38
- @label_releases.releases.first.status.should == "Accepted"
33
+ expect(@label_releases.releases.first.status).to eq("Accepted")
39
34
  end
40
35
 
41
36
  it "should not have a bogus attribute" do
42
- @label_releases.bogus_attribute.should be_nil
37
+ expect(@label_releases.bogus_attribute).to be_nil
43
38
  end
44
39
 
45
40
  end