Class: Notu::UserApi

Inherits:
Api
  • Object
show all
Defined in:
lib/notu/user_api.rb

Constant Summary

Constants inherited from Api

Api::DEFAULT_API_KEY, Api::FORMAT, Api::HOST, Api::VERSION

Instance Attribute Summary collapse

Attributes inherited from Api

#api_key

Instance Method Summary collapse

Constructor Details

#initialize(username:, api_key: DEFAULT_API_KEY) ⇒ UserApi



7
8
9
10
# File 'lib/notu/user_api.rb', line 7

def initialize(username:, api_key: DEFAULT_API_KEY)
  super(api_key:)
  @username = username.try(:squish).presence || raise(Error.new('Username must be specified'))
end

Instance Attribute Details

#usernameObject (readonly)

Returns the value of attribute username.



5
6
7
# File 'lib/notu/user_api.rb', line 5

def username
  @username
end

Instance Method Details

#loved_tracksObject



12
13
14
# File 'lib/notu/user_api.rb', line 12

def loved_tracks
  LovedTracks.new(self)
end

#recent_tracksObject



16
17
18
# File 'lib/notu/user_api.rb', line 16

def recent_tracks
  RecentTracks.new(self)
end

#top_tracks(options = {}) ⇒ Object



20
21
22
# File 'lib/notu/user_api.rb', line 20

def top_tracks(options = {})
  TopTracks.new(self, options)
end

#url(params = {}) ⇒ Object



24
25
26
# File 'lib/notu/user_api.rb', line 24

def url(params = {})
  super((params || {}).symbolize_keys.merge(user: username))
end