Module: Ip2Geo::Data

Defined in:
lib/ip2geo/data/states.rb,
lib/ip2geo/data/messages.rb,
lib/ip2geo/data/constants.rb

Defined Under Namespace

Classes: State

Constant Summary collapse

MESSAGES =
{
  conversions: {
    'ip-address-is-required-to-convert-it' => 'IP address is required to convert it.',
    'invalid-ip-address-so-we-could-not-convert-it' => 'Invalid IP address, so we could not convert it.',
    'ip-addresses-are-required-to-convert-them' => 'IP addresses are required to convert them.',
    'all-ip-addresses-are-invalid' => 'All IP addresses are invalid.',
    'some-ip-addresses-are-invalid' => 'Some IP addresses are invalid.',
    'conversion-id-is-required' => 'Conversion ID is required.',
    'conversion-ids-are-required' => 'Conversion IDs are required.'
  }
}.freeze
API_ENDPOINT =
'https://api.ip2geo.dev'
DOCS_URL =
'https://docs.ip2geo.dev'
RUBYGEMS_URL =
'https://rubygems.org/api/v1/gems/ip2geo.json'
IP_TYPES =
{
  IPV4: 'ipv4',
  IPV6: 'ipv6'
}.freeze
HTTP_METHODS =
{
  ALL: 'all',
  GET: 'GET',
  POST: 'POST',
  DELETE: 'DELETE',
  OPTIONS: 'OPTIONS'
}.freeze
HEADER_KEYS =
{
  X_API_KEY: 'X-Api-Key'
}.freeze
FILE_TYPES =
{
  JSON: 'json'
}.freeze
FILE_FORMATS =
{
  APPLICATION_JSON: 'application/json'
}.freeze
HEADER_TYPES =
{
  CONTENT_TYPE: 'Content-Type'
}.freeze
ENDPOINTS =
{
  CONVERT: '/convert',
  CONVERSIONS: {
    GET: '/conversions/get',
    LIST: '/conversions/list'
  }.freeze
}.freeze
SELECT =
{
  IP: 'ip',
  TYPE: 'type',
  IS_EU: 'is_eu',
  CONTINENT_NAME: 'continent.name',
  CONTINENT_CODE: 'continent.code',
  CONTINENT_GEONAME_ID: 'continent.geoname_id',
  COUNTRY_NAME: 'continent.country.name',
  COUNTRY_CODE: 'continent.country.code',
  COUNTRY_GEONAME_ID: 'continent.country.geoname_id',
  COUNTRY_PHONE_CODE: 'continent.country.phone_code',
  COUNTRY_CAPITAL: 'continent.country.capital',
  COUNTRY_TLD: 'continent.country.tld',
  SUBDIVISION_NAME: 'continent.country.subdivision.name',
  SUBDIVISION_CODE: 'continent.country.subdivision.code',
  CITY_NAME: 'continent.country.city.name',
  CITY_GEONAME_ID: 'continent.country.city.geoname_id',
  CITY_LATITUDE: 'continent.country.city.latitude',
  CITY_LONGITUDE: 'continent.country.city.longitude',
  CITY_ACCURACY_RADIUS: 'continent.country.city.accuracy_radius',
  CITY_METRO_CODE: 'continent.country.city.metro_code',
  CITY_POSTAL_CODE: 'continent.country.city.postal_code',
  TIMEZONE_NAME: 'continent.country.city.timezone.name',
  TIMEZONE_TIME_NOW: 'continent.country.city.timezone.time_now',
  FLAG_IMG: 'continent.country.flag.img',
  FLAG_EMOJI: 'continent.country.flag.emoji',
  FLAG_EMOJI_UNICODE: 'continent.country.flag.emoji_unicode',
  CURRENCY_NAME: 'continent.country.currency.name',
  CURRENCY_CODE: 'continent.country.currency.code',
  CURRENCY_SYMBOL: 'continent.country.currency.symbol',
  REGISTERED_COUNTRY_NAME: 'registered_country.name',
  REGISTERED_COUNTRY_CODE: 'registered_country.code',
  REGISTERED_COUNTRY_GEONAME_ID: 'registered_country.geoname_id',
  ASN_NUMBER: 'asn.number',
  ASN_NAME: 'asn.name',
  COMPLETION_TIME_MILISECONDS: 'completion_time.miliseconds',
  COMPLETION_TIME_SECONDS: 'completion_time.seconds'
}.freeze

Class Method Summary collapse

Class Method Details

.translate(key) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ip2geo/data/messages.rb', line 17

def self.translate(key)
  keys = key.split('.')
  result = MESSAGES

  keys.each do |k|
    result = result[k.to_sym] || result[k]
    return key if result.nil?
  end

  result
end