Sha256: a8a13a3625384aadf2bd410315d67d96b3c86391d87dd66000933c933f5a4eb1

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

module Peddler
  # @api private
  class Marketplace
    HOSTS = {
      'A2EUQ1WTGCTBG2' => 'mws.amazonservices.ca',
      'AAHKV2X7AFYLW'  => 'mws.amazonservices.com.cn',
      'A1PA6795UKMFR9' => 'mws-eu.amazonservices.com',
      'A1RKKUPIHCS9HS' => 'mws-eu.amazonservices.com',
      'A13V1IB3VIYZZH' => 'mws-eu.amazonservices.com',
      'A1F83G8C2ARO7P' => 'mws-eu.amazonservices.com',
      'A21TJRUUN4KGV'  => 'mws.amazonservices.in',
      'APJ6JRA9NG5V4'  => 'mws-eu.amazonservices.com',
      'A1VC38T7YXB528' => 'mws.amazonservices.jp',
      'A1AM78C64UM0Y8' => 'mws.amazonservices.com.mx',
      'ATVPDKIKX0DER'  => 'mws.amazonservices.com'
    }.freeze

    BadId = Class.new(StandardError)

    attr_reader :id

    def initialize(id)
      @id = id || raise(BadId, 'missing MarketplaceId')
    end

    def host
      @host ||= find_host
    end

    # Caveat: We use the supersets Windows-31J and CP1252 in place of Shift_JIS
    # and ISO 8859-1 respectively to handle edge cases where latter will not
    # support some characters. The supersets should be safe to use as drop-in
    # replacements.
    def encoding
      if japanese?
        'Windows-31J'
      elsif chinese?
        'UTF-16'
      else
        'CP1252'
      end
    end

    private

    def find_host
      HOSTS.fetch(id) { raise BadId, %("#{id}" is not a valid MarketplaceId) }
    end

    def japanese?
      host.end_with?('jp')
    end

    def chinese?
      host.end_with?('cn')
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
peddler-1.6.1 lib/peddler/marketplace.rb
peddler-1.6.0 lib/peddler/marketplace.rb
peddler-1.5.0 lib/peddler/marketplace.rb
peddler-1.4.1 lib/peddler/marketplace.rb
peddler-1.4.0 lib/peddler/marketplace.rb