Class: Nova::API::Base
Direct Known Subclasses
Resource::Apportionment, Resource::ApportionmentValue, Resource::Bill, Resource::Company, Resource::CurrentAsset, Resource::DirectBill, Resource::FinancialAccount, Resource::Installment, 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
104
105
106
|
# File 'lib/nova/api/base.rb', line 104
def self.
{ 'Persistent-Token': configuration.api_key }.dup
end
|
.base_url ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/nova/api/base.rb', line 19
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
|
.configuration ⇒ Object
109
110
111
|
# File 'lib/nova/api/base.rb', line 109
def self.configuration
Nova::API.configuration
end
|
.do_get(endpoint, query, object = self) ⇒ Object
39
40
41
42
43
|
# File 'lib/nova/api/base.rb', line 39
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
33
34
35
36
37
|
# File 'lib/nova/api/base.rb', line 33
def self.do_get_search(endpoint, query, object = self)
response = perform_get(endpoint, query, )
Nova::API::ListResponse.build(response, object)
end
|
.endpoint ⇒ Object
15
16
17
|
# File 'lib/nova/api/base.rb', line 15
def self.endpoint
raise EndpointNotConfiguredError, 'Each class must implement its own endpoint'
end
|
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/nova/api/base.rb', line 91
def self.perform_get(endpoint, query, = {})
set_base_uri
Kernel.p "[NOVA-API] Issuing GET to #{base_uri}#{endpoint}, headers: #{.merge()}" if configuration.debug?
response =
if query
self.get(endpoint, query: query, headers: .merge())
else
self.get(endpoint, headers: .merge())
end
end
|
.set_base_uri ⇒ Object
114
115
116
117
118
119
120
121
122
|
# File 'lib/nova/api/base.rb', line 114
def self.set_base_uri
if configuration.debug?
debug_output $stdout
Kernel.p "[NOVA-API] Changing base URI from #{base_uri} to #{base_url}"
end
default_options[:base_uri] = base_url
end
|
Instance Method Details
#endpoint ⇒ Object
27
28
29
|
# File 'lib/nova/api/base.rb', line 27
def endpoint
raise EndpointNotConfiguredError, 'Each class must implement its own endpoint'
end
|