class Reservix::Client
Constants
- API_KEY_PARAM_NAME
- API_SUBHOST
- API_VERSION
- DEFAULT_OPTIONS
- USER_AGENT
Attributes
options[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/reservix/client.rb, line 17 def initialize(options = {}) store_options(options) raise ArgumentError, "An api key must be present" if api_key.nil? end
Public Instance Methods
api_host()
click to toggle source
# File lib/reservix/client.rb, line 70 def api_host [API_SUBHOST, host].join(".") end
api_key()
click to toggle source
accessors for options
# File lib/reservix/client.rb, line 53 def api_key @options[:api_key] end
api_module()
click to toggle source
# File lib/reservix/client.rb, line 61 def api_module @options[:api_module] end
api_url()
click to toggle source
# File lib/reservix/client.rb, line 74 def api_url [api_host, API_VERSION, api_module].join("/") end
delete(path, query={}, options={})
click to toggle source
# File lib/reservix/client.rb, line 40 def delete(path, query={}, options={}) handle_response { self.class.delete(*construct_query_arguments(path, options.merge(:query => query))) } end
get(path, query={}, options={})
click to toggle source
# File lib/reservix/client.rb, line 22 def get(path, query={}, options={}) handle_response { self.class.get(*construct_query_arguments(path, options.merge(:query => query))) } end
head(path, query={}, options={})
click to toggle source
# File lib/reservix/client.rb, line 46 def head(path, query={}, options={}) handle_response { self.class.head(*construct_query_arguments(path, options.merge(:query => query))) } end
post(path, body={}, options={})
click to toggle source
# File lib/reservix/client.rb, line 28 def post(path, body={}, options={}) handle_response { self.class.post(*construct_query_arguments(path, options.merge(:body => body), :body)) } end
put(path, body={}, options={})
click to toggle source
# File lib/reservix/client.rb, line 34 def put(path, body={}, options={}) handle_response { self.class.put(*construct_query_arguments(path, options.merge(:body => body), :body)) } end
site()
click to toggle source
# File lib/reservix/client.rb, line 65 def site @options[:site] end
Also aliased as: host
use_ssl?()
click to toggle source
# File lib/reservix/client.rb, line 57 def use_ssl? @options[:use_ssl] end
Private Instance Methods
construct_query_arguments(path_or_uri, options={}, body_or_query=:query)
click to toggle source
# File lib/reservix/client.rb, line 95 def construct_query_arguments(path_or_uri, options={}, body_or_query=:query) uri = URI.parse(path_or_uri) path = uri.path scheme = use_ssl? ? "https" : "http" options = options.dup options[body_or_query] ||= {} options[body_or_query][:format] = "json" options[body_or_query][API_KEY_PARAM_NAME] = api_key [ "#{scheme}://#{api_url}#{path}#{uri.query ? "?#{uri.query}" : ""}", options ] end
handle_response(refreshing_enabled=true, &block)
click to toggle source
# File lib/reservix/client.rb, line 79 def handle_response(refreshing_enabled=true, &block) response = block.call if response && !response.success? raise ResponseError.new(response) elsif response.is_a?(Hash) HashResponseWrapper.new(response) elsif response && response.success? response end end
store_options(options={})
click to toggle source
# File lib/reservix/client.rb, line 90 def store_options(options={}) @options ||= DEFAULT_OPTIONS.dup @options.merge!(options) end