class DaFace::Api::Adapters::Base
Attributes
api_key[R]
host[R]
path_prefix[R]
user[R]
Public Class Methods
new()
click to toggle source
# File lib/da_face/api/adapters/base.rb, line 7 def initialize @host = DaFace.configuration.api_host @path_prefix = DaFace.configuration.api_path_prefix @user = DaFace.configuration.user @api_key = DaFace.configuration.api_key raise DaFace::AdapterError.new('Missing user for authentication') unless @user raise DaFace::AdapterError.new('Missing api_key for authentication') unless @api_key end
Public Instance Methods
api_auth_header()
click to toggle source
Constructs the auth header for Datasift
# File lib/da_face/api/adapters/base.rb, line 43 def api_auth_header "#{self.user}:#{self.api_key}" end
api_path()
click to toggle source
Constructs the base api path for Datasift
# File lib/da_face/api/adapters/base.rb, line 38 def api_path "#{self.host}#{self.path_prefix}" end
default_headers()
click to toggle source
Constructs default headers for operations
# File lib/da_face/api/adapters/base.rb, line 18 def default_headers { 'Authorization' => api_auth_header, 'Accept' => 'application/json' } end
encode_form(payload)
click to toggle source
# File lib/da_face/api/adapters/base.rb, line 33 def encode_form payload URI.encode_www_form(payload) end
get_headers()
click to toggle source
# File lib/da_face/api/adapters/base.rb, line 25 def get_headers default_headers end
post_headers()
click to toggle source
# File lib/da_face/api/adapters/base.rb, line 29 def post_headers default_headers.merge({'Content-Type' => 'application/x-www-form-urlencoded'}) end
set_rate_limit_status(rate_limit, remaining)
click to toggle source
# File lib/da_face/api/adapters/base.rb, line 55 def set_rate_limit_status rate_limit, remaining DaFace.set_rate_limit_status do |status| status.limit = rate_limit status.remaining = remaining end end
url_params(params)
click to toggle source
Transforms a level 1 hash to valid url params
This will return something like “?something=thing” to be appended to url path
# File lib/da_face/api/adapters/base.rb, line 51 def url_params params '?' + URI.encode(params.collect{ |key, value| "#{key}=#{value}"}.join('&')) unless params.empty? end