Sha256: 458ded290d1d281e8ae09272f9c22e26b693fa3aee2338aca2b295bc76a9340f

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

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

            private

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

              resource.ledger_id = response.dig('Id')
              success(response: response)
            end

            def local_resource_data
              {
                'DisplayName' => resource.display_name,
                'GivenName' => resource.first_name,
                'FamilyName' => resource.last_name,
                'PrimaryEmailAddr' => {
                  'Address' => resource.email
                }
              }
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ledger_sync-1.1.1 lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/create.rb