Class: Harvest::API::InvoiceMessages

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

Instance Attribute Summary

Attributes inherited from Base

#credentials

Instance Method Summary collapse

Methods included from Behavior::Crud

#update

Methods inherited from Base

api_model, #initialize

Constructor Details

This class inherits a constructor from Harvest::API::Base

Instance Method Details

#all(invoice) ⇒ Object


7
8
9
10
# File 'lib/harvest/api/invoice_messages.rb', line 7

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

#create(message) ⇒ Object


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

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

#delete(message) ⇒ Object


24
25
26
27
# File 'lib/harvest/api/invoice_messages.rb', line 24

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

#find(invoice, message) ⇒ Object


12
13
14
15
# File 'lib/harvest/api/invoice_messages.rb', line 12

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

#mark_as_closed(message) ⇒ Harvest::InvoiceMessage

Create a message and mark an open invoice as closed (writing an invoice off)

Parameters:

Returns:


41
42
43
# File 'lib/harvest/api/invoice_messages.rb', line 41

def mark_as_closed(message)
  send_status_message(message, 'mark_as_closed')
end

#mark_as_draft(message) ⇒ Harvest::InvoiceMessage

Create a message for marking an open invoice as draft

Parameters:

Returns:


57
58
59
# File 'lib/harvest/api/invoice_messages.rb', line 57

def mark_as_draft(message)
  send_status_message(message, 'mark_as_draft')
end

#mark_as_sent(message) ⇒ Harvest::InvoiceMessage

Create a message for marking an invoice as sent.

Parameters:

Returns:


33
34
35
# File 'lib/harvest/api/invoice_messages.rb', line 33

def mark_as_sent(message)
  send_status_message(message, 'mark_as_sent')
end

#re_open(message) ⇒ Harvest::InvoiceMessage

Create a message and mark a closed (written-off) invoice as open

Parameters:

Returns:


49
50
51
# File 'lib/harvest/api/invoice_messages.rb', line 49

def re_open(message)
  send_status_message(message, 're_open')
end