class Hphones
Base class for Hphones
. Contains API data and acts as a central place to call methods on.
Constants
- ROOT_PATH
The root path of the Headphones API.
- VERSION
Attributes
api_key[R]
host[R]
http_root[R]
port[R]
protocol[R]
Public Class Methods
new(host:, port:, api_key:, protocol: 'http', http_root: nil)
click to toggle source
@param host [String] the hostname of the Headphones server @param port [String, Integer] the port of the Headphones server @param api_key
[String] the API key generated by Headphones @param protocol [String] the protocol being used (usually 'http' or 'https') @param http_root
[String] the optional root path set in Headphones
# File lib/hphones.rb, line 24 def initialize(host:, port:, api_key:, protocol: 'http', http_root: nil) @host = host @port = port @protocol = protocol @http_root = decorate_http_root(http_root) @api_key = api_key end
Public Instance Methods
base_path()
click to toggle source
# File lib/hphones.rb, line 43 def base_path @base_path ||= "#{http_root}/#{ROOT_PATH}" end
connection()
click to toggle source
Connection and URL stuff
# File lib/hphones.rb, line 35 def connection @connection ||= Faraday.new(url: url) end
method_missing(mth, *args, &blk)
click to toggle source
Methods to pass to Endpoint
Calls superclass method
# File lib/hphones.rb, line 49 def method_missing(mth, *args, &blk) return fetch_from_endpoint(mth, *args) if lookup_endpoint(mth) super end
respond_to_missing?(mth, *)
click to toggle source
Calls superclass method
# File lib/hphones.rb, line 55 def respond_to_missing?(mth, *) !!lookup_endpoint(mth) || super end
url()
click to toggle source
# File lib/hphones.rb, line 39 def url @url ||= "#{protocol}://#{host}:#{port}" end
Private Instance Methods
decorate_http_root(http_root)
click to toggle source
# File lib/hphones.rb, line 71 def decorate_http_root(http_root) if http_root =~ %r{^\/} || http_root.nil? http_root else "/#{http_root}" end end
fetch_from_endpoint(endpoint, params = {})
click to toggle source
# File lib/hphones.rb, line 67 def fetch_from_endpoint(endpoint, params = {}) Endpoint.new(endpoint, self, params).fetch end
lookup_endpoint(endpoint)
click to toggle source
# File lib/hphones.rb, line 63 def lookup_endpoint(endpoint) Endpoint.lookup endpoint end