discogs-wrapper 2.1.1 → 2.1.2

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: 6c7393abcfb3e6fd0b9c285b1d26d9aad99faedd
4
- data.tar.gz: a739942c39f1c3753e6ecf6241e0a49b44cd9ac2
3
+ metadata.gz: c264470609e42cec3b34d3e3f26eee0ee2ec98ea
4
+ data.tar.gz: 988c6e27cd78fe56077489ffeb9a59ae1cfedd66
5
5
  SHA512:
6
- metadata.gz: be7b13a1e01081c2054879e7abc8c5ad3dd5d7605251e1081c0cc278bec700f0c99939645896ef00784a5bff809e957375a0bd799f2c7b1b3ed650b52989eb46
7
- data.tar.gz: 4a3f21c0ac2801fa6da3f020c60ebc482b5ae1b0ef6323097884a4c427c116125cb5c8784db7ded636c51f34d6cf53b4cc6d4223bf837846f48d51f076226983
6
+ metadata.gz: 3fa923afa4b681feffb684b62ca7a3c98d2aa6c3771a47e534f1b38db6cdd824807fe2863865b6ba55f2d8e08d0467780d443a39078a77d389ae86b167ccc600
7
+ data.tar.gz: 0788c097b724e9a510bf3a341d6c174bdb25650b5c3eddee0af1ac787d3e5906d68655b9817362a5b158d2d595ed07186ad856b79509ddf970be5ba6ea81f883
data/README.markdown CHANGED
@@ -3,7 +3,7 @@ Discogs::Wrapper
3
3
 
4
4
  ABOUT
5
5
  -----
6
- A 100% Ruby wrapper of the Discogs.com API.
6
+ A Ruby wrapper of the Discogs.com API v2.0.
7
7
 
8
8
  Discogs::Wrapper abstracts all of the boilerplate code needed to interact with the Discogs API. It gives you direct access to the information you need. All methods return a ruby Hash wrapped in a [Hashie](https://github.com/intridea/hashie) object with the same structure as documented on the [Discogs API website](http://www.discogs.com/developers/index.html).
9
9
 
@@ -39,7 +39,7 @@ INSTALLATION
39
39
 
40
40
  $ gem install discogs-wrapper
41
41
 
42
- Or within your Gemfile:
42
+ Or, if you are using Bundler:
43
43
 
44
44
  gem "discogs-wrapper"
45
45
 
@@ -47,40 +47,44 @@ USAGE
47
47
  -----
48
48
  To use this library, you must supply the name of your application. For example:
49
49
 
50
- wrapper = Discogs::Wrapper.new("My awesome web app")
50
+ ```ruby
51
+ wrapper = Discogs::Wrapper.new("My awesome web app")
52
+ ```
51
53
 
52
54
  Accessing information is easy:
53
55
 
54
- artist = wrapper.get_artist("329937")
55
- artist_releases = wrapper.get_artist_releases("329937")
56
- release = wrapper.get_release("1529724")
57
- label = wrapper.get_label("29515")
56
+ ```ruby
57
+ artist = wrapper.get_artist("329937")
58
+ artist_releases = wrapper.get_artist_releases("329937")
59
+ release = wrapper.get_release("1529724")
60
+ label = wrapper.get_label("29515")
58
61
 
59
- # You must be authenticated in order to search. I provide a few ways to do this. See the AUTHENTICATION section below.
60
- auth_wrapper = Discogs::Wrapper.new("My awesome web app", app_key: "my_key", app_secret: "my_secret")
61
- search = auth_wrapper.search("Necrovore", :per_page => 10, :type => :artist)
62
+ # You must be authenticated in order to search. I provide a few ways to do this. See the AUTHENTICATION section below.
63
+ auth_wrapper = Discogs::Wrapper.new("My awesome web app", user_token: "my_user_token")
64
+ search = auth_wrapper.search("Necrovore", :per_page => 10, :type => :artist)
62
65
 
63
- artist.name # => "Manilla Road"
64
- artist.members.count # => 4
65
- artist.members.first.name # => "Mark Shelton"
66
- artist.profile # => "Heavy Metal band from ..."
66
+ artist.name # => "Manilla Road"
67
+ artist.members.count # => 4
68
+ artist.members.first.name # => "Mark Shelton"
69
+ artist.profile # => "Heavy Metal band from ..."
67
70
 
68
- artist_releases.releases.count # => 35
69
- artist_releases.releases.first.title # => "Invasion"
71
+ artist_releases.releases.count # => 35
72
+ artist_releases.releases.first.title # => "Invasion"
70
73
 
71
- release.title # => "Medieval"
72
- release.labels.first.name # => "New Renaissance Records"
73
- release.formats[0].descriptions[0] # => "12\""
74
- release.styles # => [ "Heavy Metal", "Doom Metal" ]
75
- release.tracklist[1].title # => "Death is Beauty"
74
+ release.title # => "Medieval"
75
+ release.labels.first.name # => "New Renaissance Records"
76
+ release.formats[0].descriptions[0] # => "12\""
77
+ release.styles # => [ "Heavy Metal", "Doom Metal" ]
78
+ release.tracklist[1].title # => "Death is Beauty"
76
79
 
77
- label.name # => "Monitor (2)"
78
- label.sublabels.count # => 3
80
+ label.name # => "Monitor (2)"
81
+ label.sublabels.count # => 3
79
82
 
80
- search.pagination.items # => 2
81
- search.results.first.title # => "Necrovore"
82
- search.results.first.type # => "artist"
83
- search.results.first.id # => 691078
83
+ search.pagination.items # => 2
84
+ search.results.first.title # => "Necrovore"
85
+ search.results.first.type # => "artist"
86
+ search.results.first.id # => 691078
87
+ ```
84
88
 
85
89
  Many of the API endpoints return further URLs that will yield specific data. To cater for this, the library provides a "raw" method that accepts a valid API URL. For example:
86
90
 
@@ -96,9 +100,9 @@ AUTHENTICATION
96
100
  --------------
97
101
  Many of the API endpoints require the user to be authenticated via oAuth. The library provides support for this.
98
102
 
99
- For non user-facing apps (when you only want to authenticate as yourself), you can simply pass your applications :key and :secret options to the appropriate methods. For example:
103
+ For non user-facing apps (when you only want to authenticate as yourself), you can simply pass your user token (generated from your API dashboard) to the constructor. For example:
100
104
 
101
- wrapper = Discogs::Wrapper.new("Test OAuth", app_key: "my_key", app_secret: "my_secret")
105
+ wrapper = Discogs::Wrapper.new("Test OAuth", user_token: "my_user_token")
102
106
  results = wrapper.search("Nick Cave")
103
107
 
104
108
  For user-facing apps, I've provided [a simple Rails application](https://github.com/buntine/discogs-oauth) that demonstrates how to perform authenticated requests.
@@ -107,37 +111,39 @@ AUTHENTICATION
107
111
 
108
112
  Basically, you should preform the "oAuth dance" like so:
109
113
 
110
- # Add an action to initiate the process.
111
- def authenticate
112
- @discogs = Discogs::Wrapper.new("Test OAuth")
113
- request_data = @discogs.get_request_token("YOUR_APP_KEY", "YOUR_APP_SECRET", "http://127.0.0.1:3000/callback")
114
+ ```ruby
115
+ # Add an action to initiate the process.
116
+ def authenticate
117
+ @discogs = Discogs::Wrapper.new("Test OAuth")
118
+ request_data = @discogs.get_request_token("YOUR_APP_KEY", "YOUR_APP_SECRET", "http://127.0.0.1:3000/callback")
114
119
 
115
- session[:request_token] = request_data[:request_token]
120
+ session[:request_token] = request_data[:request_token]
116
121
 
117
- redirect_to request_data[:authorize_url]
118
- end
122
+ redirect_to request_data[:authorize_url]
123
+ end
119
124
 
120
- # And an action that Discogs will redirect back to.
121
- def callback
122
- @discogs = Discogs::Wrapper.new("Test OAuth")
123
- request_token = session[:request_token]
124
- verifier = params[:oauth_verifier]
125
- access_token = @discogs.authenticate(request_token, verifier)
125
+ # And an action that Discogs will redirect back to.
126
+ def callback
127
+ @discogs = Discogs::Wrapper.new("Test OAuth")
128
+ request_token = session[:request_token]
129
+ verifier = params[:oauth_verifier]
130
+ access_token = @discogs.authenticate(request_token, verifier)
126
131
 
127
- session[:request_token] = nil
128
- session[:access_token] = access_token
132
+ session[:request_token] = nil
133
+ session[:access_token] = access_token
129
134
 
130
- @discogs.access_token = access_token
135
+ @discogs.access_token = access_token
131
136
 
132
- # You can now perform authenticated requests.
133
- end
137
+ # You can now perform authenticated requests.
138
+ end
134
139
 
135
- # Once you have it, you can also pass your access_token into the constructor.
136
- def another_action
137
- @discogs = Discogs::Wrapper.new("Test OAuth", access_token: session[:access_token])
140
+ # Once you have it, you can also pass your access_token into the constructor.
141
+ def another_action
142
+ @discogs = Discogs::Wrapper.new("Test OAuth", access_token: session[:access_token])
138
143
 
139
- # You can now perform authenticated requests.
140
- end
144
+ # You can now perform authenticated requests.
145
+ end
146
+ ```
141
147
 
142
148
  PAGINATION
143
149
  ----------
@@ -145,11 +151,15 @@ PAGINATION
145
151
 
146
152
  Page defaults to 1, page size defaults to 50.
147
153
 
148
- wrapper.get_artist_releases(345211, :page => 2, :per_page => 10)
154
+ ```ruby
155
+ wrapper.get_artist_releases(345211, :page => 2, :per_page => 10)
156
+ ```
149
157
 
150
158
  If other params are accepted, they can also be passed:
151
159
 
152
- wrapper.get_user_inventory("username", :page => 3, :sort => "price", :sort_order => "asc")
160
+ ```ruby
161
+ wrapper.get_user_inventory("username", :page => 3, :sort => "price", :sort_order => "asc")
162
+ ```
153
163
 
154
164
  LICENSE
155
165
  -----
@@ -157,4 +167,4 @@ LICENSE
157
167
 
158
168
  CONTRIBUTORS
159
169
  ------------
160
- List all contributors.
170
+ [Thank you for the support](https://github.com/buntine/discogs/graphs/contributors)
@@ -4,7 +4,7 @@ module Authentication
4
4
 
5
5
  def auth_params
6
6
  if self_authenticating?
7
- {:key => @app_key, :secret => @app_secret}
7
+ {:token => @user_token}
8
8
  else
9
9
  {}
10
10
  end
@@ -19,7 +19,7 @@ module Authentication
19
19
  # Indicates whether this instance is self-authenticated.
20
20
  # @return [Boolean]
21
21
  def self_authenticating?
22
- !@app_key.nil? and !@app_secret.nil?
22
+ !!@user_token
23
23
  end
24
24
 
25
25
  # @return [Boolean]
@@ -34,9 +34,9 @@ module Authentication
34
34
  # @param app_secret [String] application secret
35
35
  # @return [Hash] containing a :request_token that should be stored locally and a :authorize_url that the user must browse to.
36
36
  def get_request_token(app_key, app_secret, callback)
37
- consumer = OAuth::Consumer.new(app_key, app_secret,
38
- :authorize_url => "http://www.discogs.com/oauth/authorize",
39
- :site => "https://api.discogs.com")
37
+ consumer = OAuth::Consumer.new(app_key, app_secret,
38
+ :authorize_url => "http://www.discogs.com/oauth/authorize",
39
+ :site => "https://api.discogs.com")
40
40
  request_token = consumer.get_request_token(:oauth_callback => callback)
41
41
 
42
42
  {:request_token => request_token,
@@ -17,7 +17,7 @@ class Discogs::Wrapper
17
17
  @@root_host = "https://api.discogs.com"
18
18
 
19
19
  attr_reader :app_name
20
- attr_accessor :access_token, :app_key, :app_secret
20
+ attr_accessor :access_token, :user_token
21
21
 
22
22
  def initialize(app_name, auth_opts={})
23
23
  @app_name = app_name
@@ -25,8 +25,7 @@ class Discogs::Wrapper
25
25
  # Allow for backwards-compatibility with v2.0.0
26
26
  if auth_opts.is_a?(Hash)
27
27
  @access_token = auth_opts[:access_token]
28
- @app_key = auth_opts[:app_key]
29
- @app_secret = auth_opts[:app_secret]
28
+ @user_token = auth_opts[:user_token]
30
29
  else
31
30
  @access_token = auth_opts
32
31
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Discogs::Wrapper do
4
4
 
5
5
  before do
6
- @wrapper = Discogs::Wrapper.new("some_user_agent")
6
+ @wrapper = Discogs::Wrapper.new("some_user_agent", :user_token => "token")
7
7
  @search_term = "Winter Falls Over the Land"
8
8
  @search_type = "release"
9
9
  end
@@ -11,7 +11,7 @@ describe Discogs::Wrapper do
11
11
  describe "when handling an advanced search" do
12
12
 
13
13
  it "should properly encode the request URI" do
14
- encoded_uri = "/database/search?f=json&q=Release+Title+artist%3AArtist+Name&type=release"
14
+ encoded_uri = "/database/search?f=json&q=Release+Title+artist%3AArtist+Name&token=token&type=release"
15
15
  get = Net::HTTP::Get.new(encoded_uri)
16
16
  Net::HTTP::Get.should_receive(:new).with(encoded_uri).and_return(get)
17
17
 
@@ -23,7 +23,7 @@ describe Discogs::Wrapper do
23
23
  describe "when handling a search including whitespace" do
24
24
 
25
25
  it "should properly encode spaces in the request URI" do
26
- encoded_uri = "/database/search?f=json&q=One+Two"
26
+ encoded_uri = "/database/search?f=json&q=One+Two&token=token"
27
27
  get = Net::HTTP::Get.new(encoded_uri)
28
28
  Net::HTTP::Get.should_receive(:new).with(encoded_uri).and_return(get)
29
29
 
data/spec/wrapper_spec.rb CHANGED
@@ -39,7 +39,7 @@ describe Discogs::Wrapper do
39
39
 
40
40
  describe "requested URIs" do
41
41
  before do
42
- @uri = mock("uri", :host => "", :query => "", :path => "")
42
+ @uri = mock("uri", :host => "", :query => "", :path => "", :port => "", :scheme => "")
43
43
  end
44
44
 
45
45
  it "should generate the correct release URL to parse" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discogs-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Buntine
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-07 00:00:00.000000000 Z
12
+ date: 2015-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry
@@ -71,16 +71,16 @@ dependencies:
71
71
  name: hashie
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - "~>"
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: '2.1'
76
+ version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - "~>"
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: '2.1'
83
+ version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: oauth
86
86
  requirement: !ruby/object:Gem::Requirement
@@ -175,56 +175,56 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
175
  version: '0'
176
176
  requirements: []
177
177
  rubyforge_project:
178
- rubygems_version: 2.4.4
178
+ rubygems_version: 2.4.8
179
179
  signing_key:
180
180
  specification_version: 4
181
181
  summary: Discogs::Wrapper is a full wrapper for the http://www.discogs.com API V2
182
182
  test_files:
183
- - spec/wrapper_methods/get_artist_spec.rb
184
- - spec/wrapper_methods/get_order_spec.rb
185
- - spec/wrapper_methods/add_release_to_user_wantlist_spec.rb
186
- - spec/wrapper_methods/get_artist_releases_spec.rb
187
- - spec/wrapper_methods/get_label_releases_spec.rb
188
- - spec/wrapper_methods/get_user_folders_spec.rb
183
+ - spec/wrapper_spec.rb
184
+ - spec/spec_helper.rb
185
+ - spec/wrapper_methods/get_user_folder_spec.rb
186
+ - spec/wrapper_methods/get_user_spec.rb
189
187
  - spec/wrapper_methods/get_user_wantlist_spec.rb
190
- - spec/wrapper_methods/get_label_spec.rb
191
- - spec/wrapper_methods/get_order_messages_spec.rb
192
- - spec/wrapper_methods/edit_release_in_user_wantlist_spec.rb
193
- - spec/wrapper_methods/get_release_spec.rb
194
- - spec/wrapper_methods/get_identity_spec.rb
195
- - spec/wrapper_methods/get_listing_spec.rb
196
188
  - spec/wrapper_methods/get_master_release_versions_spec.rb
189
+ - spec/wrapper_methods/search_spec.rb
190
+ - spec/wrapper_methods/get_user_collection_spec.rb
191
+ - spec/wrapper_methods/get_order_spec.rb
192
+ - spec/wrapper_methods/get_listing_spec.rb
197
193
  - spec/wrapper_methods/get_price_suggestions_spec.rb
194
+ - spec/wrapper_methods/add_release_to_user_wantlist_spec.rb
198
195
  - spec/wrapper_methods/get_master_release_spec.rb
199
- - spec/wrapper_methods/get_user_spec.rb
200
- - spec/wrapper_methods/get_user_folder_spec.rb
201
- - spec/wrapper_methods/get_user_inventory_spec.rb
196
+ - spec/wrapper_methods/get_release_spec.rb
197
+ - spec/wrapper_methods/get_order_messages_spec.rb
198
+ - spec/wrapper_methods/get_identity_spec.rb
199
+ - spec/wrapper_methods/get_artist_spec.rb
202
200
  - spec/wrapper_methods/edit_user_spec.rb
203
- - spec/wrapper_methods/search_spec.rb
204
- - spec/wrapper_methods/get_user_collection_spec.rb
205
- - spec/samples/valid_identity.json
201
+ - spec/wrapper_methods/get_artist_releases_spec.rb
202
+ - spec/wrapper_methods/edit_release_in_user_wantlist_spec.rb
203
+ - spec/wrapper_methods/get_user_folders_spec.rb
204
+ - spec/wrapper_methods/get_user_inventory_spec.rb
205
+ - spec/wrapper_methods/get_label_spec.rb
206
+ - spec/wrapper_methods/get_label_releases_spec.rb
206
207
  - spec/samples/valid_user_wantlist.json
207
- - spec/samples/valid_artist.json
208
- - spec/samples/valid_master_release.json
209
- - spec/samples/valid_master_release_versions.json
210
- - spec/samples/valid_label.json
211
208
  - spec/samples/valid_search_results.json
212
- - spec/samples/valid_folder.json
213
- - spec/samples/valid_artist_releases.json
214
- - spec/samples/valid_order.json
215
- - spec/samples/valid_user_collection.json
216
- - spec/samples/valid_order_messages.json
209
+ - spec/samples/valid_fields.json
217
210
  - spec/samples/valid_user_folder.json
211
+ - spec/samples/valid_user_collection.json
212
+ - spec/samples/valid_artist_releases.json
213
+ - spec/samples/valid_master_release.json
214
+ - spec/samples/valid_folder.json
215
+ - spec/samples/valid_price_suggestions.json
218
216
  - spec/samples/valid_listing.json
219
- - spec/samples/valid_orders.json
217
+ - spec/samples/valid_order_messages.json
220
218
  - spec/samples/valid_wantlist_release.json
221
- - spec/samples/valid_price_suggestions.json
222
- - spec/samples/valid_fields.json
223
- - spec/samples/valid_user_inventory.json
224
- - spec/samples/valid_user_profile.json
225
- - spec/samples/valid_user_folders.json
226
- - spec/samples/valid_release.json
227
219
  - spec/samples/valid_label_releases.json
220
+ - spec/samples/valid_label.json
221
+ - spec/samples/valid_user_profile.json
222
+ - spec/samples/valid_user_inventory.json
223
+ - spec/samples/valid_identity.json
228
224
  - spec/samples/valid_user.json
229
- - spec/wrapper_spec.rb
230
- - spec/spec_helper.rb
225
+ - spec/samples/valid_master_release_versions.json
226
+ - spec/samples/valid_artist.json
227
+ - spec/samples/valid_release.json
228
+ - spec/samples/valid_user_folders.json
229
+ - spec/samples/valid_order.json
230
+ - spec/samples/valid_orders.json