Class: Charging::ServiceAccount

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

Overview

Represents a Charging service account.

Constant Summary collapse

ATTRIBUTES =
[:plan, :name, :uri, :uuid]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes, response, token) ⇒ ServiceAccount

Initializes a service account instance, to represent a charging account



21
22
23
24
25
26
# File 'lib/charging/service_account.rb', line 21

def initialize(attributes, response, token) # :nodoc:
  Helpers.load_variables(self, ATTRIBUTES, attributes)

  @last_response = response
  @application_token = token
end

Instance Attribute Details

#application_tokenObject (readonly)

Responds the current application token



14
15
16
# File 'lib/charging/service_account.rb', line 14

def application_token
  @application_token
end

#last_responseObject (readonly)

Responds the last http response from the API.



11
12
13
# File 'lib/charging/service_account.rb', line 11

def last_response
  @last_response
end

Class Method Details

.currentObject



16
17
18
# File 'lib/charging/service_account.rb', line 16

def self.current
  @current ||= find_by_token(Charging.configuration.application_token)
end

.find_by_token(token) ⇒ Object

Finds a service account by it’s access token. Returns the service account instance with all fields set if successful. If something went wrong, it raises Charging::Http::LastResponseError.

API documentation: charging.financeconnect.com.br/static/docs/accounts_and_domains.html#get-account-entry-point



33
34
35
36
37
38
39
40
41
# File 'lib/charging/service_account.rb', line 33

def self.find_by_token(token)
  response = Http.get('/account/', token)

  raise Http::LastResponseError.new(response) if response.code != 200

  self. response, token
rescue ::RestClient::Exception => exception
  raise Http::LastResponseError.new(exception.response)
end