class Hphones::Endpoint
Stores information for endpoints.
Constants
- ENDPOINTS_PATH
The path to the endpoints file.
Attributes
api[R]
key[R]
params[R]
Public Class Methods
endpoints()
click to toggle source
# File lib/hphones/endpoint.rb, line 21 def endpoints @endpoints ||= load_endpoints_from_file end
lookup(key)
click to toggle source
# File lib/hphones/endpoint.rb, line 17 def lookup(key) !endpoints[key.to_s].nil? end
new(key, api, params = {})
click to toggle source
# File lib/hphones/endpoint.rb, line 32 def initialize(key, api, params = {}) @key = key.to_s @api = api @params = Hashie::Mash.new params end
Private Class Methods
load_endpoints_from_file()
click to toggle source
# File lib/hphones/endpoint.rb, line 27 def load_endpoints_from_file YAML.load_file ENDPOINTS_PATH end
Public Instance Methods
fetch()
click to toggle source
# File lib/hphones/endpoint.rb, line 38 def fetch api_params = compile_params req = Hphones::Request.new(api, self) req.send endpoint_info['method'], api_params end
response_type()
click to toggle source
# File lib/hphones/endpoint.rb, line 44 def response_type endpoint_info['response'] end
Private Instance Methods
compile_pair(spec)
click to toggle source
# File lib/hphones/endpoint.rb, line 62 def compile_pair(spec) spec['value'] ? default_pair_for(spec) : merged_pair_for(spec) end
compile_params()
click to toggle source
# File lib/hphones/endpoint.rb, line 56 def compile_params param_specs = endpoint_info['params'] pairs = param_specs.map { |spec| compile_pair spec } Hash[pairs.compact] end
default_pair_for(spec)
click to toggle source
# File lib/hphones/endpoint.rb, line 66 def default_pair_for(spec) [spec['key'], spec['value']] end
endpoint_info()
click to toggle source
# File lib/hphones/endpoint.rb, line 52 def endpoint_info @endpoint_info ||= self.class.endpoints[key] end
merged_pair_for(spec)
click to toggle source
# File lib/hphones/endpoint.rb, line 70 def merged_pair_for(spec) key = spec['key'] spec['required'] ? required_pair_for(key) : optional_pair_for(key) end
optional_pair_for(key)
click to toggle source
# File lib/hphones/endpoint.rb, line 79 def optional_pair_for(key) params[key] ? [key, params[key]] : nil end
required_pair_for(key)
click to toggle source
# File lib/hphones/endpoint.rb, line 75 def required_pair_for(key) params[key] ? [key, params[key]] : raise(MissingParameterError, "Parameter missing: #{key}") end