class Feathr::Client

Attributes

config[RW]

Public Class Methods

default() click to toggle source
# File lib/feathr/client.rb, line 13
def self.default
  @@default ||= Feathr::Client.new
end
new(config: Feathr::Config.default) click to toggle source
# File lib/feathr/client.rb, line 9
def initialize(config: Feathr::Config.default)
  @config = config
end

Public Instance Methods

api_token_auth() click to toggle source
# File lib/feathr/client.rb, line 80
def api_token_auth
  @api_token_auth ||= Feathr::Api::ApiTokenAuth.new(client: self)
end
api_token_refresh() click to toggle source
# File lib/feathr/client.rb, line 84
def api_token_refresh
  @api_token_refresh ||= Feathr::Api::ApiTokenRefresh.new(client: self)
end
api_token_verify() click to toggle source
# File lib/feathr/client.rb, line 88
def api_token_verify
  @api_token_verify ||= Feathr::Api::ApiTokenVerify.new(client: self)
end
auth_headers() click to toggle source
# File lib/feathr/client.rb, line 21
def auth_headers
  { Authorization: "Bearer #{ auth_token }" }
end
auth_token() click to toggle source
# File lib/feathr/client.rb, line 25
def auth_token
  @auth_token ||= if defined?(Rails)
    fetch_from_cache!
  else
    authenticate!
  end
end
authenticate!() click to toggle source
# File lib/feathr/client.rb, line 33
def authenticate!
  @auth_token = api_token_auth.authenticate(
    email:    config.api_email,
    password: config.api_password
  )['token']
end
cashouts() click to toggle source
# File lib/feathr/client.rb, line 96
def cashouts
  @cashouts ||= Feathr::Api::Cashouts.new(client: self)
end
contractors() click to toggle source
# File lib/feathr/client.rb, line 112
def contractors
  @contractors ||= Feathr::Api::Contractors.new(client: self)
end
default_headers() click to toggle source
# File lib/feathr/client.rb, line 17
def default_headers
  { 'Content-Type' => 'application/json' }
end
fetch_from_cache!() click to toggle source
# File lib/feathr/client.rb, line 48
def fetch_from_cache!
  Rails.cache.fetch('qwil_api_token', expires_in: 24.hours) { authenticate! }
end
incomes() click to toggle source
# File lib/feathr/client.rb, line 116
def incomes
  @incomes ||= Feathr::Api::Incomes.new(client: self)
end
invoices() click to toggle source
# File lib/feathr/client.rb, line 136
def invoices
  @invoices ||= Feathr::Api::Invoices.new(client: self)
end
managers() click to toggle source
# File lib/feathr/client.rb, line 100
def managers
  @managers ||= Feathr::Api::Managers.new(client: self)
end
memberships() click to toggle source
# File lib/feathr/client.rb, line 104
def memberships
  @memberships ||= Feathr::Api::Memberships.new(client: self)
end
platforms() click to toggle source
# File lib/feathr/client.rb, line 108
def platforms
  @platforms ||= Feathr::Api::Platforms.new(client: self)
end
rebates() click to toggle source
# File lib/feathr/client.rb, line 120
def rebates
  @rebates ||= Feathr::Api::Rebates.new(client: self)
end
receiveables() click to toggle source
# File lib/feathr/client.rb, line 124
def receiveables
  @receiveables ||= Feathr::Api::Receiveables.new(client: self)
end
refresh_token!() click to toggle source
# File lib/feathr/client.rb, line 40
def refresh_token!
  @auth_token = api_token_refresh.refresh!(auth_token)['token']
end
request(method: :get, path:, query: {}, headers: {}) { |parsed_response| ... } click to toggle source
# File lib/feathr/client.rb, line 52
def request(method: :get, path:, query: {}, headers: {})
  url = [config.base_url, path].join('/')



  unless path == Feathr::Api::ApiTokenAuth.new.api_path
    headers = default_headers.merge(auth_headers).merge(headers)
    query   = query.to_json
  end

  response = self.class.send(
    method,
    url,
    body:     query,
    headers:  headers
  )

  if response.success? && block_given?
    yield response.parsed_response
  elsif response.success?
    response.parsed_response
  else
    raise Feathr::Api::FeathrError.new(
      status: response.code,
      errors: response.parsed_response)
  end
end
reset_password() click to toggle source
# File lib/feathr/client.rb, line 92
def reset_password
  @reset_password ||= Feathr::Api::ResetPassword.new(client: self)
end
users() click to toggle source
# File lib/feathr/client.rb, line 144
def users
  @users ||= Feathr::Api::Users.new(client: self)
end
verify_token!() click to toggle source
# File lib/feathr/client.rb, line 44
def verify_token!
  api_token_verify.verify(auth_token)
end