Class: Charging::Domain
Overview
Represents a Charging domain.
Defined Under Namespace
Classes: Collection
Constant Summary collapse
- READ_ONLY_ATTRIBUTES =
[:token]
- ATTRIBUTES =
[ :supplier_name, :address, :city_state, :zipcode, :national_identifier, :description ]
Constants inherited from Base
Base::COMMON_ATTRIBUTES, Base::DEFAULT_LIMIT, Base::DEFAULT_PAGE
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.find_all(account, page = DEFAULT_PAGE, limit = DEFAULT_LIMIT) ⇒ Object
Finds all domains for a specified account.
-
.find_by_token(token) ⇒ Object
Finds a domain by its authentication token.
-
.find_by_uuid(account, uuid) ⇒ Object
Finds a domain by your uuid.
-
.load_persisted_domain(attributes, response, account = nil) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#create! ⇒ Object
Creates current domain at API.
-
#destroy! ⇒ Object
Destroys current domain at API.
-
#initialize(attributes, account, response = nil) ⇒ Domain
constructor
Initializes a domain instance.
Methods inherited from Base
#attributes, #deleted?, #normalize_etag!, #persisted?, #unpersisted?, validate_attributes!
Constructor Details
#initialize(attributes, account, response = nil) ⇒ Domain
Initializes a domain instance
14 15 16 17 |
# File 'lib/charging/domain.rb', line 14 def initialize(attributes, account, response = nil) super(attributes, response) @account = account end |
Class Method Details
.find_all(account, page = DEFAULT_PAGE, limit = DEFAULT_LIMIT) ⇒ Object
Finds all domains for a specified account. It requites an ServiceAccount instance, and you should pass page
and/or limit
to apply on find.
Returns a Collection (Array-like) of Domain
API method: GET /account/domains/
API documentation: charging.financeconnect.com.br/static/docs/accounts_and_domains.html#get-account-domains-limit-limit-page-page
57 58 59 60 61 62 63 |
# File 'lib/charging/domain.rb', line 57 def self.find_all(account, page = DEFAULT_PAGE, limit = DEFAULT_LIMIT) Helpers.required_arguments!('service account' => account) response = get_account_domains(account, page, limit) Collection.new(account, response) end |
.find_by_token(token) ⇒ Object
Finds a domain by its authentication token. It requites an token
.
Returns a Domain instance or raises a Http::LastResponseError if something went wrong, like unauthorized request, not found.
API method: GET /domain/
API documentation: charging.financeconnect.com.br/static/docs/accounts_and_domains.html#get-subuser-domain
92 93 94 95 96 97 98 99 100 |
# File 'lib/charging/domain.rb', line 92 def self.find_by_token(token) Helpers.required_arguments!('token' => token) response = get_domain(token) raise_last_response_unless 200, response load_persisted_domain(MultiJson.decode(response.body), response) end |
.find_by_uuid(account, uuid) ⇒ Object
Finds a domain by your uuid. It requites an ServiceAccount instance and a String uuid
.
Returns a Domain instance or raises a Http::LastResponseError if something went wrong, like unauthorized request, not found.
API method: GET /account/domains/:uuid/
API documentation: charging.financeconnect.com.br/static/docs/accounts_and_domains.html#get-account-domains-uuid
74 75 76 77 78 79 80 81 82 |
# File 'lib/charging/domain.rb', line 74 def self.find_by_uuid(account, uuid) Helpers.required_arguments!('service account' => account, uuid: uuid) response = get_account_domain(account, uuid) raise_last_response_unless 200, response load_persisted_domain(MultiJson.decode(response.body), response, account) end |
Instance Method Details
#create! ⇒ Object
Creates current domain at API.
API method: POST /account/domains/
API documentation: charging.financeconnect.com.br/static/docs/accounts_and_domains.html#post-account-domains
24 25 26 27 28 29 30 31 32 |
# File 'lib/charging/domain.rb', line 24 def create! super do raise 'can not create without a service account' if invalid_account? Domain.post_account_domains(account.application_token, attributes) end reload_attributes! end |
#destroy! ⇒ Object
Destroys current domain at API.
API method: DELETE /account/domains/:uuid/
API documentation: charging.financeconnect.com.br/static/docs/accounts_and_domains.html#delete-account-domains-uuid
39 40 41 42 43 44 45 46 |
# File 'lib/charging/domain.rb', line 39 def destroy! super do raise 'can not destroy without a service account' if invalid_account? raise 'can not destroy a not persisted domain' unless persisted? Domain.delete_account_domains(self) end end |