Class: Harvest::API::InvoicePayments

Inherits:
Base
  • Object
show all
Includes:
Behavior::Crud
Defined in:
lib/forecast/api/invoice_payments.rb

Instance Method Summary collapse

Instance Method Details

#all(invoice) ⇒ Object



7
8
9
10
# File 'lib/forecast/api/invoice_payments.rb', line 7

def all(invoice)
  response = request(:get, credentials, "/invoices/#{invoice.to_i}/payments")
  api_model.parse(response.parsed_response)
end

#create(payment) ⇒ Object



17
18
19
20
21
22
# File 'lib/forecast/api/invoice_payments.rb', line 17

def create(payment)
  payment = api_model.wrap(payment)
  response = request(:post, credentials, "/invoices/#{payment.invoice_id}/payments", :body => payment.to_json)
  id = response.headers["location"].match(/\/.*\/(\d+)\/.*\/(\d+)/)[2]
  find(payment.invoice_id, id)
end

#delete(payment) ⇒ Object



24
25
26
27
# File 'lib/forecast/api/invoice_payments.rb', line 24

def delete(payment)
  request(:delete, credentials, "/invoices/#{payment.invoice_id}/payments/#{payment.to_i}")
  payment.id
end

#find(invoice, payment) ⇒ Object



12
13
14
15
# File 'lib/forecast/api/invoice_payments.rb', line 12

def find(invoice, payment)
  response = request(:get, credentials, "/invoices/#{invoice.to_i}/payments/#{payment.to_i}")
  api_model.parse(response.parsed_response).first
end