Sha256: ee29522c0f9809f78fb2ceeac511282604cb2c585242a090f1e5a21584245cfb

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

module LedgerSync
  module Adaptors
    module Test
      module Vendor
        module Operations
          class Create < Operation::Create
            class Contract < LedgerSync::Adaptors::Contract
              schema do
                required(:external_id).maybe(:string)
                required(:ledger_id).value(:nil)
                required(:display_name).maybe(:string)
                required(:first_name).maybe(:string)
                required(:last_name).maybe(:string)
                required(:email).maybe(:string)
              end
            end

            private

            def id
              SecureRandom.uuid
            end

            def local_resource_data
              {
                'name' => resource.display_name,
                'email' => resource.email
              }
            end

            def operate
              response = adaptor.post(
                resource: 'vendor',
                payload: local_resource_data.merge(
                  'id' => id
                )
              )

              resource.ledger_id = response.dig('id')

              success(
                resource: Test::LedgerSerializer.new(resource: resource).deserialize(hash: response),
                response: response
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ledger_sync-1.1.3 lib/ledger_sync/adaptors/test/vendor/operations/create.rb
ledger_sync-1.1.2 lib/ledger_sync/adaptors/test/vendor/operations/create.rb