Class: TesoteSdk::V1::Accounts

Inherits:
Object
  • Object
show all
Defined in:
lib/tesote_sdk/v1/accounts.rb

Constant Summary collapse

INDEX_CACHE_TTL =

1 minute ETag (spec)

60
SHOW_CACHE_TTL =

5 minutes ETag (spec)

300

Instance Method Summary collapse

Constructor Details

#initialize(transport) ⇒ Accounts

Returns a new instance of Accounts.



7
8
9
# File 'lib/tesote_sdk/v1/accounts.rb', line 7

def initialize(transport)
  @transport = transport
end

Instance Method Details

#each_transaction_page(account_id, query = {}, opts: {}, &block) ⇒ Object

Enumerate all transactions across pages (cursor-based). Yields TransactionList page objects.



35
36
37
38
39
40
41
42
# File 'lib/tesote_sdk/v1/accounts.rb', line 35

def each_transaction_page(, query = {}, opts: {}, &block)
  return enum_for(:each_transaction_page, , query, opts: opts) unless block

  enum = Pagination::CursorEnumerator.new(start_query: query) do |q|
    list_transactions(, q, opts: opts)
  end
  enum.each(&block)
end

#get(id, opts: {}) ⇒ Object

GET /v1/accounts/id

Raises:

  • (ArgumentError)


18
19
20
21
22
23
# File 'lib/tesote_sdk/v1/accounts.rb', line 18

def get(id, opts: {})
  raise ArgumentError, 'id is required' if id.nil? || id.to_s.empty?

  body = @transport.request('GET', "accounts/#{id}", opts: with_cache(opts, SHOW_CACHE_TTL))
  Models::Account.from_hash(body)
end

#list(query = {}, opts: {}) ⇒ Object

GET /v1/accounts



12
13
14
15
# File 'lib/tesote_sdk/v1/accounts.rb', line 12

def list(query = {}, opts: {})
  body = @transport.request('GET', 'accounts', query: query, opts: with_cache(opts, INDEX_CACHE_TTL))
  Models::AccountList.from_hash(body)
end

#list_transactions(account_id, query = {}, opts: {}) ⇒ Object

GET /v1/accounts/id/transactions

Raises:

  • (ArgumentError)


26
27
28
29
30
31
# File 'lib/tesote_sdk/v1/accounts.rb', line 26

def list_transactions(, query = {}, opts: {})
  raise ArgumentError, 'account_id is required' if .nil? || .to_s.empty?

  body = @transport.request('GET', "accounts/#{}/transactions", query: query, opts: opts)
  Models::TransactionList.from_hash(body)
end