Class: Spotify::Client
- Inherits:
-
Object
- Object
- Spotify::Client
- Defined in:
- lib/spotify/client.rb
Constant Summary collapse
- BASE_URL =
"https://api.spotify.com/v1"
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Instance Method Summary collapse
- #albums ⇒ Object
- #artists ⇒ Object
- #connection ⇒ Object
-
#initialize(access_token:, adapter: Faraday.default_adapter) ⇒ Client
constructor
A new instance of Client.
- #me ⇒ Object
- #player ⇒ Object
- #playlists ⇒ Object
- #search ⇒ Object
- #tracks ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(access_token:, adapter: Faraday.default_adapter) ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/spotify/client.rb', line 7 def initialize(access_token:, adapter: Faraday.default_adapter) @access_token = access_token @adapter = adapter end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
5 6 7 |
# File 'lib/spotify/client.rb', line 5 def access_token @access_token end |
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
5 6 7 |
# File 'lib/spotify/client.rb', line 5 def adapter @adapter end |
Instance Method Details
#albums ⇒ Object
28 29 30 |
# File 'lib/spotify/client.rb', line 28 def albums AlbumsResource.new(self) end |
#artists ⇒ Object
32 33 34 |
# File 'lib/spotify/client.rb', line 32 def artists ArtistsResource.new(self) end |
#connection ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/spotify/client.rb', line 44 def connection @connection ||= Faraday.new(BASE_URL) do |conn| conn.request :authorization, :Bearer, access_token conn.headers = { "User-Agent" => "spotifyrb/v#{VERSION} (github.com/deanpcmad/spotifyrb)" } conn.request :json conn.response :json, content_type: "application/json" conn.adapter adapter, @stubs end end |
#me ⇒ Object
12 13 14 |
# File 'lib/spotify/client.rb', line 12 def me MeResource.new(self) end |
#player ⇒ Object
20 21 22 |
# File 'lib/spotify/client.rb', line 20 def player PlayerResource.new(self) end |
#playlists ⇒ Object
36 37 38 |
# File 'lib/spotify/client.rb', line 36 def playlists PlaylistsResource.new(self) end |
#search ⇒ Object
16 17 18 |
# File 'lib/spotify/client.rb', line 16 def search SearchResource.new(self) end |
#tracks ⇒ Object
40 41 42 |
# File 'lib/spotify/client.rb', line 40 def tracks TracksResource.new(self) end |
#users ⇒ Object
24 25 26 |
# File 'lib/spotify/client.rb', line 24 def users UsersResource.new(self) end |