Class: Spotify::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/spotify/client.rb

Constant Summary collapse

BASE_URL =
"https://api.spotify.com/v1"

Instance Attribute Summary collapse

Instance Method Summary collapse

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_tokenObject (readonly)

Returns the value of attribute access_token.



5
6
7
# File 'lib/spotify/client.rb', line 5

def access_token
  @access_token
end

#adapterObject (readonly)

Returns the value of attribute adapter.



5
6
7
# File 'lib/spotify/client.rb', line 5

def adapter
  @adapter
end

Instance Method Details

#albumsObject



28
29
30
# File 'lib/spotify/client.rb', line 28

def albums
  AlbumsResource.new(self)
end

#artistsObject



32
33
34
# File 'lib/spotify/client.rb', line 32

def artists
  ArtistsResource.new(self)
end

#connectionObject



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

#meObject



12
13
14
# File 'lib/spotify/client.rb', line 12

def me
  MeResource.new(self)
end

#playerObject



20
21
22
# File 'lib/spotify/client.rb', line 20

def player
  PlayerResource.new(self)
end

#playlistsObject



36
37
38
# File 'lib/spotify/client.rb', line 36

def playlists
  PlaylistsResource.new(self)
end

#searchObject



16
17
18
# File 'lib/spotify/client.rb', line 16

def search
  SearchResource.new(self)
end

#tracksObject



40
41
42
# File 'lib/spotify/client.rb', line 40

def tracks
  TracksResource.new(self)
end

#usersObject



24
25
26
# File 'lib/spotify/client.rb', line 24

def users
  UsersResource.new(self)
end