Class: Discogs::Wrapper
- Inherits:
-
Object
- Object
- Discogs::Wrapper
- Includes:
- Authentication
- Defined in:
- lib/wrapper/wrapper.rb
Constant Summary collapse
- @@root_host =
"https://api.discogs.com"
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
-
#user_token ⇒ Object
Returns the value of attribute user_token.
Instance Method Summary collapse
-
#add_release_to_user_folder(username, folder_id, release_id) ⇒ Hash
(also: #add_instance_to_user_folder)
Add a release to a folder in a user’s collection.
-
#add_release_to_user_wantlist(username, release_id, data = {}) ⇒ Hash
Add a release to a user’s wantlist.
-
#create_listing(data = {}) ⇒ Hash
Create a Marketplace listing.
-
#create_order_message(order_id, data = {}) ⇒ Hash
Adds a new message to the order’s message log.
-
#create_user_folder(username, data = {}) ⇒ Hash
(also: #add_user_folder)
Create a new folder in a user’s collection.
-
#delete_instance_in_user_folder(username, folder_id, release_id, instance_id) ⇒ Boolean
(also: #delete_release_in_user_folder)
Remove an instance of a release from a user’s collection folder.
-
#delete_listing(listing_id) ⇒ Boolean
Permanently remove a listing from the Marketplace.
-
#delete_release_in_user_wantlist(username, release_id) ⇒ Boolean
(also: #delete_release_from_user_wantlist)
Remove a release from a user’s wantlist.
-
#delete_user_folder(username, folder_id) ⇒ Boolean
Delete a folder from a user’s collection.
-
#edit_field_on_instance_in_user_folder(username, folder_id, release_id, instance_id, field_id, data = {}) ⇒ Object
Change the value of a notes field on a particular instance.
-
#edit_listing(listing_id, data = {}) ⇒ Hash, Boolean
Edit the data associated with a listing.
-
#edit_order(order_id, data = {}) ⇒ Hash
Edit the data associated with an order.
-
#edit_release_in_user_folder(username, folder_id, release_id, instance_id = 1, data = {}) ⇒ Boolean
(also: #edit_instance_in_user_folder)
Change the rating on a release and/or move the instance to another folder.
-
#edit_release_in_user_wantlist(username, release_id, data = {}) ⇒ Hash
Edit the notes (or rating) on a release in a user’s wantlist.
-
#edit_user(username, data = {}) ⇒ Object
Edit a user’s profile data.
-
#edit_user_folder(username, folder_id, data = {}) ⇒ Hash
Edit a folder’s metadata.
-
#get_artist(artist_id) ⇒ Hash
Retrieves an artist by ID.
-
#get_artists_releases(artist_id, pagination = {}) ⇒ Hash
(also: #get_artist_releases)
Returns a list of Releases and Masters associated with the artist.
-
#get_fee(price, currency = "USD") ⇒ Object
Calculate the fee for the provided price and currency.
-
#get_identity ⇒ Hash
Retrieve basic information about the authenticated user.
-
#get_image(filename) ⇒ Binary
Retrieve an image by filename.
-
#get_label(label_id) ⇒ Hash
Retrieves a label by ID.
-
#get_labels_releases(label_id, pagination = {}) ⇒ Hash
(also: #get_label_releases)
Returns a list of Releases associated with the label.
-
#get_listing(listing_id) ⇒ Hash
View the data associated with a listing.
-
#get_master_release(master_release_id) ⇒ Hash
(also: #get_master)
Retrieves a master release by ID.
-
#get_master_release_versions(master_release_id, pagination = {}) ⇒ Hash
Retrieves a list of all Releases that are versions of this master.
-
#get_order(order_id) ⇒ Hash
View the data associated with an order.
-
#get_price_suggestions(release_id) ⇒ Hash
Retrieve price suggestions for the provided Release ID.
-
#get_release(release_id) ⇒ Hash
Retrieves a release by ID.
-
#get_user(username) ⇒ Hash
Retrieve a user by username.
-
#get_user_collection(username, pagination = {}) ⇒ Hash
Get a collection for a user by username.
-
#get_user_collection_fields(username) ⇒ Hash
Retrieve a list of user-defined collection notes fields.
-
#get_user_folder(username, folder_id) ⇒ Hash
Retrieve metadata about a folder in a user’s collection.
-
#get_user_folder_releases(username, folder_id, params = {}) ⇒ Object
Returns the list of releases in a folder in a user’s collection.
-
#get_user_folders(username) ⇒ Hash
Retrieve a list of folders in a user’s collection.
-
#get_user_inventory(username, params = {}) ⇒ Hash
Returns the list of listings in a user’s inventory.
-
#get_user_want(username, release_id) ⇒ Hash
Returns a specific release in a user’s wantlist by release id.
-
#get_user_wantlist(username, pagination = {}) ⇒ Hash
(also: #get_user_wants)
Returns the list of releases in a user’s wantlist.
-
#initialize(app_name, auth_opts = {}) ⇒ Wrapper
constructor
A new instance of Wrapper.
-
#list_order_messages(order_id, pagination = {}) ⇒ Hash
(also: #get_order_messages)
Returns a list of the order’s messages with the most recent first.
-
#list_orders(params = {}) ⇒ Hash
Returns a list of the authenticated user’s orders.
-
#raw(url, additional_params = {}) ⇒ Hash
Fetch response from API using a fully-qualified URL.
-
#search(term, params = {}) ⇒ Hash
Perform a search.
Methods included from Authentication
#any_authentication?, #auth_params, #authenticate, #authenticated?, #get_request_token, #self_authenticating?, #user_facing?
Constructor Details
#initialize(app_name, auth_opts = {}) ⇒ Wrapper
Returns a new instance of Wrapper.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wrapper/wrapper.rb', line 22 def initialize(app_name, auth_opts={}) @app_name = app_name # Allow for backwards-compatibility with v2.0.0 if auth_opts.is_a?(Hash) @access_token = auth_opts[:access_token] @user_token = auth_opts[:user_token] else @access_token = auth_opts end end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
20 21 22 |
# File 'lib/wrapper/wrapper.rb', line 20 def access_token @access_token end |
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
19 20 21 |
# File 'lib/wrapper/wrapper.rb', line 19 def app_name @app_name end |
#user_token ⇒ Object
Returns the value of attribute user_token.
20 21 22 |
# File 'lib/wrapper/wrapper.rb', line 20 def user_token @user_token end |
Instance Method Details
#add_release_to_user_folder(username, folder_id, release_id) ⇒ Hash Also known as: add_instance_to_user_folder
Authentication as the owner is required.
Add a release to a folder in a user’s collection.
The folder_id must be non-zero – you can use 1 for “Uncategorized”.
253 254 255 256 257 |
# File 'lib/wrapper/wrapper.rb', line 253 def add_release_to_user_folder(username, folder_id, release_id) authenticated? do query_and_build "users/#{username}/collection/folders/#{folder_id}/releases/#{release_id}", {}, :post end end |
#add_release_to_user_wantlist(username, release_id, data = {}) ⇒ Hash
Authentication as the owner is required.
Add a release to a user’s wantlist.
175 176 177 178 179 |
# File 'lib/wrapper/wrapper.rb', line 175 def add_release_to_user_wantlist(username, release_id, data={}) authenticated? do query_and_build "users/#{username}/wants/#{release_id}", {}, :put, data end end |
#create_listing(data = {}) ⇒ Hash
Authentication as the owner is required.
Create a Marketplace listing.
499 500 501 502 503 |
# File 'lib/wrapper/wrapper.rb', line 499 def create_listing(data={}) authenticated? do query_and_build "marketplace/listings", {}, :post, data end end |
#create_order_message(order_id, data = {}) ⇒ Hash
Authentication as the owner is required.
Adds a new message to the order’s message log.
When posting a new message, you can simultaneously change the order status. If you do, the message will automatically be prepended with:
Seller changed status from Old Status to New Status\n\n
While message and status are each optional, one or both must be present.
652 653 654 655 656 |
# File 'lib/wrapper/wrapper.rb', line 652 def (order_id, data={}) authenticated? do query_and_build "marketplace/orders/#{order_id}/messages", {}, :post, data end end |
#create_user_folder(username, data = {}) ⇒ Hash Also known as: add_user_folder
Authentication as the owner is required.
Create a new folder in a user’s collection.
386 387 388 389 390 |
# File 'lib/wrapper/wrapper.rb', line 386 def create_user_folder(username, data={}) authenticated? do query_and_build "users/#{username}/collection/folders", {}, :post, data end end |
#delete_instance_in_user_folder(username, folder_id, release_id, instance_id) ⇒ Boolean Also known as: delete_release_in_user_folder
Authentication as the owner is required.
Remove an instance of a release from a user’s collection folder.
To move the release to the “Uncategorized” folder instead, use the POST method.
293 294 295 296 297 |
# File 'lib/wrapper/wrapper.rb', line 293 def delete_instance_in_user_folder(username, folder_id, release_id, instance_id) authenticated? do query_and_build "/users/#{username}/collection/folders/#{folder_id}/releases/#{release_id}/instances/#{instance_id}", {}, :delete end end |
#delete_listing(listing_id) ⇒ Boolean
Authentication as the owner is required.
Permanently remove a listing from the Marketplace.
526 527 528 529 530 |
# File 'lib/wrapper/wrapper.rb', line 526 def delete_listing(listing_id) authenticated? do query_and_build "marketplace/listings/#{listing_id}", {}, :delete end end |
#delete_release_in_user_wantlist(username, release_id) ⇒ Boolean Also known as: delete_release_from_user_wantlist
Authentication as the owner is required.
Remove a release from a user’s wantlist.
204 205 206 207 208 |
# File 'lib/wrapper/wrapper.rb', line 204 def delete_release_in_user_wantlist(username, release_id) authenticated? do query_and_build "users/#{username}/wants/#{release_id}", {}, :delete end end |
#delete_user_folder(username, folder_id) ⇒ Boolean
Authentication as the owner is required.
Delete a folder from a user’s collection. A folder must be empty before it can be deleted.
416 417 418 419 420 |
# File 'lib/wrapper/wrapper.rb', line 416 def delete_user_folder(username, folder_id) authenticated? do query_and_build "users/#{username}/collection/folders#{folder_id}", {}, :delete end end |
#edit_field_on_instance_in_user_folder(username, folder_id, release_id, instance_id, field_id, data = {}) ⇒ Object
Authentication as the owner is required.
Change the value of a notes field on a particular instance.
312 313 314 315 316 |
# File 'lib/wrapper/wrapper.rb', line 312 def edit_field_on_instance_in_user_folder(username, folder_id, release_id, instance_id, field_id, data={}) authenticated? do query_and_build "/users/#{username}/collection/folders/#{folder_id}/releases/#{release_id}/instances/#{instance_id}/fields/#{field_id}", {}, :post, data end end |
#edit_listing(listing_id, data = {}) ⇒ Hash, Boolean
Authentication as the owner is required.
Edit the data associated with a listing.
If the listing’s status is not For Sale, Draft
, or Expired
, it cannot be modified – only deleted. To re-list a Sold listing, a new listing must be created.
514 515 516 517 518 |
# File 'lib/wrapper/wrapper.rb', line 514 def edit_listing(listing_id, data={}) authenticated? do query_and_build "marketplace/listings/#{listing_id}", {}, :post, data end end |
#edit_order(order_id, data = {}) ⇒ Hash
Authentication as the owner is required.
Edit the data associated with an order.
The conditions under which an order is permitted to transition from one status to another are best summarized by a state diagram.
Rather than implementing this logic in your application, the response contains a next_status key – an array of valid next statuses for this order, which you can display to the user in (for example) a dropdown control. This also renders your application more resilient to any future changes in the order status logic.
Changing the order status using this resource will always message the buyer with:
Seller changed status from Old Status to New Status
and does not provide a facility for including a custom message along with the change. For more fine-grained control, use the Add a new message resource, which allows you to simultaneously add a message and change the order status.
If the order status is neither cancelled
, Payment Received, nor Shipped
, you can change the shipping. Doing so will send an invoice to the buyer and set the order status to Invoice Sent. (For that reason, you cannot set the shipping and the order status in the same request.)
581 582 583 584 585 |
# File 'lib/wrapper/wrapper.rb', line 581 def edit_order(order_id, data={}) authenticated? do query_and_build "marketplace/orders/#{order_id}", {}, :post, data end end |
#edit_release_in_user_folder(username, folder_id, release_id, instance_id = 1, data = {}) ⇒ Boolean Also known as: edit_instance_in_user_folder
Authentication as the owner is required.
Change the rating on a release and/or move the instance to another folder.
274 275 276 277 278 |
# File 'lib/wrapper/wrapper.rb', line 274 def edit_release_in_user_folder(username, folder_id, release_id, instance_id=1, data={}) authenticated? do query_and_build "/users/#{username}/collection/folders/#{folder_id}/releases/#{release_id}/instances/#{instance_id}" end end |
#edit_release_in_user_wantlist(username, release_id, data = {}) ⇒ Hash
Authentication as the owner is required.
Edit the notes (or rating) on a release in a user’s wantlist.
191 192 193 194 195 |
# File 'lib/wrapper/wrapper.rb', line 191 def edit_release_in_user_wantlist(username, release_id, data={}) authenticated? do query_and_build "users/#{username}/wants/#{release_id}", {}, :post, data end end |
#edit_user(username, data = {}) ⇒ Object
Authentication as the owner is required.
Edit a user’s profile data.
236 237 238 239 240 |
# File 'lib/wrapper/wrapper.rb', line 236 def edit_user(username, data={}) authenticated? do query_and_build "users/#{username}", {}, :post, data end end |
#edit_user_folder(username, folder_id, data = {}) ⇒ Hash
Authentication as the owner is required.
Edit a folder’s metadata. Folders 0 and 1 cannot be renamed.
403 404 405 406 407 |
# File 'lib/wrapper/wrapper.rb', line 403 def edit_user_folder(username, folder_id, data={}) authenticated? do query_and_build "users/#{username}/collection/folders#{folder_id}", {}, :post, data end end |
#get_artist(artist_id) ⇒ Hash
Retrieves an artist by ID.
65 66 67 |
# File 'lib/wrapper/wrapper.rb', line 65 def get_artist(artist_id) query_and_build "artists/#{artist_id}" end |
#get_artists_releases(artist_id, pagination = {}) ⇒ Hash Also known as: get_artist_releases
Returns a list of Releases and Masters associated with the artist. Accepts Pagination parameters.
73 74 75 |
# File 'lib/wrapper/wrapper.rb', line 73 def get_artists_releases(artist_id, pagination={}) query_and_build "artists/#{artist_id}/releases", pagination end |
#get_fee(price, currency = "USD") ⇒ Object
Calculate the fee for the provided price and currency.
682 683 684 |
# File 'lib/wrapper/wrapper.rb', line 682 def get_fee(price, currency="USD") query_and_build "marketplace/fee/#{CGI.escape(price)}/#{currency}" end |
#get_identity ⇒ Hash
Authentication as the owner is required.
Retrieve basic information about the authenticated user.
You can use this resource to find out who you’re authenticated as, and it also doubles as a good sanity check to ensure that you’re using OAuth correctly.
For more detailed information, make another request for the user’s Profile.
220 221 222 223 224 |
# File 'lib/wrapper/wrapper.rb', line 220 def get_identity authenticated? do query_and_build "oauth/identity" end end |
#get_image(filename) ⇒ Binary
Authentication as the owner is required.
Retrieve an image by filename.
It’s unlikely that you’ll ever have to construct an image URL; images keys on other resources use fully-qualified URLs, including hostname and protocol.
694 695 696 697 698 699 700 701 702 |
# File 'lib/wrapper/wrapper.rb', line 694 def get_image(filename) authenticated? do if user_facing? @access_token.get("/images/#{filename}").body else query_api("images/#{filename}") end end end |
#get_label(label_id) ⇒ Hash
Retrieves a label by ID.
83 84 85 |
# File 'lib/wrapper/wrapper.rb', line 83 def get_label(label_id) query_and_build "labels/#{label_id}" end |
#get_labels_releases(label_id, pagination = {}) ⇒ Hash Also known as: get_label_releases
Returns a list of Releases associated with the label. Accepts Pagination parameters.
91 92 93 |
# File 'lib/wrapper/wrapper.rb', line 91 def get_labels_releases(label_id, pagination={}) query_and_build "labels/#{label_id}/releases", pagination end |
#get_listing(listing_id) ⇒ Hash
View the data associated with a listing.
If the authorized user is the listing owner the listing will include the weight
, format_quantity
, and external_id
keys.
457 458 459 |
# File 'lib/wrapper/wrapper.rb', line 457 def get_listing(listing_id) query_and_build "marketplace/listings/#{listing_id}" end |
#get_master_release(master_release_id) ⇒ Hash Also known as: get_master
Retrieves a master release by ID.
46 47 48 |
# File 'lib/wrapper/wrapper.rb', line 46 def get_master_release(master_release_id) query_and_build "masters/#{master_release_id}" end |
#get_master_release_versions(master_release_id, pagination = {}) ⇒ Hash
Retrieves a list of all Releases that are versions of this master. Accepts Pagination parameters.
57 58 59 |
# File 'lib/wrapper/wrapper.rb', line 57 def get_master_release_versions(master_release_id, pagination={}) query_and_build "masters/#{master_release_id}/versions", pagination end |
#get_order(order_id) ⇒ Hash
Authentication as the owner is required.
View the data associated with an order.
539 540 541 542 543 |
# File 'lib/wrapper/wrapper.rb', line 539 def get_order(order_id) authenticated? do query_and_build "marketplace/orders/#{order_id}" end end |
#get_price_suggestions(release_id) ⇒ Hash
Authentication as the owner is required.
Retrieve price suggestions for the provided Release ID. If no suggestions are available, an empty object will be returned.
Authentication is required, and the user needs to have filled out their seller settings. Suggested prices will be denominated in the user’s selling currency.
666 667 668 669 670 |
# File 'lib/wrapper/wrapper.rb', line 666 def get_price_suggestions(release_id) authenticated? do query_and_build "marketplace/price_suggestions/#{release_id}" end end |
#get_release(release_id) ⇒ Hash
Retrieves a release by ID.
38 39 40 |
# File 'lib/wrapper/wrapper.rb', line 38 def get_release(release_id) query_and_build "releases/#{release_id}" end |
#get_user(username) ⇒ Hash
Retrieve a user by username.
If authenticated as the requested user, the email key will be visible.
If authenticated as the requested user or the user’s collection/wantlist is public, the num_collection / num_wantlist keys will be visible.
107 108 109 |
# File 'lib/wrapper/wrapper.rb', line 107 def get_user(username) query_and_build "users/#{username}" end |
#get_user_collection(username, pagination = {}) ⇒ Hash
Get a collection for a user by username
Shortcut method for #get_user_folder_releases
118 119 120 |
# File 'lib/wrapper/wrapper.rb', line 118 def get_user_collection(username, pagination={}) get_user_folder_releases(username, 0, pagination) end |
#get_user_collection_fields(username) ⇒ Hash
Retrieve a list of user-defined collection notes fields. These fields are available on every release in the collection.
If the collection has been made private by its owner, authentication as the collection owner is required.
If you are not authenticated as the collection owner, only fields with public set to true will be visible.
130 131 132 |
# File 'lib/wrapper/wrapper.rb', line 130 def get_user_collection_fields(username) query_and_build "users/#{username}/collection/fields" end |
#get_user_folder(username, folder_id) ⇒ Hash
Authentication as the owner is required.
Retrieve metadata about a folder in a user’s collection.
If folder_id is not 0, authentication as the collection owner is required.
358 359 360 361 362 363 364 |
# File 'lib/wrapper/wrapper.rb', line 358 def get_user_folder(username, folder_id) if folder_id == 0 or authenticated? query_and_build "users/#{username}/collection/folders/#{folder_id}" else raise_authentication_error end end |
#get_user_folder_releases(username, folder_id, params = {}) ⇒ Object
Returns the list of releases in a folder in a user’s collection. Accepts Pagination parameters.
Basic information about each release is provided, suitable for display in a list. For detailed information, make another API call to fetch the corresponding release.
If folder_id is not 0, or the collection has been made private by its owner, authentication as the collection owner is required.
If you are not authenticated as the collection owner, only public notes fields will be visible.
341 342 343 344 345 346 347 |
# File 'lib/wrapper/wrapper.rb', line 341 def get_user_folder_releases(username, folder_id, params={}) if folder_id == 0 or authenticated? query_and_build "users/#{username}/collection/folders/#{folder_id}/releases", params else raise_authentication_error end end |
#get_user_folders(username) ⇒ Hash
Retrieve a list of folders in a user’s collection.
If the collection has been made private by its owner, authentication as the collection owner is required.
If you are not authenticated as the collection owner, only folder ID 0 (the “All” folder) will be visible.
374 375 376 |
# File 'lib/wrapper/wrapper.rb', line 374 def get_user_folders(username) query_and_build "users/#{username}/collection/folders" end |
#get_user_inventory(username, params = {}) ⇒ Hash
Returns the list of listings in a user’s inventory. Accepts Pagination parameters.
Basic information about each listing and the corresponding release is provided, suitable for display in a list. For detailed information about the release, make another API call to fetch the corresponding Release.
If you are not authenticated as the inventory owner, only items that have a status of For Sale will be visible.
If you are authenticated as the inventory owner you will get additional weight
, format_quantity
, and external_id
keys.
446 447 448 |
# File 'lib/wrapper/wrapper.rb', line 446 def get_user_inventory(username, params={}) query_and_build "users/#{username}/inventory", params end |
#get_user_want(username, release_id) ⇒ Hash
Returns a specific release in a user’s wantlist by release id.
If the wantlist has been made private by its owner, you must be authenticated as the owner to view it.
The notes field will be visible if you are authenticated as the wantlist owner.
160 161 162 |
# File 'lib/wrapper/wrapper.rb', line 160 def get_user_want(username, release_id) query_and_build "users/#{username}/wants/#{release_id}" end |
#get_user_wantlist(username, pagination = {}) ⇒ Hash Also known as: get_user_wants
Returns the list of releases in a user’s wantlist. Accepts Pagination parameters.
Basic information about each release is provided, suitable for display in a list. For detailed information, make another API call to fetch the corresponding release.
If the wantlist has been made private by its owner, you must be authenticated as the owner to view it.
The notes field will be visible if you are authenticated as the wantlist owner.
145 146 147 |
# File 'lib/wrapper/wrapper.rb', line 145 def get_user_wantlist(username, pagination={}) query_and_build "users/#{username}/wants", pagination end |
#list_order_messages(order_id, pagination = {}) ⇒ Hash Also known as: get_order_messages
Authentication as the owner is required.
Returns a list of the order’s messages with the most recent first. Accepts Pagination parameters.
630 631 632 633 634 |
# File 'lib/wrapper/wrapper.rb', line 630 def (order_id, pagination={}) authenticated? do query_and_build "marketplace/orders/#{order_id}/messages", pagination end end |
#list_orders(params = {}) ⇒ Hash
Authentication as the owner is required.
Returns a list of the authenticated user’s orders. Accepts Pagination parameters.
617 618 619 620 621 |
# File 'lib/wrapper/wrapper.rb', line 617 def list_orders(params={}) authenticated? do query_and_build "marketplace/orders", params end end |
#raw(url, additional_params = {}) ⇒ Hash
Fetch response from API using a fully-qualified URL.
721 722 723 724 725 726 |
# File 'lib/wrapper/wrapper.rb', line 721 def raw(url, additional_params={}) uri = URI.parse(url) params = CGI.parse(uri.query.to_s).merge(additional_params) query_and_build uri.path, params end |
#search(term, params = {}) ⇒ Hash
Authentication as the owner is required.
Perform a search.
710 711 712 713 714 715 |
# File 'lib/wrapper/wrapper.rb', line 710 def search(term, params={}) authenticated? do parameters = {:q => term}.merge(params) query_and_build "database/search", parameters end end |