Module: TesoteSdk::Models::FromHash
- Included in:
- Account, AccountData, AccountList, Bank, BatchApproveResult, BatchCancelResult, BatchCreateResult, BatchSubmitResult, BatchSummary, BulkAccountResult, BulkResult, Counterparty, Destination, Fee, LatestAttempt, LegalEntity, OffsetPage, Pagination, PaymentMethod, SearchResult, SourceAccount, StatusResult, SyncRemoval, SyncResult, SyncSession, SyncSessionError, SyncSessionPerformance, SyncStartResult, SyncTransaction, TesoteAccountRef, TesoteTransactionRef, Transaction, TransactionCategory, TransactionData, TransactionList, TransactionOrder, Whoami
- Defined in:
- lib/tesote_sdk/models.rb
Overview
rubocop:disable Metrics/ModuleLength
Instance Method Summary collapse
-
#build_field(_key, value) ⇒ Object
Override in subclasses that wrap nested objects.
- #from_array(arr) ⇒ Object
-
#from_hash(hash) ⇒ Object
why: API may grow new fields between SDK releases — drop unknown keys silently rather than crash.
Instance Method Details
#build_field(_key, value) ⇒ Object
Override in subclasses that wrap nested objects.
32 33 34 |
# File 'lib/tesote_sdk/models.rb', line 32 def build_field(_key, value) value end |
#from_array(arr) ⇒ Object
25 26 27 28 29 |
# File 'lib/tesote_sdk/models.rb', line 25 def from_array(arr) return [] if arr.nil? arr.map { |h| from_hash(h) } end |
#from_hash(hash) ⇒ Object
why: API may grow new fields between SDK releases — drop unknown keys silently rather than crash. Clients can still get raw via response_body.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/tesote_sdk/models.rb', line 12 def from_hash(hash) return nil if hash.nil? return hash if hash.is_a?(self) hash = hash.transform_keys(&:to_s) if hash.is_a?(Hash) known = members.map(&:to_s) attrs = {} known.each do |key| attrs[key.to_sym] = build_field(key, hash[key]) end new(**attrs) end |