Module: FatZebra::APIOperation::Save

Included in:
BankAccount, Batch, Card, Customer, DirectCredit, DirectDebit, PaymentPlan, Purchase, Refund, WebHook
Defined in:
lib/fat_zebra/api_operation/save.rb

Overview

Save (create or update) a resource for the API

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



63
64
65
# File 'lib/fat_zebra/api_operation/save.rb', line 63

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#save(params = {}, options = {}) ⇒ FatZebra::Object Also known as: update

Create or Update an API Resource

Parameters:

  • params (Hash) (defaults to: {})

    for the request

  • Additional (Hash)

    options for the request

Returns:

  • (FatZebra::Object)

    response from the API



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fat_zebra/api_operation/save.rb', line 49

def save(params = {}, options = {})
  path   = singleton_methods.include?(:id) ? "#{resource_path}/#{id}" : resource_path
  method = singleton_methods.include?(:id) ? :put : :post

  params_for_save = to_hash.merge(params)

  # Remove the id from the params to save, it should not be updated.
  params_for_save.delete('id')

  response = request(method, path, params_for_save, options)
  update_from(response)
end