Class: Ibanity::BaseResource

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/ibanity/api/base_resource.rb

Direct Known Subclasses

Consent::Consent, Consent::ProcessingOperation, IsabelConnect::Account, IsabelConnect::AccountReport, IsabelConnect::Balance, IsabelConnect::BulkPaymentInitiationRequest, IsabelConnect::IntradayTransaction, IsabelConnect::Transaction, PontoConnect::Account, PontoConnect::BulkPayment, PontoConnect::FinancialInstitution, PontoConnect::Integration, PontoConnect::IntegrationAccount, PontoConnect::OnboardingDetails, PontoConnect::Payment, PontoConnect::PaymentActivationRequest, PontoConnect::PaymentRequest, PontoConnect::PendingTransaction, PontoConnect::ReauthorizationRequest, PontoConnect::Sandbox::FinancialInstitutionAccount, PontoConnect::Sandbox::FinancialInstitutionTransaction, PontoConnect::Synchronization, PontoConnect::Transaction, PontoConnect::Usage, Webhooks::PontoConnect::Account::DetailsUpdated, Webhooks::PontoConnect::Account::PendingTransactionsCreated, Webhooks::PontoConnect::Account::PendingTransactionsUpdated, Webhooks::PontoConnect::Account::Reauthorized, Webhooks::PontoConnect::Account::TransactionsCreated, Webhooks::PontoConnect::Account::TransactionsUpdated, Webhooks::PontoConnect::Integration::AccountAdded, Webhooks::PontoConnect::Integration::AccountRevoked, Webhooks::PontoConnect::Integration::Created, Webhooks::PontoConnect::Integration::Revoked, Webhooks::PontoConnect::Organization::Blocked, Webhooks::PontoConnect::Organization::Unblocked, Webhooks::PontoConnect::PaymentRequest::Closed, Webhooks::PontoConnect::Synchronization::Failed, Webhooks::PontoConnect::Synchronization::SucceededWithoutChange, Webhooks::Xs2a::Account::DetailsUpdated, Webhooks::Xs2a::Account::PendingTransactionsCreated, Webhooks::Xs2a::Account::PendingTransactionsUpdated, Webhooks::Xs2a::Account::TransactionsCreated, Webhooks::Xs2a::Account::TransactionsDeleted, Webhooks::Xs2a::Account::TransactionsUpdated, Webhooks::Xs2a::BulkPaymentInitiationRequest::AuthorizationCompleted, Webhooks::Xs2a::BulkPaymentInitiationRequest::StatusUpdated, Webhooks::Xs2a::PaymentInitiationRequest::AuthorizationCompleted, Webhooks::Xs2a::PaymentInitiationRequest::StatusUpdated, Webhooks::Xs2a::PeriodicPaymentInitiationRequest::AuthorizationCompleted, Webhooks::Xs2a::PeriodicPaymentInitiationRequest::StatusUpdated, Webhooks::Xs2a::Synchronization::Failed, Webhooks::Xs2a::Synchronization::SucceededWithoutChange, Xs2a::Account, Xs2a::AccountInformationAccessRequest, Xs2a::AccountInformationAccessRequestAuthorization, Xs2a::BatchSynchronization, Xs2a::BulkPaymentInitiationRequest, Xs2a::BulkPaymentInitiationRequestAuthorization, Xs2a::Customer, Xs2a::CustomerAccessToken, Xs2a::FinancialInstitution, Xs2a::FinancialInstitutionCountry, Xs2a::Holding, Xs2a::PaymentInitiationRequest, Xs2a::PaymentInitiationRequestAuthorization, Xs2a::PendingTransaction, Xs2a::PeriodicPaymentInitiationRequest, Xs2a::PeriodicPaymentInitiationRequestAuthorization, Xs2a::Sandbox::FinancialInstitutionAccount, Xs2a::Sandbox::FinancialInstitutionHolding, Xs2a::Sandbox::FinancialInstitutionTransaction, Xs2a::Sandbox::FinancialInstitutionUser, Xs2a::Synchronization, Xs2a::Transaction, Xs2a::TransactionDeleteRequest

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw, customer_access_token = nil) ⇒ BaseResource

Returns a new instance of BaseResource.



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ibanity/api/base_resource.rb', line 64

def initialize(raw, customer_access_token = nil)
  attributes = prepare_attributes(raw)
  super(attributes)

  relationships = raw["relationships"] || {}
  setup_relationships(relationships, customer_access_token)

  links = raw["links"] || {}
  setup_links(links)

  meta = raw["meta"] || {}
end

Class Method Details

.create_by_uri(uri:, resource_type:, attributes:, customer_access_token: nil, idempotency_key: nil, meta: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/ibanity/api/base_resource.rb', line 3

def self.create_by_uri(uri:, resource_type:, attributes:, customer_access_token: nil, idempotency_key: nil, meta: nil)
  payload = {
    data: {
      type:       resource_type,
      attributes: attributes
    }
  }
  payload[:data][:meta] = meta if meta
  raw_item = Ibanity.client.post(uri: uri, payload: payload, customer_access_token: customer_access_token, idempotency_key: idempotency_key)
  new(raw_item["data"], customer_access_token)
end

.create_file_by_uri(uri:, resource_type:, raw_content:, customer_access_token: nil, idempotency_key: nil, headers: nil) ⇒ Object



59
60
61
62
# File 'lib/ibanity/api/base_resource.rb', line 59

def self.create_file_by_uri(uri:, resource_type:, raw_content:, customer_access_token: nil, idempotency_key: nil, headers: nil)
  raw_item = Ibanity.client.post(uri: uri, payload: raw_content, customer_access_token: customer_access_token, idempotency_key: idempotency_key, json: false, headers: headers)
  new(raw_item["data"], customer_access_token)
end

.destroy_by_uri(uri:, customer_access_token: nil) ⇒ Object



39
40
41
42
# File 'lib/ibanity/api/base_resource.rb', line 39

def self.destroy_by_uri(uri:, customer_access_token: nil)
  raw_item = Ibanity.client.delete(uri: uri, customer_access_token: customer_access_token)
  new(raw_item["data"], customer_access_token)
end

.find_by_uri(uri:, customer_access_token: nil, headers: nil) ⇒ Object



30
31
32
# File 'lib/ibanity/api/base_resource.rb', line 30

def self.find_by_uri(uri:, customer_access_token: nil, headers: nil)
  new(find_raw_by_uri(uri: uri, customer_access_token: customer_access_token, headers: headers), customer_access_token)
end

.find_file_by_uri(uri:, customer_access_token: nil, headers: nil) ⇒ Object



55
56
57
# File 'lib/ibanity/api/base_resource.rb', line 55

def self.find_file_by_uri(uri:, customer_access_token: nil, headers: nil)
  Ibanity.client.get(uri: uri, customer_access_token: customer_access_token, headers: headers)
end

.find_raw_by_uri(uri:, customer_access_token: nil, headers: nil) ⇒ Object



34
35
36
37
# File 'lib/ibanity/api/base_resource.rb', line 34

def self.find_raw_by_uri(uri:, customer_access_token: nil, headers: nil)
  raw_item = Ibanity.client.get(uri: uri, customer_access_token: customer_access_token, headers: headers)
  raw_item["data"]
end

.list_by_uri(uri:, query_params: {}, customer_access_token: nil, headers: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ibanity/api/base_resource.rb', line 15

def self.list_by_uri(uri:, query_params: {}, customer_access_token: nil, headers: nil)
  raw_response = Ibanity.client.get(uri: uri, query_params: query_params, headers: headers, customer_access_token: customer_access_token)
  items        = raw_response["data"].map do |raw_item|
    new(raw_item, customer_access_token)
  end
  Ibanity::Collection.new(
    klass:                  self,
    items:                  items,
    links:                  raw_response["links"],
    paging:                 raw_response.dig("meta", "paging"),
    synchronized_at:        raw_response.dig("meta", "synchronizedAt"),
    latest_synchronization: raw_response.dig("meta", "latestSynchronization"),
  )
end

.update_by_uri(uri:, resource_type:, attributes:, customer_access_token: nil, idempotency_key: nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/ibanity/api/base_resource.rb', line 44

def self.update_by_uri(uri:, resource_type:, attributes:, customer_access_token: nil, idempotency_key: nil)
  payload = {
    data: {
      type: resource_type,
      attributes: attributes
    }
  }
  raw_item = Ibanity.client.patch(uri: uri, payload: payload, customer_access_token: customer_access_token, idempotency_key: idempotency_key)
  new(raw_item["data"])
end

Instance Method Details

#reload!Object



77
78
79
80
81
82
83
84
# File 'lib/ibanity/api/base_resource.rb', line 77

def reload!
  reloaded   = self.class.find_raw_by_uri(uri)
  attributes = prepare_attributes(reloaded)
  attributes.each do |key, value|
    self[key] = value
  end
  self
end