Class: Notu::Library
- Inherits:
-
Object
- Object
- Notu::Library
- Defined in:
- lib/notu/library.rb
Constant Summary collapse
- DEFAULT_HOST =
'www.last.fm'
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Library
constructor
A new instance of Library.
- #loved_tracks ⇒ Object
- #most_played_tracks(options = {}) ⇒ Object
- #played_tracks ⇒ Object
- #url(options = {}) ⇒ Object
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( = {}) = .stringify_keys self.host = ['host'] self.username = ['username'] end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'lib/notu/library.rb', line 7 def host @host end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/notu/library.rb', line 7 def username @username end |
Instance Method Details
#loved_tracks ⇒ Object
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( = {}) MostPlayedTracks.new(self, ) end |
#played_tracks ⇒ Object
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( = {}) = .stringify_keys path = ['path'].presence query = ['query'].presence query = ['query'].map { |name, value| "#{CGI.escape(name.to_s)}=#{CGI.escape(value.to_s)}" }.join('&') if ['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 |