• Stars
    star
    219
  • Rank 179,734 (Top 4 %)
  • Language
    Ruby
  • License
    Other
  • Created about 15 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Ruby wrapper of the Discogs.com API

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

More Repositories

1

SwervinMervin

A truly radical homage to 16-bit racing games.
Python
231
star
2

barcoders

A barcode encoding library for the Rust programming language
Rust
164
star
3

Simply-Scheme-Exercises

All of the exercises (and their solutions!) from the Berkeley textbook Simply Scheme.
Scheme
111
star
4

MoonDweller

A text-based adventure. You will definitely die.
Clojure
67
star
5

pioneers

An interactive study of the impact of pioneers in the field of computer science.
TypeScript
26
star
6

CarEngines

Some simple techniques for generating car engine sound effects
JavaScript
20
star
7

Medieval-Alien-Massacre

A sadistic, pro-death text-based adventure for children.
Clojure
17
star
8

Dim-Jump

A fried Dim Sim on the run with nothing to lose
Lua
16
star
9

wrestlers-adapter

TCP -> HTTP adapter for alerting on wifi events.
Rust
16
star
10

laser-drift

Reverse engineered Carrera Digital 132/124 infrared controller suite
Python
15
star
11

Haskell--Craft-of-FP

My progress through "Haskell: The Craft of Functional Programming (2nd edition)" by Simon Thompson
Haskell
15
star
12

basmap

Buntine's Awesome SiteMap Audit Program
Rust
10
star
13

discogs-oauth

An example app for authenticating with OAuth using my Discogs library.
Ruby
8
star
14

necroblaster

A rhythm game for the metal-obsessed.
Lua
7
star
15

love2d-top-down-shooter

A prototype top-down shooter game
Lua
5
star
16

bolverk

An 8-bit microprocessor emulator, built for educational purposes.
Ruby
5
star
17

rust-crawler

A simple website crawler in Rust.
Rust
4
star
18

traka

Rails plugin for tracking changes to resources over time.
Ruby
3
star
19

Life-is-a-game

Conway's Game of Life implemented in PLT Scheme
Scheme
3
star
20

love2d-tiled-sti

2D Platformer experiments with Lua, Love2d, Tiled, STI and others
Lua
3
star
21

carrera-champs

Python
3
star
22

merb-restful-links

A Merb plugin that allows you to make "RESTful requests" with the link_to helper method.
3
star
23

dimjump

A fried Dim Sim on the run with nothing to lose...
Clojure
3
star
24

witchhammer

A firefox extension to easily find bands and albums at metal-archives.com
JavaScript
3
star
25

ternary-machines

Notes and examples for an essay
2
star
26

trafficlive

A Python wrapper of the TrafficLive API
Python
2
star
27

dots

For Mel
Clojure
2
star
28

RubySwift

A Ruby wrapper of the Swift Digital Suite API
Ruby
2
star
29

Our-sites

A Clojure web app (Compojure) to display the sites hosted on our staging server.
Clojure
2
star
30

algo2

Rust
2
star
31

dm-multi-hooks

A DataMapper plugin that allows you to assign multiple hook methods easily
2
star
32

Bolverk-Assembler

An assembly language compiler for the Bolverk microprocessor emulator.
Ruby
2
star
33

valshamr

A collection of small, integrated tools that perform some common IPv6 related tasks.
Ruby
2
star
34

Fractals

My experiments in generating fractal art with Scheme
Scheme
1
star
35

rust-playground

My playground for learning Rust. Expect horrible code.
Rust
1
star
36

started-from-the-bottom

Tribute to Drake
JavaScript
1
star
37

Dubstep-Makes-You

JavaScript
1
star
38

p-prime-prime

1
star
39

bunts-io

Bunts.io
Clojure
1
star
40

ir-plot

Python
1
star
41

Quick-ROT13

A Mozilla Firefox extension to quickly apply a ROT13 or ROT47 cipher to a body of text.
JavaScript
1
star
42

The-Solar-System-is-Badass

A parallax demo for my presentation at Web Directions
JavaScript
1
star
43

picster

Example app for my web dev students
Ruby
1
star
44

bolverk_ui

A Sinatra application, which provides a UI for the Bolverk machine emulator
JavaScript
1
star
45

Lisp-Brainfuck-REPL

A brainfuck REPL implemented in Scheme
Scheme
1
star
46

Brainfuck-Yo-self

A basic brainfuck interpreter in Python.
Python
1
star
47

daily_hunks

Daily Hunks for the Bergcloud Little Printer. Hot piece o' ass on demand.
Ruby
1
star
48

cd_git_branch

A "cd" replacement that warns you about non-master branches of a Git repository
Python
1
star
49

jquery.colorChars.js

The most important JQuery plugin in the universe: Colors character groups in a collection of elements.
JavaScript
1
star
50

blobber

A simple Javascript example for my web dev students
JavaScript
1
star