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
35 36 37 38 39 40 |
# File 'lib/free_agent/resources/estimates.rb', line 35 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
47 48 49 50 |
# File 'lib/free_agent/resources/estimates.rb', line 47 def delete(id:) response = delete_request("estimates/#{id}") response.success? end |
#email(id:, to:, **params) ⇒ Object
52 53 54 55 56 |
# File 'lib/free_agent/resources/estimates.rb', line 52 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
4 5 6 7 |
# File 'lib/free_agent/resources/estimates.rb', line 4 def list(**params) response = get_request("estimates", params: params) Collection.from_response(response, type: Estimate, key: "estimates") end |
#list_for_contact(contact:, **params) ⇒ Object
9 10 11 12 |
# File 'lib/free_agent/resources/estimates.rb', line 9 def list_for_contact(contact:, **params) response = get_request("estimates?contact=#{contact}", params: params) Collection.from_response(response, type: Estimate, key: "estimates") end |
#list_for_invoice(invoice:, **params) ⇒ Object
19 20 21 22 |
# File 'lib/free_agent/resources/estimates.rb', line 19 def list_for_invoice(invoice:, **params) response = get_request("estimates?invoice=#{invoice}", params: params) Collection.from_response(response, type: Estimate, key: "estimates") end |
#list_for_project(project:, **params) ⇒ Object
14 15 16 17 |
# File 'lib/free_agent/resources/estimates.rb', line 14 def list_for_project(project:, **params) response = get_request("estimates?project=#{project}", params: params) Collection.from_response(response, type: Estimate, key: "estimates") end |
#mark_as_approved(id:) ⇒ Object
68 69 70 71 |
# File 'lib/free_agent/resources/estimates.rb', line 68 def mark_as_approved(id:) response = put_request("estimates/#{id}/transitions/mark_as_approved", body: {}) response.success? end |
#mark_as_draft(id:) ⇒ Object
63 64 65 66 |
# File 'lib/free_agent/resources/estimates.rb', line 63 def mark_as_draft(id:) response = put_request("estimaates/#{id}/transitions/mark_as_draft", body: {}) response.success? end |
#mark_as_rejected(id:) ⇒ Object
73 74 75 76 |
# File 'lib/free_agent/resources/estimates.rb', line 73 def mark_as_rejected(id:) response = put_request("estimates/#{id}/transitions/mark_as_rejected", body: {}) response.success? end |
#mark_as_sent(id:) ⇒ Object
58 59 60 61 |
# File 'lib/free_agent/resources/estimates.rb', line 58 def mark_as_sent(id:) response = put_request("estimaates/#{id}/transitions/mark_as_sent", body: {}) response.success? end |
#retrieve(id:) ⇒ Object
24 25 26 27 |
# File 'lib/free_agent/resources/estimates.rb', line 24 def retrieve(id:) response = get_request("estimates/#{id}") Estimate.new(response.body["estimate"]) end |
#retrieve_pdf(id:) ⇒ Object
Returns a Base64-encoded PDF
30 31 32 33 |
# File 'lib/free_agent/resources/estimates.rb', line 30 def retrieve_pdf(id:) response = get_request("estimates/#{id}/pdf") response.body["pdf"]["content"] if response.success? end |