Class: FreeAgent::BillsResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/free_agent/resources/bills.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from FreeAgent::Resource

Instance Method Details

#create(contact:, dated_on:, due_on:, reference:, bill_items:, **params) ⇒ Object



24
25
26
27
28
29
# File 'lib/free_agent/resources/bills.rb', line 24

def create(contact:, dated_on:, due_on:, reference:, bill_items:, **params)
  attributes = {contact: contact, dated_on: dated_on, due_on: due_on, reference: reference, bill_items: bill_items}

  response = post_request("bills", body: {bill: attributes.merge(params)})
  Bill.new(response.body["bill"]) if response.success?
end

#delete(id:) ⇒ Object



36
37
38
39
# File 'lib/free_agent/resources/bills.rb', line 36

def delete(id:)
  response = delete_request("bills/#{id}")
  response.success?
end

#list(**params) ⇒ Object



4
5
6
7
# File 'lib/free_agent/resources/bills.rb', line 4

def list(**params)
  response = get_request("bills", params: params)
  Collection.from_response(response, type: Bill, key: "bills")
end

#list_for_contact(contact:, **params) ⇒ Object



9
10
11
12
# File 'lib/free_agent/resources/bills.rb', line 9

def list_for_contact(contact:, **params)
  response = get_request("bills?contact=#{contact}", params: params)
  Collection.from_response(response, type: Bill, key: "bills")
end

#list_for_project(project:, **params) ⇒ Object



14
15
16
17
# File 'lib/free_agent/resources/bills.rb', line 14

def list_for_project(project:, **params)
  response = get_request("bills?project=#{project}", params: params)
  Collection.from_response(response, type: Bill, key: "bills")
end

#retrieve(id:) ⇒ Object



19
20
21
22
# File 'lib/free_agent/resources/bills.rb', line 19

def retrieve(id:)
  response = get_request("bills/#{id}")
  Bill.new(response.body["bill"])
end

#update(id:, **params) ⇒ Object



31
32
33
34
# File 'lib/free_agent/resources/bills.rb', line 31

def update(id:, **params)
  response = put_request("bills/#{id}", body: {bill: params})
  Bill.new(response.body["bill"]) if response.success?
end