View Source Plausible.Geo (Plausible v0.0.1)

This module provides an API for fetching IP geolocation.

Link to this section Summary

Functions

Waits for the database to start after calling load_db/1 with the async option.

Returns geodatabase type.

Starts the geodatabase loading process. Two modes are supported: local file and MaxMind license key.

Looks up geo info about an IP address.

Link to this section Functions

Waits for the database to start after calling load_db/1 with the async option.

Returns geodatabase type.

Used for deciding whether to show the DB-IP disclaimer or not.

examples

Examples

In the case of a DB-IP database:

iex> database_type()
"DBIP-City-Lite"

In the case of a MaxMind database:

iex> database_type()
"GeoLite2-City"

Starts the geodatabase loading process. Two modes are supported: local file and MaxMind license key.

options

Options

  • :path - the path to the .mmdb database local file. When present, :license_key and :edition are not required.

  • :license_key - the license key from MaxMind to authenticate requests to MaxMind.

  • :edition - the name of the MaxMind database to be downloaded from MaxMind servers. Defaults to GeoLite2-City.

  • :async - when used, configures the database loading to run asynchronously.

examples

Examples

Loading from a local file:

iex> load_db(path: "/etc/plausible/dbip-city.mmdb")
:ok

Downloading a MaxMind DB (this license key is no longer active):

iex> load_db(license_key: "LNpsJCCKPis6XvBP", edition: "GeoLite2-City", async: true)
:ok

Looks up geo info about an IP address.

examples

Examples

iex> lookup("8.7.6.5")
%{
  "city" => %{
    "geoname_id" => 5349755,
    "names" => %{
      "de" => "Fontana",
      "en" => "Fontana",
      "ja" => "フォンタナ",
      "ru" => "Фонтана"
    }
  },
  "continent" => %{
    "code" => "NA",
    "geoname_id" => 6255149,
    "names" => %{
      "de" => "Nordamerika",
      "en" => "North America",
      "es" => "Norteamérica",
      "fr" => "Amérique du Nord",
      "ja" => "北アメリカ",
      "pt-BR" => "América do Norte",
      "ru" => "Северная Америка",
      "zh-CN" => "北美洲"
    }
  },
  "country" => %{
    "geoname_id" => 6252001,
    "iso_code" => "US",
    "names" => %{
      "de" => "Vereinigte Staaten",
      "en" => "United States",
      "es" => "Estados Unidos",
      "fr" => "États Unis",
      "ja" => "アメリカ",
      "pt-BR" => "EUA",
      "ru" => "США",
      "zh-CN" => "美国"
    }
  },
  "location" => %{
    "accuracy_radius" => 50,
    "latitude" => 34.1211,
    "longitude" => -117.4362,
    "metro_code" => 803,
    "time_zone" => "America/Los_Angeles"
  },
  "postal" => %{"code" => "92336"},
  "registered_country" => %{
    "geoname_id" => 6252001,
    "iso_code" => "US",
    "names" => %{
      "de" => "Vereinigte Staaten",
      "en" => "United States",
      "es" => "Estados Unidos",
      "fr" => "États Unis",
      "ja" => "アメリカ",
      "pt-BR" => "EUA",
      "ru" => "США",
      "zh-CN" => "美国"
    }
  },
  "subdivisions" => [
    %{
      "geoname_id" => 5332921,
      "iso_code" => "CA",
      "names" => %{
        "de" => "Kalifornien",
        "en" => "California",
        "es" => "California",
        "fr" => "Californie",
        "ja" => "カリフォルニア州",
        "pt-BR" => "Califórnia",
        "ru" => "Калифорния",
        "zh-CN" => "加州"
      }
    }
  ]
}