module Acoustid::API
Public Class Methods
get(request, http_adapter=nil)
click to toggle source
# File lib/acoustid/api.rb, line 22 def get(request, http_adapter=nil) raise TypeError unless request.is_a?(Request::Base) http_request = HTTPI::Request.new( url: request.uri, query: request.params ) HTTPI.get(http_request, http_adapter) end
lookup(options={})
click to toggle source
# File lib/acoustid/api.rb, line 12 def lookup(options={}) options = parse_options(options) require 'acoustid/api/request/lookup' request = Request::Lookup.new( options[:params] ) send( options[:method], request, options[:adapter] ) end
post(request, adapter=nil)
click to toggle source
# File lib/acoustid/api.rb, line 30 def post(request, adapter=nil) raise TypeError unless request.is_a?(Request::Base) http_request = HTTPI::Request.new( url: request.uri, body: request.params ) HTTPI.post(http_request, adapter) end
Protected Class Methods
parse_options(options={})
click to toggle source
# File lib/acoustid/api.rb, line 40 def parse_options(options={}) raise TypeError, 'options must respond to :to_hash or :to_h' unless options.respond_to?(:to_hash) || options.respond_to?(:to_h) options = options.to_hash rescue options.to_h options = { method: :post }.merge(options) raise TypeError, 'option :method must respond_to :to_sym' unless options[:method].respond_to?(:to_sym) options[:method] = options[:method].to_s.strip.to_sym raise TypeError, 'option :method must be either :get or :post' unless [:get, :post].include?( options[:method] ) raise TypeError, 'option :params must respond to :to_hash or :to_h' unless options[:params].respond_to?(:to_hash) || options[:params].respond_to?(:to_h) options[:params] = options[:params].to_hash rescue options[:params].to_h raise TypeError, 'option :adapter must respond_to :to_sym or be nil' unless options[:adapter].nil? || options[:adapter].respond_to?(:to_sym) options[:adapter] = options[:adapter].to_s.strip.to_sym unless options[:adapter].nil? options end