Class: KaChing::ApiV1::Saldo

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ka_ching/api_v1/saldo.rb

Overview

Saldo Endpoint for the KaChing API V1

Instance Method Summary collapse

Constructor Details

#initialize(conn:, api_url:) ⇒ Saldo

Returns a new instance of Saldo.



13
14
15
16
# File 'lib/ka_ching/api_v1/saldo.rb', line 13

def initialize(conn:, api_url:)
  @conn = conn
  @api_url = api_url
end

Instance Method Details

#current(tenant_account_id:) {|Faraday::Response| ... } ⇒ Hash

Get the current saldo (in cents)

Parameters:

  • tenant_account_id (String)

    without the tenant database namespace, e.g. ‘user_1’ instead of ‘kaching_tenant_user_1’

Yields:

  • (Faraday::Response)

    The response from the server

Returns:

  • (Hash)

    The current saldo



27
28
29
30
31
32
33
# File 'lib/ka_ching/api_v1/saldo.rb', line 27

def current(tenant_account_id:)
  res = get(build_url(tenant_account_id: )) do |req|
    req.headers['Content-Type'] = 'application/json'
  end
  yield res if block_given?
  JSON.parse(res.body)
end