Class: Nova::API::Base
Direct Known Subclasses
Resource::Apportionment, Resource::ApportionmentValue, Resource::Bill, Resource::Company, Resource::CurrentAsset, Resource::DirectBill, Resource::FinancialAccount, Resource::Installment, Resource::Installment::WriteOffInstallment, Resource::Invoice, Resource::Permission, Resource::ThirdParty, Resource::Webhook, Resource::WriteOff
Constant Summary
collapse
- SCHEME =
'https'
- PRODUCTION_HOST =
'nova.money'
- STAGING_HOST =
'staging.nova.money'
Utils::BaseStruct::DATE_REGEX
Class Method Summary
collapse
Instance Method Summary
collapse
#allowed_attributes, generate_valid_value_for, initialize_empty_model_with_id, value_for_field
Class Method Details
92
93
94
|
# File 'lib/nova/api/base.rb', line 92
def self.
{ 'Persistent-Token': configuration.api_key }.dup
end
|
.base_url ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/nova/api/base.rb', line 15
def self.base_url
raise Nova::API::MissingSubdomainError, 'The subdomain must be informed' if configuration.subdomain.nil? || configuration.subdomain.empty?
host = configuration.use_staging? ? STAGING_HOST : PRODUCTION_HOST
"#{SCHEME}://#{configuration.subdomain}.#{host}"
end
|
.do_get(endpoint, query, object = self) ⇒ Object
36
37
38
39
40
|
# File 'lib/nova/api/base.rb', line 36
def self.do_get(endpoint, query, object = self)
response = perform_get(endpoint, query)
Nova::API::Response.build(response, object)
end
|
.do_get_search(endpoint, query, object = self) ⇒ Object
30
31
32
33
34
|
# File 'lib/nova/api/base.rb', line 30
def self.do_get_search(endpoint, query, object = self)
response = perform_get(endpoint, query)
Nova::API::ListResponse.build(response, object)
end
|
.endpoint ⇒ Object
11
12
13
|
# File 'lib/nova/api/base.rb', line 11
def self.endpoint
raise EndpointNotConfiguredError, 'Each class must implement its own endpoint'
end
|
82
83
84
85
86
87
88
89
90
|
# File 'lib/nova/api/base.rb', line 82
def self.perform_get(endpoint, query, = {})
Kernel.p "[NOVA-API] Issuing GET to #{base_url}#{endpoint}, headers: #{.merge()}" if configuration.debug?
if query
HTTParty.get("#{base_url}#{endpoint}", query: query, headers: .merge(), format: :json)
else
HTTParty.get("#{base_url}#{endpoint}", headers: .merge(), format: :json)
end
end
|
Instance Method Details
#endpoint ⇒ Object
24
25
26
|
# File 'lib/nova/api/base.rb', line 24
def endpoint
raise EndpointNotConfiguredError, 'Each class must implement its own endpoint'
end
|