module Mopidy::Library
Public Class Methods
lookup(uri)
click to toggle source
# File lib/mopidy/library.rb, line 11 def self.lookup(uri) json = Mopidy.format_json(1, 'core.library.lookup', 'uri': uri) res = Mopidy.post(json) res.body.empty? ? res : format_response(res.body.first, res.status) end
search(keyword)
click to toggle source
# File lib/mopidy/library.rb, line 17 def self.search(keyword) json = Mopidy.format_json(1, 'core.library.search', [{ 'any': keyword }]) Mopidy.post(json) end
search_tracks(keyword)
click to toggle source
# File lib/mopidy/library.rb, line 5 def self.search_tracks(keyword) res = search(keyword) tracks = parse_search_response(res, 'tracks') format_response(tracks, res.status) end
Private Class Methods
format_response(data, status_code)
click to toggle source
# File lib/mopidy/library.rb, line 28 def self.format_response(data, status_code) new_response = OpenStruct.new( parsed_response: { 'result' => data }, code: status_code ) Mopidy::Response.new(new_response) end
parse_search_response(response, type)
click to toggle source
# File lib/mopidy/library.rb, line 24 def self.parse_search_response(response, type) data = response.body.first[type] end