Sha256: 0a621427e124bcc1084fc3aebf72469966738112c639ecff314fea3eaf328dbc

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 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',
      'ATVPDKIKX0DER'  => 'mws.amazonservices.com'
    }

    BadId = Class.new(StandardError)

    attr_reader :id

    def initialize(id)
      @id = id or fail BadId, 'missing MarketplaceId'
    end

    def host
      @host ||= find_host
    end

    def encoding
      if japanese?
        # Caveat: I've had one instance in the past where Shift_JIS didn't
        # work but Windows-31J did when parsing a report.
        'Shift_JIS'
      elsif chinese?
        'UTF-16'
      else
        'ISO-8859-1'
      end
    end

    private

    def find_host
      HOSTS.fetch(id) { fail BadId, %Q("#{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

3 entries across 3 versions & 1 rubygems

Version Path
peddler-0.15.0 lib/peddler/marketplace.rb
peddler-0.14.0 lib/peddler/marketplace.rb
peddler-0.13.0 lib/peddler/marketplace.rb