Class: PapierkramApi::V1::Endpoints::Base
- Inherits:
-
Object
- Object
- PapierkramApi::V1::Endpoints::Base
show all
- Defined in:
- lib/papierkram_api/v1/endpoints/base.rb
Overview
This class is the base class for all the API calls.
Direct Known Subclasses
PapierkramApi::V1::Endpoints::Banking::BankConnections, PapierkramApi::V1::Endpoints::Banking::Transactions, Contact::Companies, Contact::CompaniesPersons, Expense::Vouchers, Income::Estimates, Income::Invoices, Income::PaymentTerms, Income::Propositions, Info, Projects, Tracker::Tasks, Tracker::TimeEntries
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#http_delete(url, params = {}, headers = {}) ⇒ Object
-
#http_get(url, params = {}, headers = {}) ⇒ Object
-
#http_patch(url, params = {}, headers = {}) ⇒ Object
-
#http_post(url, params = {}, headers = {}) ⇒ Object
-
#http_put(url, params = {}, headers = {}) ⇒ Object
-
#initialize(client) ⇒ Base
constructor
-
#remaining_quota(response) ⇒ Object
Constructor Details
#initialize(client) ⇒ Base
Returns a new instance of Base.
10
11
12
13
|
# File 'lib/papierkram_api/v1/endpoints/base.rb', line 10
def initialize(client)
@client = client
@url_api_path = '/api/v1'
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
8
9
10
|
# File 'lib/papierkram_api/v1/endpoints/base.rb', line 8
def client
@client
end
|
#url_api_path ⇒ Object
Returns the value of attribute url_api_path.
8
9
10
|
# File 'lib/papierkram_api/v1/endpoints/base.rb', line 8
def url_api_path
@url_api_path
end
|
Instance Method Details
#http_delete(url, params = {}, headers = {}) ⇒ Object
42
43
44
|
# File 'lib/papierkram_api/v1/endpoints/base.rb', line 42
def http_delete(url, params = {}, = {})
call_wrapper!(:delete, url, params, )
end
|
#http_get(url, params = {}, headers = {}) ⇒ Object
25
26
27
28
|
# File 'lib/papierkram_api/v1/endpoints/base.rb', line 25
def http_get(url, params = {}, = {})
validate_get!(params)
call_wrapper!(:get, url, params, )
end
|
#http_patch(url, params = {}, headers = {}) ⇒ Object
38
39
40
|
# File 'lib/papierkram_api/v1/endpoints/base.rb', line 38
def http_patch(url, params = {}, = {})
call_wrapper!(:patch, url, params, )
end
|
#http_post(url, params = {}, headers = {}) ⇒ Object
30
31
32
|
# File 'lib/papierkram_api/v1/endpoints/base.rb', line 30
def http_post(url, params = {}, = {})
call_wrapper!(:post, url, params, )
end
|
#http_put(url, params = {}, headers = {}) ⇒ Object
34
35
36
|
# File 'lib/papierkram_api/v1/endpoints/base.rb', line 34
def http_put(url, params = {}, = {})
call_wrapper!(:put, url, params, )
end
|
#remaining_quota(response) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/papierkram_api/v1/endpoints/base.rb', line 15
def remaining_quota(response)
return response.['x-remaining-quota'].to_i if response.is_a?(Faraday::Response)
raise ArgumentError, 'Invalid response object' unless response.is_a?(Hash)
quota = response.dig('headers', 'x-remaining-quota') || response['x-remaining-quota']
return Integer(quota) if quota
raise ArgumentError, "No remaining quota found in response: #{response}"
end
|