Class: TesoteSdk::V2::Transactions

Inherits:
Object
  • Object
show all
Defined in:
lib/tesote_sdk/v2/transactions.rb

Overview

Wraps:

  • GET /v2/accounts/id/transactions

  • GET /v2/accounts/id/transactions/export

  • POST /v2/accounts/id/transactions/sync

  • POST /v2/transactions/sync (legacy)

  • GET /v2/transactions/id

  • POST /v2/transactions/bulk

  • GET /v2/transactions/search

Constant Summary collapse

INDEX_CACHE_TTL =
60
SHOW_CACHE_TTL =
300

Instance Method Summary collapse

Constructor Details

#initialize(transport) ⇒ Transactions

Returns a new instance of Transactions.



15
16
17
# File 'lib/tesote_sdk/v2/transactions.rb', line 15

def initialize(transport)
  @transport = transport
end

Instance Method Details

#bulk(account_ids:, page: nil, per_page: nil, limit: nil, offset: nil, opts: {}) ⇒ Object

POST /v2/transactions/bulk

Raises:

  • (ArgumentError)


73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/tesote_sdk/v2/transactions.rb', line 73

def bulk(account_ids:, page: nil, per_page: nil, limit: nil, offset: nil, opts: {})
  raise ArgumentError, 'account_ids is required and must not be empty' if .nil? || .empty?

  payload = {
    account_ids: ,
    page: page,
    per_page: per_page,
    limit: limit,
    offset: offset
  }.compact
  body = @transport.request('POST', 'transactions/bulk', body: payload, opts: opts)
  Models::BulkResult.from_hash(body)
end

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

Cursor pagination over list_for_account; yields TransactionList pages.



29
30
31
32
33
34
35
36
# File 'lib/tesote_sdk/v2/transactions.rb', line 29

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

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

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

GET /v2/accounts/id/transactions/export Returns a Transport::RawResponse (file body, Content-Type, filename).

Raises:

  • (ArgumentError)


40
41
42
43
44
# File 'lib/tesote_sdk/v2/transactions.rb', line 40

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

  @transport.request_raw('GET', "accounts/#{}/transactions/export", query: query, opts: opts)
end

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

GET /v2/transactions/id

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
# File 'lib/tesote_sdk/v2/transactions.rb', line 64

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

  merged = opts.key?(:cache) ? opts : opts.merge(cache: { ttl: SHOW_CACHE_TTL })
  body = @transport.request('GET', "transactions/#{id}", opts: merged)
  Models::Transaction.from_hash(body)
end

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

GET /v2/accounts/id/transactions

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
# File 'lib/tesote_sdk/v2/transactions.rb', line 20

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

  merged = opts.key?(:cache) ? opts : opts.merge(cache: { ttl: INDEX_CACHE_TTL })
  body = @transport.request('GET', "accounts/#{}/transactions", query: query, opts: merged)
  Models::TransactionList.from_hash(body)
end

#search(opts: {}, **filters) ⇒ Object

GET /v2/transactions/search Pass ‘q:` (required) plus any optional filters as keyword args (account_id, limit, offset, status, type, start_date, etc.). `opts:` is the transport options hash.

Raises:

  • (ArgumentError)


91
92
93
94
95
96
97
98
# File 'lib/tesote_sdk/v2/transactions.rb', line 91

def search(opts: {}, **filters)
  filters = filters.transform_keys(&:to_sym)
  q_value = filters[:q]
  raise ArgumentError, 'q is required' if q_value.nil? || q_value.to_s.empty?

  body = @transport.request('GET', 'transactions/search', query: filters.compact, opts: opts)
  Models::SearchResult.from_hash(body)
end

#sync(account_id, count: nil, cursor: nil, options: nil, opts: {}) ⇒ Object

POST /v2/accounts/id/transactions/sync body: { count:, cursor:, options: } — all optional per spec.

Raises:

  • (ArgumentError)


48
49
50
51
52
53
54
# File 'lib/tesote_sdk/v2/transactions.rb', line 48

def sync(, count: nil, cursor: nil, options: nil, opts: {})
  raise ArgumentError, 'account_id is required' if .nil? || .to_s.empty?

  payload = build_sync_payload(count: count, cursor: cursor, options: options)
  body = @transport.request('POST', "accounts/#{}/transactions/sync", body: payload, opts: opts)
  Models::SyncResult.from_hash(body)
end

#sync_legacy(count: nil, cursor: nil, options: nil, opts: {}) ⇒ Object

POST /v2/transactions/sync (legacy, non-nested)



57
58
59
60
61
# File 'lib/tesote_sdk/v2/transactions.rb', line 57

def sync_legacy(count: nil, cursor: nil, options: nil, opts: {})
  payload = build_sync_payload(count: count, cursor: cursor, options: options)
  body = @transport.request('POST', 'transactions/sync', body: payload, opts: opts)
  Models::SyncResult.from_hash(body)
end