GithubHelp home page GithubHelp logo

discogs's Introduction

Discogs::Wrapper

ABOUT

A Ruby wrapper of the Discogs.com API v2.0.

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 object with the same structure as documented on the Discogs API website.

The master branch aims to give full support for version 2.0 of the API. If you need support for everything in version 1.0, see the api-v1 branch.

Specifically:

  • Artists
  • Releases
  • Master Releases
  • Labels
  • Images
  • Searching (all of the above)
  • Marketplace
  • User Inventories
  • Orders
  • Fee Calculations
  • Price Suggestions
  • User Profiles
  • Collections
  • Wantlists
  • oAuth
  • Pagination / Sorting

DOCUMENTATION

You can read the documentation at this projects RDoc page

The Discogs API is documented here.

INSTALLATION

You can install the library via Rubygems:

$ gem install discogs-wrapper

Or, if you are using Bundler:

gem "discogs-wrapper"

USAGE

To use this library, you must supply the name of your application. For example:

require "discogs"

wrapper = Discogs::Wrapper.new("My awesome web app")

Accessing information is easy:

artist          = wrapper.get_artist("329937")
artist_releases = wrapper.get_artist_releases("329937")
release         = wrapper.get_release("1529724")
label           = wrapper.get_label("29515")

# You must be authenticated in order to search. I provide a few ways to do this. See the AUTHENTICATION section below.
auth_wrapper = Discogs::Wrapper.new("My awesome web app", user_token: "my_user_token")
search       = auth_wrapper.search("Necrovore", :per_page => 10, :type => :artist)

artist.name                          # => "Manilla Road"
artist.members.count                 # => 4
artist.members.first.name            # => "Mark Shelton"
artist.profile                       # => "Heavy Metal band from ..."

artist_releases.releases.count       # => 35
artist_releases.releases.first.title # => "Invasion"

release.title                        # => "Medieval"
release.labels.first.name            # => "New Renaissance Records"
release.formats[0].descriptions[0]   # => "12\""
release.styles                       # => [ "Heavy Metal", "Doom Metal" ]
release.tracklist[1].title           # => "Death is Beauty"

label.name                           # => "Monitor (2)"
label.sublabels.count                # => 3

search.pagination.items              # => 2
search.results.first.title           # => "Necrovore"
search.results.first.type            # => "artist"
search.results.first.id              # => 691078

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:

sts_records       = wrapper.get_label(9800)
sts_releases      = wrapper.raw(sts_records.releases_url)
first_sts_release = wrapper.raw(sts_releases.releases[1].resource_url)

first_sts_release.title  # => "I'll Nostra Tempo De La Vita / Having The Time Of Your Life"

You can also add optional querystring overrides to raw calls:

sombre = wrapper.raw("https://api.discogs.com/database/search?q=Sombre+Records&per_page=50&type=release", {"page" => 2})

You can see all implemented methods on this projects RDoc page.

SANITIZATION

The Discogs.com API uses the name "count" in several places, which is sanitized to "total" in this gem in order to prevent overriding the count attribute of Hash.

For example:

release.rating.count # => Returns number of keys in "rating" Hash.
release.rating.total # => Returns total number of ratings as per Discogs API response.

AUTHENTICATION

Many of the API endpoints require the user to be authenticated via oAuth. The library provides support for this.

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:

wrapper = Discogs::Wrapper.new("Test OAuth", user_token: "my_user_token")
results = wrapper.search("Nick Cave")

For user-facing apps, I've provided a simple Rails application that demonstrates how to perform authenticated requests.

Make sure you've created an "app" in your developer settings on the Discogs website. You will need your consumer key and consumer secret.

Basically, you should preform the "oAuth dance" like so:

# Add an action to initiate the process.
def authenticate
  @discogs     = Discogs::Wrapper.new("Test OAuth")
  request_data = @discogs.get_request_token("YOUR_APP_KEY", "YOUR_APP_SECRET", "http://127.0.0.1:3000/callback")

  session[:request_token] = request_data[:request_token]

  redirect_to request_data[:authorize_url]
end

# And an action that Discogs will redirect back to.
def callback
  @discogs      = Discogs::Wrapper.new("Test OAuth")
  request_token = session[:request_token]
  verifier      = params[:oauth_verifier]
  access_token  = @discogs.authenticate(request_token, verifier)

  session[:request_token] = nil
  session[:access_token]  = access_token

  @discogs.access_token = access_token

  # You can now perform authenticated requests.
end

# Once you have it, you can also pass your access_token into the constructor.
def another_action
  @discogs = Discogs::Wrapper.new("Test OAuth", access_token: session[:access_token])

  # You can now perform authenticated requests.
end

PAGINATION

All API endpoints that accept pagination, sorting or other parameters are supported.

Page defaults to 1, page size defaults to 50.

wrapper.get_artist_releases(345211, :page => 2, :per_page => 10)

If other params are accepted, they can also be passed:

wrapper.get_user_inventory("username", :page => 3, :sort => "price", :sort_order => "asc")

LICENSE

See the LICENCE file. Copyright (c) Andrew Buntine

CONTRIBUTORS

Thank you for the support

discogs's People

Contributors

amogower avatar bassnode avatar bingneef avatar bradykimball avatar buntine avatar diegodurs avatar ewollesen avatar jslabovitz avatar link82 avatar lionelerard avatar rex avatar simo2409 avatar team3 avatar thezeroalpha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

discogs's Issues

Provide some documentation

It would be cool if someone could help update the documentation with some basic information about setup, authentication, method calls, etc. I plan to release in about one week.

Implement JSON endpoints

I've continued on from the work bradykimball has merged in and start (re)implementing the endpoints to use JSON.

I've also stubbed out some empty methods that need to be implemented. It's really just a matter of writing tests for them. Each method is really just a call to "query_and_build_json".

Any takers to implement? I will keep working, but someone can fork and tell me which ones they will do to prevent merge conflicts.

RSPEC Failing

Rspec fails on typecasting the response objects, and fails in the Wrapper#search method

Uninitialized constant

Hey,

When I try to use the gem with Rails 3.2.11 I get an uninitialized constant NameError. I checked if I have any other discogs related gems in case of naming collisions but that doesn't seem to be the case.

I have put gem 'discogs-wrapper' in my Gemfile and have run bundle install. Everything seems fine. I checked that the files are in place and the locations and namespaces seem alright to me.

Any ideas on this would be much appreciated.

allow_buffers --> allow_offers

Minor typo in the api comments

In

  • (Hash) create_listing(data = {})
  • (Hash, Boolean) edit_listing(listing_id, data = {})

allow_buffers should be: allow_offers

Authenticated post/put via user_token

From the method: make_request(path, params, method, body) (in wrapper.rb) it seems impossible to perform authenticated non-get requests using the user token. However, I believe this is possible (and I need it for my application). Is there a specific reason you did this I am overlooking?

My proposed code would look like this:

# Generates a HTTP request and returns the response.
def make_request(path, params, method, body)
  full_params   = params.merge(auth_params)
  uri           = build_uri(path, full_params)
  formatted     = "#{uri.path}?#{uri.query}"
  output_format = full_params.fetch(:f, "json")
  headers       = {"Accept"          => "application/#{output_format}",
                   "Accept-Encoding" => "gzip,deflate",
                   "User-Agent"      => @app_name}

  if any_authentication?
    if [:post, :put].include?(method)
      headers["Content-Type"] = "application/json"
      if user_facing?
        @access_token.send(method, formatted, JSON(body), headers)
      else
        HTTParty.send(method, uri, {headers: headers, body: JSON(body)})
      end
    else
      if user_facing?
        @access_token.send(method, formatted, JSON(body), headers)
      else
        HTTParty.send(method, uri, headers: headers)
      end
    end
  else
    # All non-authenticated endpoints are GET.
    HTTParty.get(uri, headers: headers)
  end
end

I am happy to create a PR with updated specs, but checking before I put in the work :)

Release-artist

Hey, is there a method for "release" which returns its artist? If not, is there a way to find out the artist?

Thank you very much

Typos in conditon/sleeve_condition api comments

Typos in the api comments on the values for conditon and sleeve_condition:

Near Mint (NM or NM-) --> Near Mint (NM or M-)
Very Good Plus (VG)+ --> Very Good Plus (VG+)
Good Plus (G)+ --> Good Plus (G+)

Unable to begin rescue => e through wrapper.get_artist("blah")

Hello again,

Trying to collect data from the database when the artist is not found, results in the following error and terminates the program: Discogs::UnkownResource

C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/discogs-wrapper-1.1.2/lib/wrapper/wrapper.rb:103:in raise_unknown_resource': Unknown Discogs resource: artist/Beyonce (Discogs::UnknownResource) from C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/discogs-wrapper-1.1.2/lib/wrapper/wrapper.rb:59:inquery_api'
from C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/discogs-wrapper-1.1.2/lib/wrapper/wrapper.rb:50:in query_and_build' from C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/discogs-wrapper-1.1.2/lib/wrapper/wrapper.rb:30:inget_artist'
from init.rb:12:in block (2 levels) in <main>' from C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/ruby-mp3info-0.6.16/lib/mp3info.rb:305:inopen'
from init.rb:10:in block in <main>' from init.rb:9:ineach'
from init.rb:9:in`

'

Trying to catch the exception does not solve the problem:

list = ["foo","bar", "blah" ]

list.each { | artist |
begin; wrapper.get_artist("#{ artist }")
rescue => e
case e; when Discogs::UnkownResource; puts 'Not found artists'; end
end
end }

in a general catch all still the problem insists. (i.e. begin; ..... ;rescue; puts "Not found Artist"; end)

Any help would be very much appreciated.

Thank you.

Invalid Request Token

Hello,
When I try to authenticate to Discogs API, using access_token = @discogs.authenticate(request_token, verifier)

I get the error :
"OAuth::Error in DiscogsWrapperController#callback
Invalid Request Token"

Edit : it seems that the session[:request_token] isn't considered as an OAuth::RequestToken anymore when we are in the callback function

Can you help me please ? I'm using the same code as you in the auth examples

[DEPRECATED]: The key 'count' has been replaced with 'total'.

Hi,
first of all, thanks for the great work you all, I really love this wrapper, using it for all my applications, makes it way easier for me. I'm just working with this piece of code:

require 'discogs-wrapper'
require 'pp'
aw = Discogs::Wrapper.new("My_Application", user_token: "My_Token")
path='Path to my CSV File with Label ID's of Records'
seperator = ','
values = File.open(path).map{|line| line.chop.split(seperator)}
temp_data=aw.search(values[0][0])["results"][0]
pp aw.get_release(temp_data['id'])['status']

Got this as return:
[DEPRECATED]: The key 'count' has been replaced with 'total'. When accessing, please use the latter. This message will be removed in the next major release.
W, [2018-01-15T19:29:26.463127 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#count defined in Enumerable. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.
W, [2018-01-15T19:29:26.467639 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.
W, [2018-01-15T19:29:26.469200 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.
W, [2018-01-15T19:29:26.469642 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.
W, [2018-01-15T19:29:26.470643 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.
W, [2018-01-15T19:29:26.471159 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.
W, [2018-01-15T19:29:26.471644 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.
W, [2018-01-15T19:29:26.472192 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.
W, [2018-01-15T19:29:26.472653 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.
W, [2018-01-15T19:29:26.473155 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.
W, [2018-01-15T19:29:26.473653 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.

To be honest I'm not really sure what this means to me, I'm pretty new to ruby, but as far as I can see I did not mess with Syntax or Discogs own structure, or did I just get something wrong? Thank you very much!
Greetings, rtuz2th

BUG: NameError: undefined method `type_' for class `Hashie::Mash'

@buntine any idea on below error?

NameError: undefined method type_' for class Hashie::Mash'
from /var/apps/youtoo/shared/bundle/ruby/2.2.0/gems/hashie-3.5.5/lib/hashie/mash.rb:342:in method' from /var/apps/youtoo/shared/bundle/ruby/2.2.0/gems/hashie-3.5.5/lib/hashie/mash.rb:342:in log_built_in_message'
from /var/apps/youtoo/shared/bundle/ruby/2.2.0/gems/hashie-3.5.5/lib/hashie/mash.rb:148:in custom_writer' from /var/apps/youtoo/shared/bundle/ruby/2.2.0/gems/hashie-3.5.5/lib/hashie/mash.rb:217:in block in deep_update'
from /var/apps/youtoo/shared/bundle/ruby/2.2.0/gems/hashie-3.5.5/lib/hashie/mash.rb:210:in each_pair' from /var/apps/youtoo/shared/bundle/ruby/2.2.0/gems/hashie-3.5.5/lib/hashie/mash.rb:210:in deep_update'
from /var/apps/youtoo/shared/bundle/ruby/2.2.0/gems/hashie-3.5.5/lib/hashie/mash.rb:124:in `initialize'
from /var/apps/youtoo/shared/bundle/ruby/2.2.0/gems/hashie-3.5.5/lib/hashie/mash.rb:327:in

"404 XML Output is Deprecated"

I used this gem months ago and everything was working properly, now I'm getting errors so I tried to fetch some artists but I'm always receiving

Net::HTTPBadResponse: wrong status line: "404 XML Output is Deprecated"

I also tried one of examples given in readme like this:

wrapper.get_artist("329937")

But I get the same error

Net::HTTPBadResponse: wrong status line: "404 XML Output is Deprecated"
    from /Users/simone/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:2565:in `read_status_line'
    from /Users/simone/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:2552:in `read_new'
    from /Users/simone/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:1320:in `block in transport_request'
    from /Users/simone/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:1317:in `catch'
    from /Users/simone/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:1317:in `transport_request'
    from /Users/simone/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:1294:in `request'
    from /Users/simone/.rvm/gems/ruby-1.9.3-p429@bantamu/gems/rest-client-1.6.7/lib/restclient/net_http_ext.rb:51:in `request'
    from /Users/simone/.rvm/gems/ruby-1.9.3-p429@bantamu/gems/discogs-wrapper-1.1.4/lib/wrapper/wrapper.rb:89:in `block in make_request'
    from /Users/simone/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/net/http.rb:746:in `start'
    from /Users/simone/.rvm/gems/ruby-1.9.3-p429@bantamu/gems/discogs-wrapper-1.1.4/lib/wrapper/wrapper.rb:88:in `make_request'
    from /Users/simone/.rvm/gems/ruby-1.9.3-p429@bantamu/gems/discogs-wrapper-1.1.4/lib/wrapper/wrapper.rb:61:in `query_api'
    from /Users/simone/.rvm/gems/ruby-1.9.3-p429@bantamu/gems/discogs-wrapper-1.1.4/lib/wrapper/wrapper.rb:54:in `query_and_build'
    from /Users/simone/.rvm/gems/ruby-1.9.3-p429@bantamu/gems/discogs-wrapper-1.1.4/lib/wrapper/wrapper.rb:30:in `get_artist'

Is there any problem with api support?

Thank you

Extension points

In my client code I need to obtain the barcode of a release.

I currently do (as of Discogs::Wrapper,v2)
barcode = release.identifiers && release.identifiers.find{|i|i.type=='Barcode'}
self.ean = barcode && barcode.value.strip

Back in Discogs::Wrapper,v1 I monkey patched Discogs::Release
so that release.barcode was available everywhere

First of all: the change to Hashie::Mash is very good!

But let's have the responses typed again, to enable extending again:
like
class Discogs::Release < Hashie::Mash

or maybe even introducing an extension point for all discogs responses like
Discogs::Release < Discogs::Response < Hashie::Mash

Map missing arrays from nil to [] ?

release = discogs.get_release(...)

sometimes includes release.identifiers but sometimes does not.
(aka release.identifiers == nil)

I'd like to suggest to add some postprocessing to the Discogs::Wrapper
aka: release.identifiers=nil should automagically be mapped to release.identifiers={}

And let's look up all other pieces of the responses where such things might happen.

One might argue, that nil is the proper value here and we should not mess with this.

But on the other hand, the wrapper is ment to make life easy,
and it would be much more convenient, DRY and fool proof.

So actually the contract for release.identifiers would change from:
"might also return nil" to "always returns a hash"
which lessens the clients of the api to check for nil.

Session storing was not storing objects so example in ReadMe was not working.

Hey, first of all, thank for your gem!
I'm a beginner but I encountered an issue while trying it so this might help someone with the same issue.
I had an error "Invalid Token" from OAuth when trying to authenticate with the consummer key to Discogs API.
I encountered an issue using this code from ReadMe.

# Add an action to initiate the process.
def authenticate
  @discogs     = Discogs::Wrapper.new("Test OAuth")
  request_data = @discogs.get_request_token("YOUR_APP_KEY", "YOUR_APP_SECRET", "http://127.0.0.1:3000/callback")

  session[:request_token] = request_data[:request_token]

  redirect_to request_data[:authorize_url]
end

# And an action that Discogs will redirect back to.
def callback
  @discogs      = Discogs::Wrapper.new("Test OAuth")
  request_token = session[:request_token]
  verifier      = params[:oauth_verifier]
  access_token  = @discogs.authenticate(request_token, verifier)

  session[:request_token] = nil
  session[:access_token]  = access_token

  @discogs.access_token = access_token

  # You can now perform authenticated requests.
end

# Once you have it, you can also pass your access_token into the constructor.
def another_action
  @discogs = Discogs::Wrapper.new("Test OAuth", access_token: session[:access_token])

  # You can now perform authenticated requests.
end

To resolve this, I had to follow the procedure and install the gem activerecord-sessions-store
Turns out when you were passing objects through sessions, it was rendered no more as an instance but as JSON data. Using this gem, I was able to log and made it to the end of the callback.

I'm sure it's a common issue, and maybe you had a better solution to this issue.

Missing Genres.

Hi,

Probably this is more of an feature request / question.

I am interested to search by Genre and get all labels from a specific genre. Would this be possible with the search function?

get_release pulling back wrong release

Here's a sample script I have:

#!/usr/bin/env ruby

require 'discogs'
wrapper = Discogs::Wrapper.new("...")

artist = wrapper.get_artist("autechre")
release_id = artist.releases.select{|x| x.title == "Exai" }[0].id
release = wrapper.get_release(release_id)

puts release.title

And here's the output

Finesse / Meet Me Halfway There

Am I doing it wrong?

Testers

All functionality of the Discogs API is now covered. I need someone to help me test all of the functionality before I release.

If anyone is interested, let me know.

JSON parsing support

While the get_user method attempts to query with the XML format, Discogs 2.0 API does not support XML format for users. I want to update the Discogs::User class with information like their collection, but we first need to support JSON parsing.

nil

Hey,
the methods that return hashies kind of dont always work... i tried to get some information from them using the [] method but it sometimes outputs an error "undefined method `[]' for nil:NilClass", so it treats it as nil? im very confused an dont know how to fix that.
Can you help me please?
Thank you

members

Hey,
I tested the methods and, for some reason, when i try artist.members.first.name it works, and it works until fifth.name, but sixth.name and onward shows an error (the artist has 12 members, so the problem is not there). Am i missing something?
Thank you

Is this project dead?

Sorry to be so forward. I am merely curious because this is the only officially recognized Ruby library for the Discogs API and it's painfully out of date. Not only is the API returning responses in JSON now, but this library doesn't even cover the entirety of the Discogs API endpoints. Heck, you can't even specify an ID of an artist to return.

If this project is dead or dying, I'd like to inquire into taking it over. Please let me know!

Pagination at raw calls

There are parts of the api you can only fetch using the raw method that accept pagination, for example if you parse the versions_url of a master release. Raw does not accept any parameters and I tried but could not fix this myself. Could someone please implement this?

The hpricot gem dependency

Hi,

It is mentioned in the README that the discogs gem doesn't need any extra gem or dependency.
However, I had to install the hpricot gem after getting the error below to be able to use discogs.

[1] pry(main)> require 'discogs'
LoadError: cannot load such file -- hpricot
from /home/dinduks/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'

authenticate callback fails on nil when called manually

I'm just trying to get the oauth dance to work.
I copied the example code and put it into a controller.

When invoking the callback manually aka http://mysite/callback
(aka for testing if the callback route works)
I get: undefined method `get_access_token' for nil:NilClass

The error is somehow expected as my manual request is missing the required data.

I'd like to suggest to improve the error message.


undefined method get_access_token' for nil:NilClass discogs-wrapper (2.0.0) lib/wrapper/authentication.rb:28:inauthenticate'

'raise_unknown_resource exception' if try to get user folders being authentificated as the user

If run the code pulling my collection folders,(my_app_key, my_secret_key are keys for my registered app):

require 'discogs-wrapper'
require 'hashie'
wrapper = Discogs::Wrapper.new(App_name, app_key: my_app_key, app_secret: my_secret_key)

puts wrapper.get_user_folders(my_username)

it ends up with error like this, looks like 404 response returned:

C:/Ruby22/lib/ruby/gems/2.2.0/gems/discogs-wrapper-2.1.1/lib/wrapper/wrapper.rb:802:in 'raise_unknown_resource': Unknown Discogs resource: users/xadnight/collection/folders (Discogs::UnknownResource)
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/discogs-wrapper-2.1.1/lib/wrapper/wrapper.rb:733:in 'query_api'
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/discogs-wrapper-2.1.1/lib/wrapper/wrapper.rb:723:in 'query_and_build'
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/discogs-wrapper-2.1.1/lib/wrapper/wrapper.rb:376:in 'get_user_folders'
    from C:/Users/Uladzimir/RubymineProjects/untitled/discogs_client.rb:20:in '<class:DiscogsClient>'
    from C:/Users/Uladzimir/RubymineProjects/untitled/discogs_client.rb:5:in '<top (required)>'

however if remove the authentication params when initiate wrapper with no keys, like this:
wrapper = Discogs::Wrapper.new(App_name)

the same code returns the public 'All' folder:

#<Hashie::Mash folders=[#<Hashie::Mash count=316 id=0 name="All" resource_url="http://api.discogs.com/users/xadnight/collection/folders/0">]>

I expected to get the list of all my folder, including private ones since I had send requests being authenticated.

ps. I'm new to Ruby, so please don't blame me so much. Thanks!

Image URIs blank after gem upgrade

I'm using the uri field on release images as follows:

wrapper = Discogs::Wrapper.new(...)
wrapper.get_release(id)
release.images

In version 2.1.1, the uri field is present, but is a blank string after updating to 2.1.5. I think I'll look more into this later but wanted to open the issue in case you had any ideas before I did.

list_order_messages

It seems slash is missing in list_order_messages method.
query_and_build "marketplace/orders#{order_id}/messages", pagination
I think it should be edited like this.
query_and_build "marketplace/orders/#{order_id}/messages", pagination

Please push to rubygems

...and likely bump the version number. Your latest implementation of Discogs::Wrapper#query_api which takes a params hash is on Github, but not in the version on Rubygems.

This means that your usage example in the Readme doesn't work, e.g.

artist = wrapper.get_artist("Master's Hammer")
release = wrapper.get_release("611973") # Supply an ID.
label = wrapper.get_label("Monitor Records")
search_results = wrapper.search("Necrovore")

artist.name                         # => "Master's Hammer"
artist.releases[0].title            # => NoMethodError: undefined method `[]' for nil:NilClass

...since the Discogs API requests 'releases=1' to get that data and the pushed gem doesn't include the aforementioned params support.

Thanks!

Implement OAuth

Any takers to implement OAuth into the library? Several of the endpoints require authentication and cannot be implemented at the moment.

Mac OS Lion: problem loading the rubygem

Hi, following the instruction of the page I get the following error:

:~ kfam$ sudo gem install discogs-wrapper

Fetching: discogs-wrapper-1.1.2.gem (100%)
Successfully installed discogs-wrapper-1.1.2
1 gem installed
Installing ri documentation for discogs-wrapper-1.1.2...
Installing RDoc documentation for discogs-wrapper-1.1.2...

:~ kfam$ irb

irb(main):001:0> require "rubygems"
=> true
irb(main):002:0> require "discogs"
LoadError: no such file to load -- discogs
from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in gem_original_require' from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:inrequire'
from (irb):2
from :0
irb(main):003:0>

Is there a bug? I've tried several times to repeat this process without any luck..
Can you provide me with a solution ?

Thanks

Discogs API Endpoints Checklist

As per my comment in #22 (comment), below is the totality of the Discogs API endpoints. I figure as they are started a comment should be made to this issue indicating which endpoint you are working on and when complete @buntine can check them off.

  • GET /artists/:id
  • GET /artists/:id/releases
  • GET /releases/:id
  • GET /masters/:id
  • GET /masters/:id/versions
  • GET /labels/:id
  • GET /labels/:id/releases
  • GET /images/:filename
  • GET /database/search
  • GET /users/:username/collection/folders/0/releases
  • GET /users/:username/wants

Added identifiers support and src attribute to video

Hello, I've recently modified your gem to add support for the "identifiers" tag (it usually contains barcodes) and added the src attribute to the Video class.

Take a look if it's ok (I'm a ruby newbie) and if you're interested you can integrate it to your repo.

;)

Outdated README

Hello,

The Usage section in the README is outdated.


wrapper = Discogs::Wrapper.new("My awesome web app")

The Wrapper class apparently doesn't exist anymore (NameError: uninitialized constant Discogs::Wrapper).

Authentication when accessing thumbnail image.

Hi,
I have a Rails application using this wrapper and since few days ago, because of API change I cannot fetch any images using this gem. I get image url like http://api.discogs.com/image/R-150-3492040-1332527654.jpeg
but I cannot show it on my page, or manage it further no more. I've used both Discogs application name and customer key in initializer, none of them worked. If I have to do any additional steps to authenticate, please let me know or include solution on wiki.

Thanks,
Maciek

query_and_build fails upon empty response body

some queries like edit_listing do not return a response body but only a http status code.

response.body => ""

query_and_build than fails in
hash = JSON.parse(data)

with
JSON::ParserError: A JSON text must at least contain two octets!
from /opt/local/lib/ruby2.1/2.1.0/json/common.rb:155:in `initialize'

Instead either nil or an empty Hash should be returned.
I opt for returning an empty Hash when the response.code was in the 200 OK range,
but to return nil when the request failed

New User, Config Help Please

Hi All,

I'm new-ish to RoR, I have written PHP before, and cURL'd the discogs API.

I have added and bundled the Gem, but am wondering where I am supposed to add

wrapper = Discogs::Wrapper.new("Test OAuth", user_token: "my_user_token")
results = wrapper.search("Nick Cave")

Adding to the controller .rb file I get the following error

NameError in ShelvesController#index
uninitialized constant ShelvesController::Discogs

It's probably me being particularly incapable with Ruby (as i said I'm still learning), but any help would be appreciated as its not particularly clear in the docs, where to add the stubs, and how to display the responses

I should add, I'm not planning to use oAuth, as there will be no public facing API access, only through the admin panel when updating the local database

Ta

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.