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::ExternalSalesInvoice, Service::Identity, Service::LedgerAccount, Service::Payment, Service::Product, Service::RecurringSalesInvoice, Service::SalesInvoice, Service::Webhook
- Defined in:
- lib/moneybird/traits/save.rb
Instance Method Summary collapse
- #create(attributes) ⇒ Object (also: #update)
- #save(resource) ⇒ Object
Instance Method Details
#create(attributes) ⇒ Object Also known as: update
15 16 17 18 19 |
# File 'lib/moneybird/traits/save.rb', line 15 def create(attributes) build(attributes).tap do |resource| save(resource) end end |
#save(resource) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/moneybird/traits/save.rb', line 4 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 |