Sha256: 5bae62d65b22312e0318a5ac4b63119bb197e275e0d0b4f9d9a32e131c39e242
Contents?: true
Size: 1.25 KB
Versions: 5
Compression:
Stored size: 1.25 KB
Contents
module Notu class Library DEFAULT_HOST = 'www.last.fm' attr_reader :host, :username def initialize(options = {}) options = options.stringify_keys self.host = options['host'] self.username = options['username'] end def loved_tracks LovedTracks.new(self) end def most_played_tracks(options = {}) MostPlayedTracks.new(self, options) end def played_tracks PlayedTracks.new(self) end 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 private def host=(value) @host = value.presence || DEFAULT_HOST end def username=(value) @username = value.to_s.strip.downcase raise Error.new("Invalid Last.fm username: #{value.inspect}") if username !~ /^[a-z0-9_]+$/ end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
notu-1.0.6 | lib/notu/library.rb |
notu-1.0.5 | lib/notu/library.rb |
notu-1.0.4 | lib/notu/library.rb |
notu-1.0.3 | lib/notu/library.rb |
notu-1.0.2 | lib/notu/library.rb |