Class: Notu::Library

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

Constant Summary collapse

DEFAULT_HOST =
'www.last.fm'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Library

Returns a new instance of Library.



9
10
11
12
13
# File 'lib/notu/library.rb', line 9

def initialize(options = {})
  options = options.stringify_keys
  self.host = options['host']
  self.username = options['username']
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#loved_tracksObject



15
16
17
# File 'lib/notu/library.rb', line 15

def loved_tracks
  LovedTracks.new(self)
end

#most_played_tracks(options = {}) ⇒ Object



19
20
21
# File 'lib/notu/library.rb', line 19

def most_played_tracks(options = {})
  MostPlayedTracks.new(self, options)
end

#played_tracksObject



23
24
25
# File 'lib/notu/library.rb', line 23

def played_tracks
  PlayedTracks.new(self)
end

#url(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/notu/library.rb', line 27

def url(options = {})
  options = options.stringify_keys
  path = options['path'].presence
  query = options['query'].presence
  query = options['query'].map { |name, value| "#{CGI.escape(name.to_s)}=#{CGI.escape(value.to_s)}" }.join('&') if options['query'].is_a?(Hash)
  "https://#{host}/user/#{username}".tap do |url|
    if path.present?
      url << '/' unless path.starts_with?('/')
      url << path
    end
    if query.present?
      url << '?' << query
    end
  end
end