class Spof::Wrapper
Public Class Methods
new(options = {})
click to toggle source
# File lib/wrapper.rb, line 8 def initialize(options = {}) @type = nil Spof.config(options) end
Public Instance Methods
album()
click to toggle source
# File lib/wrapper.rb, line 13 def album @type = :album self end
all()
click to toggle source
# File lib/wrapper.rb, line 28 def all @all = true self end
artist()
click to toggle source
# File lib/wrapper.rb, line 18 def artist @type = :artist self end
search(text)
click to toggle source
# File lib/wrapper.rb, line 33 def search(text) @type ||= :all @all ||= false result = [] page = 0 loop do res = case @type when :album Spof::Search.album(text, page)[:albums] when :artist Spof::Search.artist(text, page)[:artists] when :track Spof::Search.track(text, page)[:tracks] when :all? else raise Spof::SpofError, "Invalid search type #{@type}" end result |= res page += 1 break unless @all break if res.empty? end @type = nil # TODO: reset search type? @all = nil return result end
track()
click to toggle source
# File lib/wrapper.rb, line 23 def track @type = :track self end