module Collins::Api

Public Instance Methods

clear_headers() click to toggle source

Clear out all headers @return [nil]

# File lib/collins/api.rb, line 77
def clear_headers
  headers.clear # Yes, this returns an empty hash not nil
end
headers() click to toggle source

@abstract @return [Hash<String,String>] hash with header keys/values

# File lib/collins/api.rb, line 21
def headers
  raise NotImplementedError.new("Classes including the Api module must provide a headers hash")
end
host() click to toggle source

@abstract @return [String] the collins host

# File lib/collins/api.rb, line 27
def host
  raise NotImplementedError.new("Classes including the Api module must provide a host")
end
locations() click to toggle source

Only used for multi-collins systems @abstract @return [Hash<Symbol,OpenStruct>] hash with keys as locations, values as collins credentials.

# File lib/collins/api.rb, line 34
def locations
  raise NotImplementedError.new("Classes including the Api module must provide a locations hash")
end
logger() click to toggle source

@abstract @return [Logger] a logger instance

# File lib/collins/api.rb, line 40
def logger
  raise NotImplementedError.new("Classes including the Api module must provide a logger")
end
password() click to toggle source

@abstract @return [String] a password for authentication

# File lib/collins/api.rb, line 46
def password
  raise NotImplementedError.new("Classes including the Api module must provide a password")
end
set_header(key, value) click to toggle source

Set a key/value in the headers hash

@param [Symbol,String] key @param [String] value @return [nil]

# File lib/collins/api.rb, line 86
def set_header key, value
  headers.update(key => value)
end
strict?(default = false) click to toggle source

How to deal with unexpected API responses

When true, API methods will throw an exception if an unexpected response is encountered. When false, API methods will usually normalize responses to an appropriate value indicating failure.

@param [Boolean] default @abstract @return [Boolean] strict or not

# File lib/collins/api.rb, line 59
def strict? default = false
  raise NotImplementedError.new("Classes including the Api module must provide a strict? method")
end
timeout_i() click to toggle source

@abstract @return [Fixnum] a timeout in seconds

# File lib/collins/api.rb, line 65
def timeout_i
  raise NotImplementedError.new("Classes including the Api module must provide a timeout")
end
trace(progname = nil, &block) click to toggle source

Provides a safe wrapper for our monkeypatched logger

If the provided logger responds to a trace method, use that method. Otherwise fallback to using the debug method.

# File lib/collins/api.rb, line 94
def trace(progname = nil, &block)
  if logger.respond_to?(:trace) then
    logger.trace(progname, &block)
  else
    logger.debug(progname, &block)
  end
end
use_api_version(version) click to toggle source
# File lib/collins/api.rb, line 102
def use_api_version version
  set_header "Accept", "application/json,#{version_string(version)}"
end
username() click to toggle source

@abstract @return [String] a username for authentication

# File lib/collins/api.rb, line 71
def username
  raise NotImplementedError.new("Classes including the Api module must provide a username")
end

Protected Instance Methods

version_string(version) click to toggle source
# File lib/collins/api.rb, line 119
def version_string version
  "application/com.tumblr.collins;version=#{version}"
end