class Yclients::Api::Client

Attributes

login[RW]
partner_token[RW]
password[RW]
user_token[RW]

Public Class Methods

new(args={}) click to toggle source
# File lib/yclients/api/client.rb, line 9
def initialize(args={})
  @partner_token = args[:partner_token] or raise NoPartnerToken
  @user_token = args[:user_token]
  @login = args[:login]
  @password = args[:password]
end

Public Instance Methods

has_user_token?() click to toggle source
# File lib/yclients/api/client.rb, line 16
def has_user_token?
  !!@user_token
end
headers(args={auth: false}) click to toggle source
# File lib/yclients/api/client.rb, line 47
def headers(args={auth: false})
  if args[:auth]
    {
      'Authorization' => "Bearer #{@partner_token}, User #{@user_token}",
      "Content-Type" => 'application/json'
    }
  else
    {
      'Authorization' => "Bearer #{@partner_token}",
      "Content-Type" => 'application/json'
    }
  end
end
query_param(key, value, type) click to toggle source
# File lib/yclients/api/client.rb, line 20
def query_param(key, value, type)
  case type
  when :numeric
    if value.respond_to?(:to_i) && value.to_i > 0
      { key => value }
    else
      {}
    end
  when :boolean
    if value == true
      { key => 1 }
    elsif value == false
      { key => 0 }
    else
      {}
    end
  when :string
    if value.kind_of?(String) && value.length > 0
      { key => value }
    else
      {}
    end
  else
    {}
  end
end