module Authful::Endpoint::ClassMethods

Public Instance Methods

capture_common_errors(error) click to toggle source
# File lib/authful/endpoint.rb, line 34
def capture_common_errors(error)
  if error.http_code == 400
    JSON.parse($!.response)
  elsif error.http_code == 401
    raise Authful::Errors::IncorrectApiToken
  elsif error.http_code == 403
    JSON.parse($!.response)
  elsif error.http_code == 404
    raise Authful::Errors::InvalidUserToken
    JSON.parse($!.response)
  elsif error.http_code == 409
    JSON.parse($!.response)
  else
    raise error
  end
end
config() click to toggle source
# File lib/authful/endpoint.rb, line 15
def config
  @config
end
configure(&block) click to toggle source
# File lib/authful/endpoint.rb, line 11
def configure(&block)
  block.call(@config)
end
headers() click to toggle source
# File lib/authful/endpoint.rb, line 55
def headers
  {"Api-Token" => Authful.config.api_key}
end
send_request(method, path, data = {}) click to toggle source
# File lib/authful/endpoint.rb, line 19
def send_request(method, path, data = {})
  if %w(get delete).include?(method.to_s)
    unless data.empty?
      path << "?" << data.map{|k,v| "#{k}=#{v}"}.join("&")
    end
    r = RestClient::Request.execute(method: method.downcase.to_sym, url: url_for(path), headers: headers, ssl_version: "TLSv1_2")

  else
    r = RestClient::Request.execute(method: method.downcase.to_sym, url: url_for(path), headers: headers, payload: data, ssl_version: "TLSv1_2")
  end
  JSON.parse(r)
rescue
  capture_common_errors($!)
end
url_for(path) click to toggle source
# File lib/authful/endpoint.rb, line 51
def url_for(path)
  [Authful.config.endpoint, path].join("")
end