class Notu::Library
Constants
- HOST
Attributes
username[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/notu/library.rb, line 9 def initialize(options = {}) @semaphore = Mutex.new options = options.symbolize_keys self.username = options[:username] end
Public Instance Methods
loved_tracks()
click to toggle source
# File lib/notu/library.rb, line 15 def loved_tracks LovedTracks.new(self) end
most_played_tracks(options = {})
click to toggle source
# File lib/notu/library.rb, line 19 def most_played_tracks(options = {}) MostPlayedTracks.new(self, options) end
played_tracks()
click to toggle source
# File lib/notu/library.rb, line 23 def played_tracks PlayedTracks.new(self) end
url(options = {})
click to toggle source
# File lib/notu/library.rb, line 27 def url(options = {}) options = options.symbolize_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 Instance Methods
username=(value)
click to toggle source
# File lib/notu/library.rb, line 45 def username=(value) @semaphore.synchronize do @username = value.to_s.strip.downcase raise UnknownUsernameError.new(value) if username !~ /^[a-z0-9_]+$/ begin HtmlDocument.get(url) rescue raise UnknownUsernameError.new(value) end end end