Class: FreeAgent::EstimatesResource
- Defined in:
- lib/free_agent/resources/estimates.rb
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
- #create(contact:, dated_on:, currency:, reference:, status: "Draft", estimate_type: "Estimate", **params) ⇒ Object
- #delete(id:) ⇒ Object
- #email(id:, to:, **params) ⇒ Object
- #list(**params) ⇒ Object
- #list_for_contact(contact:, **params) ⇒ Object
- #list_for_invoice(invoice:, **params) ⇒ Object
- #list_for_project(project:, **params) ⇒ Object
- #mark_as_approved(id:) ⇒ Object
- #mark_as_draft(id:) ⇒ Object
- #mark_as_rejected(id:) ⇒ Object
- #mark_as_sent(id:) ⇒ Object
- #retrieve(id:) ⇒ Object
-
#retrieve_pdf(id:) ⇒ Object
Returns a Base64-encoded PDF.
- #update(id:, **params) ⇒ Object
Methods inherited from Resource
Constructor Details
This class inherits a constructor from FreeAgent::Resource
Instance Method Details
#create(contact:, dated_on:, currency:, reference:, status: "Draft", estimate_type: "Estimate", **params) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/free_agent/resources/estimates.rb', line 34 def create(contact:, dated_on:, currency:, reference:, status: "Draft", estimate_type: "Estimate", **params) attributes = { contact: contact, dated_on: dated_on, status: status, estimate_type: estimate_type, currency: currency, reference: reference } response = post_request("estimates", body: { estimate: attributes.merge(params) }) Estimate.new(response.body["estimate"]) if response.success? end |
#delete(id:) ⇒ Object
46 47 48 49 |
# File 'lib/free_agent/resources/estimates.rb', line 46 def delete(id:) response = delete_request("estimates/#{id}") response.success? end |
#email(id:, to:, **params) ⇒ Object
51 52 53 54 55 |
# File 'lib/free_agent/resources/estimates.rb', line 51 def email(id:, to:, **params) attributes = { to: to } response = post_request("estimates/#{id}/send_email", body: { estimate: { email: attributes.merge(params) } }) response.success? end |
#list(**params) ⇒ Object
3 4 5 6 |
# File 'lib/free_agent/resources/estimates.rb', line 3 def list(**params) response = get_request("estimates", params: params) Collection.from_response(response, type: Estimate) end |
#list_for_contact(contact:, **params) ⇒ Object
8 9 10 11 |
# File 'lib/free_agent/resources/estimates.rb', line 8 def list_for_contact(contact:, **params) response = get_request("estimates?contact=#{contact}", params: params) Collection.from_response(response, type: Estimate) end |
#list_for_invoice(invoice:, **params) ⇒ Object
18 19 20 21 |
# File 'lib/free_agent/resources/estimates.rb', line 18 def list_for_invoice(invoice:, **params) response = get_request("estimates?invoice=#{invoice}", params: params) Collection.from_response(response, type: Estimate) end |
#list_for_project(project:, **params) ⇒ Object
13 14 15 16 |
# File 'lib/free_agent/resources/estimates.rb', line 13 def list_for_project(project:, **params) response = get_request("estimates?project=#{project}", params: params) Collection.from_response(response, type: Estimate) end |
#mark_as_approved(id:) ⇒ Object
67 68 69 70 |
# File 'lib/free_agent/resources/estimates.rb', line 67 def mark_as_approved(id:) response = put_request("estimates/#{id}/transitions/mark_as_approved", body: {}) response.success? end |
#mark_as_draft(id:) ⇒ Object
62 63 64 65 |
# File 'lib/free_agent/resources/estimates.rb', line 62 def mark_as_draft(id:) response = put_request("estimaates/#{id}/transitions/mark_as_draft", body: {}) response.success? end |
#mark_as_rejected(id:) ⇒ Object
72 73 74 75 |
# File 'lib/free_agent/resources/estimates.rb', line 72 def mark_as_rejected(id:) response = put_request("estimates/#{id}/transitions/mark_as_rejected", body: {}) response.success? end |
#mark_as_sent(id:) ⇒ Object
57 58 59 60 |
# File 'lib/free_agent/resources/estimates.rb', line 57 def mark_as_sent(id:) response = put_request("estimaates/#{id}/transitions/mark_as_sent", body: {}) response.success? end |
#retrieve(id:) ⇒ Object
23 24 25 26 |
# File 'lib/free_agent/resources/estimates.rb', line 23 def retrieve(id:) response = get_request("estimates/#{id}") Estimate.new(response.body["estimate"]) end |
#retrieve_pdf(id:) ⇒ Object
Returns a Base64-encoded PDF
29 30 31 32 |
# File 'lib/free_agent/resources/estimates.rb', line 29 def retrieve_pdf(id:) response = get_request("estimates/#{id}/pdf") response.body["pdf"]["content"] if response.success? end |
#update(id:, **params) ⇒ Object
41 42 43 44 |
# File 'lib/free_agent/resources/estimates.rb', line 41 def update(id:, **params) response = put_request("estimates/#{id}", body: params) Estimate.new(response.body["estimate"]) if response.success? end |