class Gocoin::API

Attributes

accounts[R]
client[R]
invoices[R]
merchant[R]
user[R]

Public Class Methods

new(client) click to toggle source
# File lib/gocoin/api.rb, line 6
  def initialize(client)
          @client = client
@accounts = Gocoin::Accounts.new(self)
@invoices = Gocoin::Invoices.new(self)
@merchant = Gocoin::Merchant.new(self)
@user = Gocoin::User.new(self)
  end

Public Instance Methods

request(route, options = {}) click to toggle source
# File lib/gocoin/api.rb, line 14
  def request(route, options = {})
          @client.logger.debug 'Gocoin::API#request called.'
          raise 'Gocoin::API#request: Options is not a hash object' unless options.nil? || options.kind_of?(Hash)
          raise 'Gocoin::API#request: API not ready. Token was not defined' unless @client.token

          headers = options[:headers] ? @client.headers.merge(options[:headers]) : @client.headers.dup
          headers['Authorization'] = "Bearer #{@client.token}"

          options = @client.options.merge(options)
          payload = options[:payload] ? options[:payload].to_json : nil

          config = {
                  url: "#{@client.http_prefix(options[:secure])}#{options[:host]}#{@client.port}#{options[:path]}/#{options[:api_version]}#{route}",
                  method: options[:method],
                  headers: headers,
          }
config[:payload] = options[:payload].to_json if options[:payload]
          @client.raw_request config
  end