Sha256: 0c42dc751a0c47c8dc6c337349f89ba4f963a614fcf494f7749cce2ec87f1985

Contents?: true

Size: 935 Bytes

Versions: 2

Compression:

Stored size: 935 Bytes

Contents

module SpreeAvataxOfficial
  class AddressPresenter
    def initialize(address:, address_type:)
      @address      = address
      @address_type = address_type
    end

    # Based on: https://developer.avalara.com/api-reference/avatax/rest/v2/models/AddressLocationInfo/
    def to_json
      {
        address_type => serialized_address
      }
    end

    private

    attr_reader :address, :address_type

    def serialized_address
      address_type == 'ShipFrom' ? ship_from_address : ship_to_address
    end

    def ship_to_address
      SpreeAvataxOfficial::ShipToAddressPresenter.new(
        address: address
      ).to_json
    end

    def ship_from_address
      {
        line1:      address[:line1],
        line2:      address[:line2],
        city:       address[:city],
        region:     address[:region],
        country:    address[:country],
        postalCode: address[:postalCode]
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_avatax_official-1.8.0 app/presenters/spree_avatax_official/address_presenter.rb
spree_avatax_official-1.7.1 app/presenters/spree_avatax_official/address_presenter.rb