Class: Chronicle::Spotify::Proxy

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

Constant Summary collapse

PER_PAGE =
50

Instance Method Summary collapse

Constructor Details

#initialize(access_token:, refresh_token:, client_id:, client_secret:, uid:) ⇒ Proxy

Returns a new instance of Proxy.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/chronicle/spotify/proxy.rb', line 8

def initialize(access_token:, refresh_token:, client_id:, client_secret:, uid:)
  auth_hash = {
    'credentials' => {
      'token' => access_token,
      'refresh_token' => refresh_token
    },
    'id' => uid
  }
  RSpotify.authenticate(client_id, client_secret)
  RSpotify.raw_response = true
  @authenticated_user = RSpotify::User.new(auth_hash)
end

Instance Method Details

#recently_played(before: nil, after: nil, limit: nil, &block) ⇒ Object



33
34
35
36
# File 'lib/chronicle/spotify/proxy.rb', line 33

def recently_played(before: nil, after: nil, limit: nil, &block)
  before = before&.to_i&.*(1000)
  retrieve_all(method: :recently_played, before:, after:, limit:, &block)
end

#saved_albums(limit:, after: nil, &block) ⇒ Object



25
26
27
# File 'lib/chronicle/spotify/proxy.rb', line 25

def saved_albums(limit:, after: nil, &block)
  retrieve_all(method: :saved_albums, after:, limit:, &block)
end

#saved_tracks(limit:, after: nil, &block) ⇒ Object



29
30
31
# File 'lib/chronicle/spotify/proxy.rb', line 29

def saved_tracks(limit:, after: nil, &block)
  retrieve_all(method: :saved_tracks, after:, limit:, &block)
end

#userObject



21
22
23
# File 'lib/chronicle/spotify/proxy.rb', line 21

def user
  JSON.parse(RSpotify::User.find(@authenticated_user.id), symbolize_names: true)
end