discogs-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bf847793a00fb7bc5dadf93ec1fe35852b8268ea
4
+ data.tar.gz: 5cc3ed15d1ba578f8eaa25ad92c1cce123f57b42
5
+ SHA512:
6
+ metadata.gz: d674de4cae3a1a553e4f46645b32ce3a196fdcdff11f425d1b2bfeed83b0c38b8f9cb7e660e04de79ed954246b129b6ba67dc750ea120774395168855e47ae68
7
+ data.tar.gz: a9969cfacbaf1834aab962c203e251c58b801db3b7338276cfa8717a50e855b442f6eb1c60bf88e474b054dc47d44454200faeb82630032fc4201101aa34c8a6
@@ -0,0 +1,86 @@
1
+ # Discogs::Api
2
+
3
+ [![Build Status](https://travis-ci.org/shkm/discogs-api.svg?branch=master)](https://travis-ci.org/shkm/discogs-api)
4
+ [![codecov](https://codecov.io/gh/shkm/discogs-api/branch/master/graph/badge.svg)](https://codecov.io/gh/shkm/discogs-api)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/07116b2d10b61e6c2726/maintainability)](https://codeclimate.com/github/shkm/discogs-api/maintainability)
6
+
7
+
8
+ A simple wrapper around the [Discogs API](https://www.discogs.com/developers/).
9
+
10
+ I'm only aiming to implement endpoints that I actually use at this time, which is a very small subset of what's available. See [Implemented Endpoints](#user-content-implemented-endpoints) and consider opening an issue or PR if you need more.
11
+
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'discogs-api'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install discogs-api
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ # Set up a client with your auth token and user agent
33
+ client = Discogs::Api::Client.new('my-auth-token', 'my-user-agent')
34
+
35
+ # Search for an artist
36
+ Discogs::Api::Search.artist(client, query: 'Electric Octopus')
37
+
38
+ # Search for a master
39
+ Discogs::Api::Search.master(client, query: 'This is our Culture')
40
+
41
+ # Search for an release
42
+ Discogs::Api::Search.release(client, query: 'This is our Culture')
43
+
44
+ # Search for a label
45
+ Discogs::Api::Search.label(client, query: 'Heavy Psych Sounds')
46
+
47
+ # Get an artist by its ID
48
+ Discogs::Api::Artist.get(client, 5272208)
49
+
50
+ # Get an artist's releases
51
+ Discogs::Api::Artist.releases(client, 5272208)
52
+ ```
53
+
54
+ ## Implemented Endpoints
55
+
56
+ - [ ] OAuth
57
+ - [ ] GET [oauth/request_token](https://www.discogs.com/developers/#page:authentication)
58
+ - [ ] POST [oauth/access_token](https://www.discogs.com/developers/#page:authentication)
59
+ - [ ] GET [oauth/identify](https://www.discogs.com/developers/#page:authentication)
60
+ - [ ] Releases
61
+ - [ ] GET [releases/:id](https://www.discogs.com/developers/#page:database,header:database-release)
62
+ - [ ] GET [releases/:id/rating](https://www.discogs.com/developers/#page:database,header:database-community-release-rating-get)
63
+ - [ ] GET [releases/:id/rating/:user](https://www.discogs.com/developers/#page:database,header:database-release-rating-by-user)
64
+ - [ ] PUT [releases/:id/rating/:user](https://www.discogs.com/developers/#page:database,header:database-release-rating-by-user-put)
65
+ - [ ] DELETE [releases/:id/rating/:user](https://www.discogs.com/developers/#page:database,header:database-release-rating-by-user-delete)
66
+ - [ ] Masters
67
+ - [ ] GET [masters/:id](https://www.discogs.com/developers/#page:database,header:database-master-release-get)
68
+ - [ ] GET [masters/:id/versions](https://www.discogs.com/developers/#page:database,header:database-master-release-get)
69
+ - [x] Artists
70
+ - [x] GET [artists/:id](https://www.discogs.com/developers/#page:database,header:database-artist-get)
71
+ - [x] GET [artists/:id/releases](https://www.discogs.com/developers/#page:database,header:database-artist-releases)
72
+ - [ ] Labels
73
+ - [ ] GET [label/:id](https://www.discogs.com/developers/#page:database,header:database-artist-releases)
74
+ - [ ] GET [label/:id/releases](https://www.discogs.com/developers/#page:database,header:database-all-label-releases-get)
75
+ - [x] Search
76
+ - [x] GET [database/search](https://www.discogs.com/developers/#page:database,header:database-search-get)
77
+
78
+ There are more endpoints regarding the marketplace, user identity, user collection, user wantlists, and user lists. I have no intention at all of implementing those at the moment.
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shkm/discogs-api.
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,11 @@
1
+ require "discogs/api/version"
2
+
3
+ module Discogs
4
+ module Api; end
5
+ end
6
+
7
+ require 'discogs/api/url'
8
+ require 'discogs/api/response'
9
+ require 'discogs/api/client'
10
+ require 'discogs/api/search'
11
+ require 'discogs/api/artists'
@@ -0,0 +1,9 @@
1
+ module Discogs::Api::Artists
2
+ def self.get(client, artist_id)
3
+ client.get Discogs::Api::Url.resolve('artists', artist_id)
4
+ end
5
+
6
+ def self.releases(client, artist_id)
7
+ client.get Discogs::Api::Url.resolve('artists', artist_id, 'releases')
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ require 'http'
2
+
3
+ class Discogs::Api::Client
4
+ def initialize(auth_token, user_agent)
5
+ @client = HTTP.auth("Discogs token=#{auth_token}")
6
+ .headers(user_agent: user_agent)
7
+ end
8
+
9
+ def get(*args)
10
+ Discogs::Api::Response.new(@client.get(*args))
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ # Simple wrapper around a HTTP::Response to easily parse JSON
2
+ class Discogs::Api::Response < SimpleDelegator
3
+ def to_h
4
+ JSON.parse(to_s, symbolize_names: true)
5
+ end
6
+ end
@@ -0,0 +1,25 @@
1
+ module Discogs::Api::Search
2
+ def self.artist(client, params = {})
3
+ execute(client, { type: :artist }.merge(params))
4
+ end
5
+
6
+ def self.release(client, params = {})
7
+ execute(client, { type: :release }.merge(params))
8
+ end
9
+
10
+ def self.master(client, params = {})
11
+ execute(client, { type: :master }.merge(params))
12
+ end
13
+
14
+ def self.label(client, params = {})
15
+ execute(client, { type: :label }.merge(params))
16
+ end
17
+
18
+ private_class_method def self.execute(client, params = {})
19
+ params[:q] = params.delete(:query) if params[:query]
20
+
21
+ url = Discogs::Api::Url.resolve('database', 'search').freeze
22
+
23
+ client.get(url, params: params)
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ module Discogs::Api::Url
2
+ DEFAULT_ENDPOINT = 'https://api.discogs.com'.freeze
3
+
4
+ def self.resolve(*segments)
5
+ [ENV.fetch('DISCOGS_ENDPOINT', DEFAULT_ENDPOINT), *segments].join('/')
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Discogs
2
+ module Api
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: discogs-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jamie Schembri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cuba
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: codecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: http
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - jamie@schembri.me
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - README.md
147
+ - lib/discogs/api.rb
148
+ - lib/discogs/api/artists.rb
149
+ - lib/discogs/api/client.rb
150
+ - lib/discogs/api/response.rb
151
+ - lib/discogs/api/search.rb
152
+ - lib/discogs/api/url.rb
153
+ - lib/discogs/api/version.rb
154
+ homepage: https://github.com/shkm/discogs-api
155
+ licenses:
156
+ - MIT
157
+ metadata: {}
158
+ post_install_message:
159
+ rdoc_options: []
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ requirements: []
173
+ rubyforge_project:
174
+ rubygems_version: 2.6.14.1
175
+ signing_key:
176
+ specification_version: 4
177
+ summary: Discogs API client in Ruby
178
+ test_files: []