Class: Charging::Domain

Inherits:
Base
  • Object
show all
Defined in:
lib/charging/domain.rb

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

#errors, #last_response

Class Method Summary collapse

Instance Method Summary collapse

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, , response = nil)
  super(attributes, response)
  @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(, page = DEFAULT_PAGE, limit = DEFAULT_LIMIT)
  Helpers.required_arguments!('service account' => )

  response = (, page, limit)

  Collection.new(, 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(, uuid)
  Helpers.required_arguments!('service account' => , uuid: uuid)

  response = (, uuid)

  raise_last_response_unless 200, response

  load_persisted_domain(MultiJson.decode(response.body), response, )
end

.load_persisted_domain(attributes, response, account = nil) ⇒ Object

:nodoc:


102
103
104
105
# File 'lib/charging/domain.rb', line 102

def self.load_persisted_domain(attributes, response,  = nil) # :nodoc:
  validate_attributes!(attributes)
  Domain.new(attributes, , response)
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.(.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.(self)
  end
end