Module Amazon::Locale
In: lib/amazon/locale.rb

Use of this module requires the use of the GeoIP library from MaxMind. It also requires the net-geoip Ruby module to interface with it.

Load this library as follows:

 require 'amazon/locale'

Methods

Classes and Modules

Class Amazon::Locale::GeoError

Constants

CA = %w[ ca ]   ISO 3166 codes of countries likely to want to shop in the CA locale.
DE = %w[ at ch de ]   ISO 3166 codes of countries likely to want to shop in the DE locale.
FR = %w[ be fr ]   ISO 3166 codes of countries likely to want to shop in the FR locale.
JP = %w[ jp ]   ISO 3166 codes of countries likely to want to shop in the JP locale.
UK = %w[ ad al ba cy cz dk ee es fi fo gg gi gr gl hu ie im is it je li lt lu lv mk mt nl no pl pt ro se si sk sm uk ]   ISO 3166 codes of countries likely to want to shop in the UK locale.
US = %w[ mx us ]   ISO 3166 codes of countries likely to want to shop in the US locale. Any countries not explicitly listed above default to the US locale.

Public Class methods

This will attempt to return a reasonable locale (ca, de, fr, jp, uk or us) to use for the IP address address.

Example:

 get_locale_by_addr( '217.110.207.55' ) => "de"

[Source]

# File lib/amazon/locale.rb, line 92
      def Locale.get_locale_by_addr(address)
        cc = Net::GeoIP.new.country_code_by_addr( address )
        raise GeoError, "invalid address: #{address}" unless cc
        localise( cc )
      end

This will attempt to return a reasonable locale (ca, de, fr, jp, uk or us) to use for host.

Example:

 get_locale_by_name( 'xs1.xs4all.nl' ) => "uk"

[Source]

# File lib/amazon/locale.rb, line 79
      def Locale.get_locale_by_name(host)
        cc = Net::GeoIP.new.country_code_by_name( host )
        raise GeoError, "invalid host: #{host}" unless cc
        localise( cc )
      end

[Validate]