Class: Charging::ChargeAccount
- Defined in:
- lib/charging/charge_account.rb
Defined Under Namespace
Classes: Collection
Constant Summary collapse
- DEFAULT_PAGE =
1
- DEFAULT_LIMIT =
10
- READ_ONLY_ATTRIBUTES =
[:national_identifier]
- ATTRIBUTES =
[ :account, :agency, :name, :portfolio_code, :address, :zipcode, :sequence_numbers, :currency, :agreement_code, :supplier_name, :advance_days, :bank, :our_number_range, :default_charging_features, :city_state ]
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.find_all(domain, page = DEFAULT_PAGE, limit = DEFAULT_LIMIT) ⇒ Object
Finds all charge accounts for a domain.
-
.find_by_uri(domain, uri) ⇒ Object
Finds a charge account by uri.
-
.find_by_uuid(domain, uuid) ⇒ Object
Finds a charge account by uuid.
- .load_persisted_charge_account(attributes, response, domain) ⇒ Object
Instance Method Summary collapse
-
#create! ⇒ Object
Creates current charge account at API.
-
#destroy! ⇒ Object
Deletes the charge account at API.
-
#initialize(attributes, domain, response = nil) ⇒ ChargeAccount
constructor
A new instance of ChargeAccount.
-
#update_attribute!(attribute, value, should_reload_attributes = true) ⇒ Object
Update an attribute on charge account at API.
-
#update_attributes!(attributes_values) ⇒ Object
Update all attributes at charge_account.
Methods inherited from Base
#attributes, #deleted?, #normalize_etag!, #persisted?, #unpersisted?, validate_attributes!
Constructor Details
#initialize(attributes, domain, response = nil) ⇒ ChargeAccount
Returns a new instance of ChargeAccount.
20 21 22 23 |
# File 'lib/charging/charge_account.rb', line 20 def initialize(attributes, domain, response = nil) super(attributes, response) @domain = domain end |
Class Method Details
.find_all(domain, page = DEFAULT_PAGE, limit = DEFAULT_LIMIT) ⇒ Object
Finds all charge accounts for a domain. It requites an domain
, and you should pass page
and/or limit
to apply on find.
Returns a Collection (Array-like) of ChargeAccount
API method: GET /charge-accounts/?page=:page&limit=:limit
API documentation: charging.financeconnect.com.br/static/docs/charges.html#get-charge-accounts-limit-limit-page-page
103 104 105 106 107 108 109 |
# File 'lib/charging/charge_account.rb', line 103 def self.find_all(domain, page = DEFAULT_PAGE, limit = DEFAULT_LIMIT) Helpers.required_arguments!(domain: domain) response = get_charge_accounts(domain, page, limit) Collection.new(domain, response) end |
.find_by_uri(domain, uri) ⇒ Object
Finds a charge account by uri. It requites an domain
and a String
.
Returns a ChargeAccount instance or raises a Http::LastResponseError if something went wrong, like unauthorized request, not found.
116 117 118 119 120 121 122 123 124 |
# File 'lib/charging/charge_account.rb', line 116 def self.find_by_uri(domain, uri) Helpers.required_arguments!(domain: domain, uri: uri) response = Http.get(uri, domain.token) raise_last_response_unless 200, response ChargeAccount.load_persisted_charge_account(MultiJson.decode(response.body), response, domain) end |
.find_by_uuid(domain, uuid) ⇒ Object
Finds a charge account by uuid. It requites an domain
and a uuid
.
Returns a ChargeAccount instance or raises a Http::LastResponseError if something went wrong, like unauthorized request, not found.
API method: GET /charge-accounts/:uuid/
API documentation: charging.financeconnect.com.br/static/docs/charges.html#get-charge-accounts-uuid
85 86 87 88 89 90 91 92 93 |
# File 'lib/charging/charge_account.rb', line 85 def self.find_by_uuid(domain, uuid) Helpers.required_arguments!(domain: domain, uuid: uuid) response = ChargeAccount.get_charge_account(domain, uuid) raise_last_response_unless 200, response load_persisted_charge_account(MultiJson.decode(response.body), response, domain) end |
.load_persisted_charge_account(attributes, response, domain) ⇒ Object
126 127 128 129 |
# File 'lib/charging/charge_account.rb', line 126 def self.load_persisted_charge_account(attributes, response, domain) validate_attributes!(attributes) ChargeAccount.new(attributes, domain, response) end |
Instance Method Details
#create! ⇒ Object
Creates current charge account at API.
API method: POST /account/domains/
API documentation: charging.financeconnect.com.br/static/docs/accounts_and_domains.html#post-account-domains
30 31 32 33 34 35 36 37 38 |
# File 'lib/charging/charge_account.rb', line 30 def create! super do raise 'can not create without a domain' if invalid_domain? ChargeAccount.post_charge_accounts(domain, attributes) end reload_attributes! end |
#destroy! ⇒ Object
Deletes the charge account at API
API method: DELETE /charge-accounts/:uuid/
API documentation: charging.financeconnect.com.br/static/docs/charges.html#delete-charge-accounts-uuid
45 46 47 48 49 |
# File 'lib/charging/charge_account.rb', line 45 def destroy! super do Http.delete("/charge-accounts/#{uuid}/", domain.token, etag) end end |
#update_attribute!(attribute, value, should_reload_attributes = true) ⇒ Object
Update an attribute on charge account at API.
API method: PATCH /charge-accounts/:uuid/
API documentation: charging.financeconnect.com.br/static/docs/charges.html#patch-charge-accounts-uuid
56 57 58 59 60 61 62 |
# File 'lib/charging/charge_account.rb', line 56 def update_attribute!(attribute, value, should_reload_attributes = true) execute_and_capture_raises_at_errors(204) do @last_response = Http.patch("/charge-accounts/#{uuid}/", domain.token, etag, attribute => value) end reload_attributes! if should_reload_attributes end |
#update_attributes!(attributes_values) ⇒ Object
Update all attributes at charge_account. This method uses update_attribute!
recurring for each attrubute. attrubutes_valies
should be a hash with attribute and value to be updated.
68 69 70 71 72 73 74 |
# File 'lib/charging/charge_account.rb', line 68 def update_attributes!(attributes_values) attributes_values.each do |attribute, value| update_attribute! attribute, value, false end ensure reload_attributes! end |