class Fulfillment::Client

Constants

DEFAULT_TIMEOUT

Attributes

api_key[R]
base_uri[R]
host[R]
logger[RW]
scheme[R]
verbose[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/fulfillment/client.rb, line 11
def initialize(options = {})
  client_options = HashWithIndifferentAccess.new(options)
  @api_key = client_options[:api_key].nil? ? (raise ArgumentError.new(":api_key is a required argument")) : client_options[:api_key]
  @host = client_options[:host].nil? ? (raise ArgumentError.new(":host is a required argument")) : client_options[:host]
  @scheme = client_options[:scheme] || "https"
  @base_uri = @scheme + "://" + @host
  @verbose = client_options[:verbose] || false
  @logger = client_options[:logger] || nil
  @timeout = client_options[:timeout] || DEFAULT_TIMEOUT
end

Public Instance Methods

add_query_parameter(curl, key, value) click to toggle source
# File lib/fulfillment/client.rb, line 41
def add_query_parameter(curl, key, value)
  current_url = curl.url
  curl.url = current_url + (current_url.match(/\?/) ? "&" : "?") + "#{CGI::escape key.to_s}=#{CGI::escape value.to_s}"
end
build_auth_url(resource_path) click to toggle source
# File lib/fulfillment/client.rb, line 37
def build_auth_url(resource_path)
  @base_uri + resource_path
end
configure_http(http) click to toggle source
# File lib/fulfillment/client.rb, line 22
def configure_http(http)
  http.headers["X-API-KEY"] = @api_key
  http.headers["Accept"] = Fulfillment::API_VERSION
  http.headers["Content-Type"] = "application/json"
  if scheme == "https"
    http.use_ssl = Curl::CURL_USESSL_ALL
    http.ssl_verify_peer = false
  end
  http.verbose = @verbose
  unless @logger.nil?
    http.on_debug { |type,data| @logger.info "Fulfillment Client #{data}" }
  end
  http.timeout = @timeout
end
set_request_page(curl, page_num) click to toggle source
# File lib/fulfillment/client.rb, line 46
def set_request_page(curl, page_num)
  add_query_parameter(curl, "page", page_num)
end