Module: Moneybird::Traits::Save
- Included in:
- Service::Contact, Service::Document::GeneralDocument, Service::Document::GeneralJournalDocument, Service::Document::PurchaseInvoice, Service::Document::Receipt, Service::Document::TypelessDocument, Service::Estimate, Service::Identity, Service::LedgerAccount, Service::Product, Service::PurchaseInvoice, Service::RecurringSalesInvoice, Service::SalesInvoice, Service::Webhook
- Defined in:
- lib/moneybird/traits/save.rb
Instance Method Summary collapse
- #create(attributes) ⇒ Object (also: #update)
- #resource_path(resource) ⇒ Object
- #save(resource) ⇒ Object
Instance Method Details
#create(attributes) ⇒ Object Also known as: update
19 20 21 22 23 |
# File 'lib/moneybird/traits/save.rb', line 19 def create(attributes) build(attributes).tap do |resource| save(resource) end end |
#resource_path(resource) ⇒ Object
4 5 6 |
# File 'lib/moneybird/traits/save.rb', line 4 def resource_path(resource) [path, resource.path].join('') end |
#save(resource) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/moneybird/traits/save.rb', line 8 def save(resource) response = if resource.persisted? client.patch(resource_path(resource), resource.to_json) else client.post(resource_path(resource), resource.to_json) end resource.attributes = response resource end |