Class: TesoteSdk::V2::Transactions
- Inherits:
-
Object
- Object
- TesoteSdk::V2::Transactions
- 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
-
#bulk(account_ids:, page: nil, per_page: nil, limit: nil, offset: nil, opts: {}) ⇒ Object
POST /v2/transactions/bulk.
-
#each_page_for_account(account_id, query = {}, opts: {}, &block) ⇒ Object
Cursor pagination over list_for_account; yields TransactionList pages.
-
#export(account_id, query = {}, opts: {}) ⇒ Object
GET /v2/accounts/id/transactions/export Returns a Transport::RawResponse (file body, Content-Type, filename).
-
#get(id, opts: {}) ⇒ Object
GET /v2/transactions/id.
-
#initialize(transport) ⇒ Transactions
constructor
A new instance of Transactions.
-
#list_for_account(account_id, query = {}, opts: {}) ⇒ Object
GET /v2/accounts/id/transactions.
-
#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.).
-
#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.
-
#sync_legacy(count: nil, cursor: nil, options: nil, opts: {}) ⇒ Object
POST /v2/transactions/sync (legacy, non-nested).
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
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 account_ids.nil? || account_ids.empty? payload = { account_ids: 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 each_page_for_account(account_id, query = {}, opts: {}, &block) return enum_for(:each_page_for_account, account_id, query, opts: opts) unless block enum = Pagination::CursorEnumerator.new(start_query: query) do |q| list_for_account(account_id, 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).
40 41 42 43 44 |
# File 'lib/tesote_sdk/v2/transactions.rb', line 40 def export(account_id, query = {}, opts: {}) raise ArgumentError, 'account_id is required' if account_id.nil? || account_id.to_s.empty? @transport.request_raw('GET', "accounts/#{account_id}/transactions/export", query: query, opts: opts) end |
#get(id, opts: {}) ⇒ Object
GET /v2/transactions/id
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
20 21 22 23 24 25 26 |
# File 'lib/tesote_sdk/v2/transactions.rb', line 20 def list_for_account(account_id, query = {}, opts: {}) raise ArgumentError, 'account_id is required' if account_id.nil? || account_id.to_s.empty? merged = opts.key?(:cache) ? opts : opts.merge(cache: { ttl: INDEX_CACHE_TTL }) body = @transport.request('GET', "accounts/#{account_id}/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.
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.
48 49 50 51 52 53 54 |
# File 'lib/tesote_sdk/v2/transactions.rb', line 48 def sync(account_id, count: nil, cursor: nil, options: nil, opts: {}) raise ArgumentError, 'account_id is required' if account_id.nil? || account_id.to_s.empty? payload = build_sync_payload(count: count, cursor: cursor, options: ) body = @transport.request('POST', "accounts/#{account_id}/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: ) body = @transport.request('POST', 'transactions/sync', body: payload, opts: opts) Models::SyncResult.from_hash(body) end |