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



56
57
58
# File 'lib/fat_zebra/api_operation/save.rb', line 56

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



47
48
49
50
51
52
53
# File 'lib/fat_zebra/api_operation/save.rb', line 47

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

  response = request(method, path, to_hash.merge(params), options)
  update_from(response)
end