spotify-ruby 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -2
- data/.rubocop.yml +16 -5
- data/.travis.yml +10 -1
- data/CODE_OF_CONDUCT.md +1 -1
- data/COVERAGE.md +98 -92
- data/LICENSE +1 -1
- data/README.md +223 -63
- data/Rakefile +5 -12
- data/lib/spotify.rb +2 -2
- data/lib/spotify/accounts.rb +130 -0
- data/lib/spotify/accounts/session.rb +173 -0
- data/lib/spotify/sdk.rb +43 -60
- data/lib/spotify/sdk/album.rb +84 -0
- data/lib/spotify/sdk/artist.rb +162 -0
- data/lib/spotify/sdk/base.rb +34 -16
- data/lib/spotify/sdk/connect.rb +51 -2
- data/lib/spotify/sdk/connect/device.rb +282 -7
- data/lib/spotify/sdk/connect/playback_state.rb +141 -0
- data/lib/spotify/sdk/image.rb +44 -0
- data/lib/spotify/sdk/item.rb +134 -0
- data/lib/spotify/sdk/me.rb +83 -0
- data/lib/spotify/sdk/me/info.rb +108 -0
- data/lib/spotify/sdk/model.rb +40 -23
- data/lib/spotify/version.rb +8 -5
- data/spotify-ruby.gemspec +24 -9
- metadata +87 -38
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/lib/spotify/auth.rb +0 -111
- data/lib/spotify/sdk/initialization.rb +0 -76
- data/lib/spotify/sdk/initialization/base.rb +0 -74
- data/lib/spotify/sdk/initialization/oauth_access_token.rb +0 -34
- data/lib/spotify/sdk/initialization/plain_string.rb +0 -26
- data/lib/spotify/sdk/initialization/query_hash.rb +0 -45
- data/lib/spotify/sdk/initialization/query_string.rb +0 -51
- data/lib/spotify/sdk/initialization/url_string.rb +0 -49
data/lib/spotify/sdk/model.rb
CHANGED
@@ -9,45 +9,62 @@ module Spotify
|
|
9
9
|
##
|
10
10
|
# Initialize a new Model instance.
|
11
11
|
#
|
12
|
-
# @
|
12
|
+
# @example
|
13
|
+
# module Spotify
|
14
|
+
# class SDK
|
15
|
+
# class User < Model
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# @base = Spotify::SDK::Base.new(@sdk)
|
21
|
+
# @user = Spotify::SDK::User.new({ username: "hi" }, @base)
|
22
|
+
# @user.username # => "hi"
|
23
|
+
#
|
24
|
+
# @param [Hash] payload The response payload.
|
13
25
|
# @param [Spotify::SDK] parent The SDK object for context.
|
14
26
|
#
|
15
27
|
def initialize(payload, parent)
|
16
28
|
@payload = payload
|
17
|
-
|
29
|
+
raise "Expected payload to be of Hash type" unless @payload.instance_of?(Hash)
|
18
30
|
|
19
31
|
@parent = parent
|
20
|
-
|
32
|
+
raise "Expected parent to be of Spotify::SDK::Base type" unless @parent.is_a?(Spotify::SDK::Base)
|
21
33
|
|
22
34
|
super(payload)
|
23
35
|
end
|
24
36
|
|
37
|
+
def to_h # :nodoc:
|
38
|
+
super.to_h.except(:parent)
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_json # :nodoc:
|
42
|
+
to_h.to_json
|
43
|
+
end
|
44
|
+
|
25
45
|
##
|
26
|
-
# A reference to Spotify::SDK::Connect
|
46
|
+
# A reference to Spotify::SDK::Connect.
|
27
47
|
#
|
28
48
|
attr_reader :parent
|
29
49
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
50
|
+
class << self
|
51
|
+
def alias_attribute(new_method, attribute) # :nodoc:
|
52
|
+
if attribute.is_a?(Symbol)
|
53
|
+
define_method(new_method) { send(attribute) }
|
54
|
+
else
|
55
|
+
define_method(new_method) do
|
56
|
+
self.class.hash_selector(to_h, attribute)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
35
60
|
|
36
|
-
|
37
|
-
|
61
|
+
def hash_selector(hash, selector)
|
62
|
+
hash.deep_symbolize_keys!
|
63
|
+
segments = selector.split(".")
|
64
|
+
hash = hash[segments.shift.try(:to_sym)] while segments.any?
|
65
|
+
hash
|
66
|
+
end
|
38
67
|
end
|
39
68
|
end
|
40
69
|
end
|
41
|
-
|
42
|
-
class Errors
|
43
|
-
##
|
44
|
-
# A Error class for when the payload is not a Hash instance.
|
45
|
-
#
|
46
|
-
class ModelPayloadExpectedToBeHashError < StandardError; end
|
47
|
-
|
48
|
-
##
|
49
|
-
# A Error class for when the parent is not a Spotify::SDK::Base instance.
|
50
|
-
#
|
51
|
-
class ModelParentInvalidSDKBaseObjectError < StandardError; end
|
52
|
-
end
|
53
70
|
end
|
data/lib/spotify/version.rb
CHANGED
@@ -4,10 +4,13 @@ module Spotify
|
|
4
4
|
##
|
5
5
|
# The definitive version of spotify-ruby.
|
6
6
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# if there is no breaking changes or new features. Anything
|
10
|
-
# else should constitute a major version bump (0.1.0 -> 1.0.0)
|
7
|
+
# We follow the Semantic Versioning convention.
|
8
|
+
# See https://semver.org/ for more information
|
11
9
|
#
|
12
|
-
|
10
|
+
# Summary:
|
11
|
+
# MAJOR version when you make incompatible API changes,
|
12
|
+
# MINOR version when you add functionality in a backwards-compatible manner, and
|
13
|
+
# PATCH version when you make backwards-compatible bug fixes.
|
14
|
+
#
|
15
|
+
VERSION = "0.2.1"
|
13
16
|
end
|
data/spotify-ruby.gemspec
CHANGED
@@ -10,31 +10,46 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ["Bilawal Hameed"]
|
11
11
|
spec.email = ["bil@spotify.com"]
|
12
12
|
|
13
|
-
spec.summary = "
|
13
|
+
spec.summary = "The developer-friendly, opinionated Ruby SDK for Spotify."
|
14
14
|
spec.description = [
|
15
15
|
"Build integrations with the different Spotify APIs",
|
16
16
|
"inside of your application.",
|
17
17
|
"For more information, visit https://developer.spotify.com"
|
18
18
|
].join(" ")
|
19
|
-
spec.homepage = "https://github.
|
19
|
+
spec.homepage = "https://bih.github.io/spotify-ruby"
|
20
20
|
spec.license = "MIT"
|
21
21
|
|
22
22
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
23
|
-
f.match(%r{^(
|
23
|
+
f.match(%r{^(assets|bin|coverage|doc|docs|html|examples|test|spec|features)/})
|
24
24
|
end
|
25
25
|
|
26
|
-
spec.
|
27
|
-
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
28
|
-
spec.require_paths = ["lib"]
|
26
|
+
spec.metadata["yard.run"] = "yri"
|
29
27
|
|
28
|
+
# We don't support executables just yet. Comment this out if you're building one.
|
29
|
+
# spec.bindir = "exe"
|
30
|
+
# spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
|
31
|
+
# spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
# Tooling
|
30
34
|
spec.add_development_dependency "bundler", "~> 1.15", ">= 1.15.4"
|
31
|
-
spec.add_development_dependency "coveralls", "~> 0.8.21"
|
32
35
|
spec.add_development_dependency "rake", "~> 12.1"
|
33
|
-
|
36
|
+
|
37
|
+
# Testing
|
38
|
+
spec.add_development_dependency "factory_bot", "~> 1.0.0.alpha"
|
34
39
|
spec.add_development_dependency "rspec", "~> 3.7"
|
40
|
+
spec.add_development_dependency "rspec-collection_matchers", "~> 1.1", ">= 1.1.2"
|
35
41
|
spec.add_development_dependency "rubocop", "~> 0.51.0"
|
42
|
+
spec.add_development_dependency "simplecov"
|
36
43
|
spec.add_development_dependency "webmock", "~> 3.1"
|
44
|
+
|
45
|
+
# Developer Productivity
|
46
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
47
|
+
|
48
|
+
# Documentation
|
49
|
+
spec.add_development_dependency "yard"
|
50
|
+
spec.add_development_dependency "yard-api"
|
51
|
+
|
52
|
+
# Runtime Dependencies
|
37
53
|
spec.add_runtime_dependency "activesupport", "~> 5.0"
|
38
54
|
spec.add_runtime_dependency "httparty", "~> 0.15.6"
|
39
|
-
spec.add_runtime_dependency "oauth2", "~> 1.4"
|
40
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spotify-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bilawal Hameed
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -31,61 +31,67 @@ dependencies:
|
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 1.15.4
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
34
|
+
name: rake
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: '12.1'
|
40
40
|
type: :development
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: '12.1'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
48
|
+
name: factory_bot
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 1.0.0.alpha
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
60
|
+
version: 1.0.0.alpha
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
62
|
+
name: rspec
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
67
|
+
version: '3.7'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
74
|
+
version: '3.7'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name: rspec
|
76
|
+
name: rspec-collection_matchers
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
81
|
+
version: '1.1'
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.1.2
|
82
85
|
type: :development
|
83
86
|
prerelease: false
|
84
87
|
version_requirements: !ruby/object:Gem::Requirement
|
85
88
|
requirements:
|
86
89
|
- - "~>"
|
87
90
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
91
|
+
version: '1.1'
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.1.2
|
89
95
|
- !ruby/object:Gem::Dependency
|
90
96
|
name: rubocop
|
91
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,6 +106,20 @@ dependencies:
|
|
100
106
|
- - "~>"
|
101
107
|
- !ruby/object:Gem::Version
|
102
108
|
version: 0.51.0
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: simplecov
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
103
123
|
- !ruby/object:Gem::Dependency
|
104
124
|
name: webmock
|
105
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,47 +135,75 @@ dependencies:
|
|
115
135
|
- !ruby/object:Gem::Version
|
116
136
|
version: '3.1'
|
117
137
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
138
|
+
name: pry
|
119
139
|
requirement: !ruby/object:Gem::Requirement
|
120
140
|
requirements:
|
121
141
|
- - "~>"
|
122
142
|
- !ruby/object:Gem::Version
|
123
|
-
version: '
|
124
|
-
type: :
|
143
|
+
version: '0.10'
|
144
|
+
type: :development
|
125
145
|
prerelease: false
|
126
146
|
version_requirements: !ruby/object:Gem::Requirement
|
127
147
|
requirements:
|
128
148
|
- - "~>"
|
129
149
|
- !ruby/object:Gem::Version
|
130
|
-
version: '
|
150
|
+
version: '0.10'
|
131
151
|
- !ruby/object:Gem::Dependency
|
132
|
-
name:
|
152
|
+
name: yard
|
153
|
+
requirement: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
type: :development
|
159
|
+
prerelease: false
|
160
|
+
version_requirements: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
- !ruby/object:Gem::Dependency
|
166
|
+
name: yard-api
|
167
|
+
requirement: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
type: :development
|
173
|
+
prerelease: false
|
174
|
+
version_requirements: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
- !ruby/object:Gem::Dependency
|
180
|
+
name: activesupport
|
133
181
|
requirement: !ruby/object:Gem::Requirement
|
134
182
|
requirements:
|
135
183
|
- - "~>"
|
136
184
|
- !ruby/object:Gem::Version
|
137
|
-
version: 0
|
185
|
+
version: '5.0'
|
138
186
|
type: :runtime
|
139
187
|
prerelease: false
|
140
188
|
version_requirements: !ruby/object:Gem::Requirement
|
141
189
|
requirements:
|
142
190
|
- - "~>"
|
143
191
|
- !ruby/object:Gem::Version
|
144
|
-
version: 0
|
192
|
+
version: '5.0'
|
145
193
|
- !ruby/object:Gem::Dependency
|
146
|
-
name:
|
194
|
+
name: httparty
|
147
195
|
requirement: !ruby/object:Gem::Requirement
|
148
196
|
requirements:
|
149
197
|
- - "~>"
|
150
198
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
199
|
+
version: 0.15.6
|
152
200
|
type: :runtime
|
153
201
|
prerelease: false
|
154
202
|
version_requirements: !ruby/object:Gem::Requirement
|
155
203
|
requirements:
|
156
204
|
- - "~>"
|
157
205
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
206
|
+
version: 0.15.6
|
159
207
|
description: Build integrations with the different Spotify APIs inside of your application.
|
160
208
|
For more information, visit https://developer.spotify.com
|
161
209
|
email:
|
@@ -176,29 +224,29 @@ files:
|
|
176
224
|
- LICENSE
|
177
225
|
- README.md
|
178
226
|
- Rakefile
|
179
|
-
- bin/console
|
180
|
-
- bin/setup
|
181
227
|
- lib/spotify.rb
|
182
|
-
- lib/spotify/
|
228
|
+
- lib/spotify/accounts.rb
|
229
|
+
- lib/spotify/accounts/session.rb
|
183
230
|
- lib/spotify/sdk.rb
|
184
231
|
- lib/spotify/sdk/.keep
|
232
|
+
- lib/spotify/sdk/album.rb
|
233
|
+
- lib/spotify/sdk/artist.rb
|
185
234
|
- lib/spotify/sdk/base.rb
|
186
235
|
- lib/spotify/sdk/connect.rb
|
187
236
|
- lib/spotify/sdk/connect/device.rb
|
188
|
-
- lib/spotify/sdk/
|
189
|
-
- lib/spotify/sdk/
|
190
|
-
- lib/spotify/sdk/
|
191
|
-
- lib/spotify/sdk/
|
192
|
-
- lib/spotify/sdk/
|
193
|
-
- lib/spotify/sdk/initialization/query_string.rb
|
194
|
-
- lib/spotify/sdk/initialization/url_string.rb
|
237
|
+
- lib/spotify/sdk/connect/playback_state.rb
|
238
|
+
- lib/spotify/sdk/image.rb
|
239
|
+
- lib/spotify/sdk/item.rb
|
240
|
+
- lib/spotify/sdk/me.rb
|
241
|
+
- lib/spotify/sdk/me/info.rb
|
195
242
|
- lib/spotify/sdk/model.rb
|
196
243
|
- lib/spotify/version.rb
|
197
244
|
- spotify-ruby.gemspec
|
198
|
-
homepage: https://github.
|
245
|
+
homepage: https://bih.github.io/spotify-ruby
|
199
246
|
licenses:
|
200
247
|
- MIT
|
201
|
-
metadata:
|
248
|
+
metadata:
|
249
|
+
yard.run: yri
|
202
250
|
post_install_message:
|
203
251
|
rdoc_options: []
|
204
252
|
require_paths:
|
@@ -218,5 +266,6 @@ rubyforge_project:
|
|
218
266
|
rubygems_version: 2.6.8
|
219
267
|
signing_key:
|
220
268
|
specification_version: 4
|
221
|
-
summary:
|
269
|
+
summary: The developer-friendly, opinionated Ruby SDK for Spotify.
|
222
270
|
test_files: []
|
271
|
+
has_rdoc:
|
data/bin/console
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require "bundler/setup"
|
5
|
-
require "spotify"
|
6
|
-
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
9
|
-
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
-
# require "pry"
|
12
|
-
# Pry.start
|
13
|
-
|
14
|
-
require "irb"
|
15
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/lib/spotify/auth.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spotify
|
4
|
-
##
|
5
|
-
# Spotify::Auth inherits from OAuth2::Client based on the "oauth-2" gem.
|
6
|
-
#
|
7
|
-
class Auth < OAuth2::Client
|
8
|
-
##
|
9
|
-
# An entire list of Spotify's OAuth scopes. Stored
|
10
|
-
# in the form of a symbolized array.
|
11
|
-
# Example: `[:scope1, :scope2]`
|
12
|
-
#
|
13
|
-
# @see https://developer.spotify.com/web-api/using-scopes/
|
14
|
-
#
|
15
|
-
# Last updated: 21 October 2017
|
16
|
-
#
|
17
|
-
SCOPES = %i[
|
18
|
-
playlist-read-private playlist-read-collaborative
|
19
|
-
playlist-modify-public playlist-modify-private
|
20
|
-
ugc-image-upload user-follow-modify user-follow-read
|
21
|
-
user-library-read user-library-modify user-read-private
|
22
|
-
user-read-birthdate user-read-email user-top-read
|
23
|
-
user-read-playback-state user-modify-playback-state
|
24
|
-
user-read-currently-playing user-read-recently-played
|
25
|
-
streaming
|
26
|
-
].freeze
|
27
|
-
|
28
|
-
##
|
29
|
-
# Error-related translations we're using.
|
30
|
-
#
|
31
|
-
OAUTH_I18N = {
|
32
|
-
must_be_hash: "Must be a Hash. Example: Spotify::Auth.new({ client_id: '', ... })",
|
33
|
-
require_attr: "Expecting a '%s' key. You can obtain from https://developer.spotify.com"
|
34
|
-
}.freeze
|
35
|
-
|
36
|
-
##
|
37
|
-
# Initialize the Spotify Auth object.
|
38
|
-
#
|
39
|
-
# @example
|
40
|
-
# @auth = Spotify::Auth.new({
|
41
|
-
# client_id: "[client id goes here]",
|
42
|
-
# client_secret: "[client secret goes here]",
|
43
|
-
# redirect_uri: "http://localhost"
|
44
|
-
# })
|
45
|
-
#
|
46
|
-
# @param [Hash] config OAuth configuration containing the Client ID, secret and redirect URL.
|
47
|
-
#
|
48
|
-
# @see https://developer.spotify.com/my-applications/
|
49
|
-
#
|
50
|
-
def initialize(config)
|
51
|
-
validate_initialized_input(config)
|
52
|
-
client_id = config.delete(:client_id)
|
53
|
-
client_secret = config.delete(:client_secret)
|
54
|
-
opts = {
|
55
|
-
site: "https://api.spotify.com",
|
56
|
-
authorize_url: "https://accounts.spotify.com/oauth/authorize",
|
57
|
-
token_url: "https://accounts.spotify.com/api/token"
|
58
|
-
}.merge(config)
|
59
|
-
super(client_id, client_secret, opts)
|
60
|
-
end
|
61
|
-
|
62
|
-
##
|
63
|
-
# Get a HTTP URL to send user for authorizing with Spotify.
|
64
|
-
#
|
65
|
-
# @example
|
66
|
-
# @auth = Spotify::Auth.new({
|
67
|
-
# client_id: "[client id goes here]",
|
68
|
-
# client_secret: "[client secret goes here]",
|
69
|
-
# redirect_uri: "http://localhost"
|
70
|
-
# })
|
71
|
-
#
|
72
|
-
# @auth.authorize_url
|
73
|
-
#
|
74
|
-
# @param [Hash] override_params Optional hash containing any overriding values for parameters.
|
75
|
-
# Parameters used are client_id, redirect_uri, response_type and scope.
|
76
|
-
# @return [String] A fully qualified Spotify authorization URL to send the user to.
|
77
|
-
#
|
78
|
-
# @see https://developer.spotify.com/web-api/authorization-guide/
|
79
|
-
#
|
80
|
-
def authorize_url(override_params={})
|
81
|
-
super({
|
82
|
-
client_id: id,
|
83
|
-
response_type: "code",
|
84
|
-
scope: SCOPES.join(" ")
|
85
|
-
}.merge(override_params))
|
86
|
-
end
|
87
|
-
|
88
|
-
private
|
89
|
-
|
90
|
-
##
|
91
|
-
# Validate initialization configuration and raise errors.
|
92
|
-
#
|
93
|
-
# @param [Hash] config OAuth configuration containing the Client ID, secret and redirect URL.
|
94
|
-
# @return [nil]
|
95
|
-
#
|
96
|
-
def validate_initialized_input(config)
|
97
|
-
raise Errors::AuthClientCredentialsError.new(OAUTH_I18N[:must_be_hash]) unless config.is_a?(Hash)
|
98
|
-
|
99
|
-
%i[client_id client_secret].each do |key|
|
100
|
-
raise Errors::AuthClientCredentialsError.new(OAUTH_I18N[:require_attr] % key) unless config.has_key?(key)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
class Errors
|
106
|
-
##
|
107
|
-
# A Error class for when authentication client credentials are empty or incorrectly formatted.
|
108
|
-
#
|
109
|
-
class AuthClientCredentialsError < StandardError; end
|
110
|
-
end
|
111
|
-
end
|