Class: Harvest::API::InvoicePayments
- Inherits:
-
Base
- Object
- Base
- Harvest::API::InvoicePayments
show all
- Defined in:
- lib/harvest/api/invoice_payments.rb
Instance Attribute Summary
Attributes inherited from Base
#credentials
Instance Method Summary
collapse
Methods inherited from Base
api_model, #initialize
Instance Method Details
#all(invoice, query = {}) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/harvest/api/invoice_payments.rb', line 6
def all(invoice, query = {})
response = request(:get, credentials, "/invoices/#{invoice.id}/payments", query: query)
response_parsed = api_model.to_json(response.parsed_response)
if response_parsed['total_pages'].to_i > 1
counter = response_parsed['page'].to_i
while counter <= response_parsed['total_pages'].to_i do
counter += 1
query = { 'page' => counter }
response_page = request(:get, credentials,
"/invoices/#{invoice.id}/payments",
query: query)
invoice_payments = api_model.to_json(response.parsed_response)
response_parsed['invoice_payments']
.concat(invoice_payments['invoice_payments'])
end
end
api_model.parse(response_parsed)
end
|
#create(invoice, invoice_payment) ⇒ Object
29
30
31
32
33
|
# File 'lib/harvest/api/invoice_payments.rb', line 29
def create(invoice, invoice_payment)
invoice_payment = api_model.wrap(invoice_payment)
response = request(:post, credentials, "/invoices/#{invoice.id}/payments", body: invoice_payment.to_json)
find(invoice_payment.id)
end
|
#delete(invoice, invoice_payment) ⇒ Object
35
36
37
38
|
# File 'lib/harvest/api/invoice_payments.rb', line 35
def delete(invoice, invoice_payment)
request(:delete, credentials, "/invoices/#{invoice.id}/payments/#{invoice_payment.id}")
invoice_payment.id
end
|