class Totter::Client

API client for interacting with the Seesaw API

Constants

DEFAULTS

Default parameters for the client

Attributes

access_token[R]
api_host[R]
api_scheme[R]
api_version[R]
result_format[R]
transport[R]

Public Class Methods

configure() { |options| ... } click to toggle source

Allows the setting of configuration parameters in a configure block.

# File lib/totter/client.rb, line 50
def self.configure
  yield options
end
new(options = {}) click to toggle source

Initialize a new client.

@param options [Hash] optionally specify `:access_token`, `:api_scheme`, `:api_host`, ':api_url', `:api_version`, `:client_token`, or `:transport`.

# File lib/totter/client.rb, line 57
def initialize(options = {})
  options = { :access_token => options } if options.is_a? String
  options = self.class.options.merge(options)

  # Parse `api_url` option
  if url = options.delete(:api_url)
    uri = URI.parse(url)
    options[:api_scheme] = uri.scheme
    options[:api_host] = uri.host + (uri.port != 80 && uri.port != 443 ? ":#{uri.port}" : '')
  end

  @access_token = options[:access_token] if options[:access_token]
  @api_scheme = options[:api_scheme]
  @api_host = options[:api_host]
  @api_version = options[:api_version]
  @client_token = options[:client_token] if options[:client_token]
  @transport = options[:transport]
  @result_format = options[:result_format]

  # Include transport
  transport_module = Totter::Transport::TRANSPORT_MAP[@transport]
  raise 'Invalid transport' unless transport_module
  self.extend transport_module
end
options() click to toggle source

The current configuration parameters for all clients

# File lib/totter/client.rb, line 40
def self.options
  @options ||= Hashie::Mash.new(DEFAULTS.dup)
end
options=(val) click to toggle source

Sets the current configuration parameters for all clients

# File lib/totter/client.rb, line 45
def self.options=(val)
  @options = val
end
stubbed?() click to toggle source

Returns the current status of HTTP stubbing

# File lib/totter/client.rb, line 104
def self.stubbed?
  @@stubbed
end

Public Instance Methods

authenticated?() click to toggle source

Is the client has an access token.

@return [Boolean] true if it is using one and false if it is not

# File lib/totter/client.rb, line 92
def authenticated?
  @access_token != nil and @access_token.length > 0
end
base_url() click to toggle source

API base URL.

@return [String] API base URL

# File lib/totter/client.rb, line 85
def base_url
  "#{@api_scheme}://#{@api_host}/v#{@api_version}/"
end
ssl?() click to toggle source

Is the client using SSL.

@return [Boolean] true if it is using SSL and false if it is not

# File lib/totter/client.rb, line 99
def ssl?
  @api_scheme == 'https'
end