module Collins::Api
Public Instance Methods
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
@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
@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
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
@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
@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 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
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
@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
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
# File lib/collins/api.rb, line 102 def use_api_version version set_header "Accept", "application/json,#{version_string(version)}" end
@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
# File lib/collins/api.rb, line 119 def version_string version "application/com.tumblr.collins;version=#{version}" end