Sha256: e945336305cd040deef198629a5f7d96db610a0e4076ade9075e91858e34d63a

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

module LedgerSync
  module Adaptors
    module Test
      module Customer
        module Operations
          class Update < Operation::Update
            class Contract < LedgerSync::Adaptors::Contract
              schema do
                required(:ledger_id).filled(:string)
                optional(:email).maybe(:string)
                required(:name).filled(:string)
                optional(:phone_number).maybe(:string)
              end
            end

            private

            def operate
              ledger_resource_data = adaptor.find(
                resource: 'customer',
                id: resource.ledger_id
              )

              response = adaptor.upsert(
                resource: 'customer',
                payload: merge_into(from: local_resource_data, to: ledger_resource_data)
              )

              success(response: response)
            rescue OAuth2::Error => e
              failure(e)
            end

            def local_resource_data
              {
                'name': resource.name,
                "phone_number": resource.phone_number,
                "email": resource.email
              }
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ledger_sync-1.0.10 lib/ledger_sync/adaptors/test/customer/operations/update.rb
ledger_sync-1.0.9 lib/ledger_sync/adaptors/test/customer/operations/update.rb
ledger_sync-1.0.3 lib/ledger_sync/adaptors/test/customer/operations/update.rb
ledger_sync-1.0.2 lib/ledger_sync/adaptors/test/customer/operations/update.rb
ledger_sync-1.0.0 lib/ledger_sync/adaptors/test/customer/operations/update.rb