{"id":15512362,"url":"https://github.com/ipinfo/ruby","last_synced_at":"2025-06-16T11:10:58.652Z","repository":{"id":55367647,"uuid":"108568073","full_name":"ipinfo/ruby","owner":"ipinfo","description":"Official Ruby client library for IPinfo API (IP geolocation and other types of IP data)","archived":false,"fork":false,"pushed_at":"2025-05-08T17:47:00.000Z","size":142,"stargazers_count":48,"open_issues_count":2,"forks_count":18,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-06-13T11:55:45.682Z","etag":null,"topics":["faraday","ip-address","ip-database","ip-geolocation","ipinfo","ruby","wrapper-api"],"latest_commit_sha":null,"homepage":"https://ipinfo.io","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ipinfo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-10-27T16:17:43.000Z","updated_at":"2025-05-08T17:47:03.000Z","dependencies_parsed_at":"2023-12-19T15:04:37.495Z","dependency_job_id":"0a5c83e5-463a-4e9f-8d47-e63d251f2c7f","html_url":"https://github.com/ipinfo/ruby","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/ipinfo/ruby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Fruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Fruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Fruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Fruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipinfo","download_url":"https://codeload.github.com/ipinfo/ruby/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipinfo%2Fruby/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260148401,"owners_count":22965915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["faraday","ip-address","ip-database","ip-geolocation","ipinfo","ruby","wrapper-api"],"created_at":"2024-10-02T09:53:36.648Z","updated_at":"2025-06-16T11:10:58.634Z","avatar_url":"https://github.com/ipinfo.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# [\u003cimg src=\"https://ipinfo.io/static/ipinfo-small.svg\" alt=\"IPinfo\" width=\"24\"/\u003e](https://ipinfo.io/) IPinfo Ruby Client Library\n\nThis is the official Ruby client library for the [IPinfo.io](https://ipinfo.io) IP address API, allowing you to look up your own IP address, or get any of the following details for an IP:\n - [IP geolocation data](https://ipinfo.io/ip-geolocation-api) (city, region, country, postal code, latitude, and longitude)\n - [ASN information](https://ipinfo.io/asn-api) (ISP or network operator, associated domain name, and type, such as business, hosting, or company)\n - [Firmographic data](https://ipinfo.io/ip-company-api) (the name and domain of the business that uses the IP address)\n - [Carrier details](https://ipinfo.io/ip-carrier-api) (the name of the mobile carrier and MNC and MCC for that carrier if the IP is used exclusively for mobile traffic)\n\nCheck all the data we have for your IP address [here](https://ipinfo.io/what-is-my-ip).\n\n### Getting Started\n\nYou'll need an IPinfo API access token, which you can get by signing up for a free account at [https://ipinfo.io/signup](https://ipinfo.io/signup).\n\nThe free plan is limited to 50,000 requests per month, and doesn't include some of the data fields such as IP type and company data. To enable all the data fields and additional request volumes see [https://ipinfo.io/pricing](https://ipinfo.io/pricing)\n\n⚠️ Note: This library does not currently support our newest free API https://ipinfo.io/lite. If you’d like to use IPinfo Lite, you can call the [endpoint directly](https://ipinfo.io/developers/lite-api) using your preferred HTTP client. Developers are also welcome to contribute support for Lite by submitting a pull request.\n\n#### Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'IPinfo'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install IPinfo\n\n#### Quick Start\n\n```ruby\nrequire 'ipinfo'\n\naccess_token = '123456789abc'\nhandler = IPinfo::create(access_token)\nip_address = '216.239.36.21'\n\ndetails = handler.details(ip_address)\ndetails_v6 = handler.details_v6() # to get details from ipinfo's IPv6 host\ncity = details.city # Emeryville\nloc = details.loc # 37.8342,-122.2900\n```\n\n##### Note about Rails 6+\n\nIf using this package in Rails 6+, the Zeitwerk auto-loader may not properly\nrecognize the gem due to its naming conventions (uppercased gem/module name).\nSee issue https://github.com/ipinfo/ruby/issues/24.\n\nA workaround is to insert this in `application.rb`:\n\n```ruby\nrequire 'ipinfo' unless defined?(IPinfo)\n```\n\n#### Usage\n\nThe `IPinfo.details()` and `IPinfo.details_v6()` methods accept an IP address as an optional, positional\nargument. If no IP address is specified, the API will return data for the IP\naddress from which it receives the request.\n\n```ruby\nrequire 'ipinfo'\n\naccess_token = '123456789abc'\nhandler = IPinfo::create(access_token)\n\ndetails = handler.details()\ndetails_v6 = handler.details_v6() # to get details from ipinfo's IPv6 host\ncity = details.city # \"Emeryville\"\nloc = details.loc # 37.8342,-122.2900\n```\n\n#### Authentication\n\nThe IPinfo library can be authenticated with your IPinfo API token, which is\npassed in as a positional argument. It also works without an authentication\ntoken, but in a more limited capacity.\n\n```ruby\naccess_token = '123456789abc'\nhandler = IPinfo::create(access_token)\n```\n\n#### Details Data\n\n`handler.details()` and `handler.details_v6` will return a `Response` object that contains all fields\nlisted in the [IPinfo developerdocs](https://ipinfo.io/developers/responses#full-response)\nwith a few minor additions. Properties can be accessed directly.\n\n```ruby\nhostname = details.hostname # cpe-104-175-221-247.socal.res.rr.com\n```\n\n##### Country Name\n\n`details.country_name` will return the country name, as defined by `DEFAULT_COUNTRY_LIST`\nwithin `countriesData.rb`. See below for instructions on changing that file for use\nwith non-English languages. `details.country` will still return the country code.\n\n```ruby\ncountry = details.country # US\ncountry_name = details.country_name # United States\n```\n\n##### European Union (EU) Country\n\n`details.is_eu` will return `true` if the country is a member of the European Union (EU)\n, as defined by `DEFAULT_EU_COUNTRIES_LIST` within `countriesData.rb`.\n\n```ruby\nis_eu = details.is_eu # false\n```\n\nIt is possible to change the file by setting the `eu_countries` setting when creating the `IPinfo` object.\n\n##### Country Flag\n\n`details.country_flag` will return `emoji` and `unicode` of a country's flag, as defined by\n`DEFAULT_COUNTRIES_FLAG_LIST` within `countriesData.rb`.\n\n```ruby\ncountry_flag = details.country_flag # {\"emoji\"=\u003e\"🇺🇸\", \"unicode\"=\u003e\"U+1F1FA U+1F1F8\"}\ncountry_flag_emoji = details.country_flag['emoji'] # 🇺🇸\ncountry_flag_unicode = details.country_flag['unicode'] # U+1F1FA U+1F1F8\n```\n\n##### Country Flag URL\n\n`details.country_flag_url` will return a public link to the country's flag image as an SVG which can be used anywhere.\n\n```ruby\ncountry_flag = details.country_flag_url # {\"https://cdn.ipinfo.io/static/images/countries-flags/US.svg\"}\n```\n\n##### Country Currency\n\n`details.country_currency` will return `code` and `symbol` of a country's currency, as defined by\n`DEFAULT_COUNTRIES_CURRENCIES_LIST` within `countriesData.rb`.\n\n```ruby\ncountry_currency = details.country_currency # {\"code\"=\u003e\"USD\", \"symbol\"=\u003e\"$\"}\ncountry_currency_code = details.country_currency['code'] # USD\ncountry_currency_symbol = details.country_currency['symbol'] # $\n```\n\nIt is possible to change the file by setting the `countries_currencies` setting when creating the `IPinfo` object.\n\n##### Continent\n\n`details.continent` will return `code` and `name` of the continent, as defined by\n`DEFAULT_CONTINENT_LIST` within `countriesData.rb`.\n\n```ruby\ncontinent = details.continent # {\"code\"=\u003e\"NA\", \"name\"=\u003e\"North America\"}\ncontinent_code = details.continent['code'] # NA\ncontinent_name = details.continent['name'] # North America\n```\n\nIt is possible to change the file by setting the `continents` setting when creating the `IPinfo` object.\n\n#### IP Address\n\n`details.ip_address` will return the `IPAddr` object from the\n[Ruby Standard Library](https://ruby-doc.org/stdlib-2.5.1/libdoc/ipaddr/rdoc/IPAddr.html).\n`details.ip` will still return a string.\n\n```ruby\nip = details.ip # 104.175.221.247\nip_addr = details.ip_address # \u003cIPAddr: IPv4:104.175.221.247/255.255.255.255\u003e\n```\n\n##### Longitude and Latitude\n\n`details.latitude` and `details.longitude` will return latitude and longitude,\nrespectively, as strings. `details.loc` will still return a composite string of\nboth values.\n\n```ruby\nloc = details.loc # 34.0293,-118.3570\nlat = details.latitude # 34.0293\nlon = details.longitude # -118.3570\n```\n\n##### Accessing all properties\n\n`details.all` will return all details data as a dictionary.\n\n```ruby\ndetails.all = {\n:asn =\u003e {  :asn =\u003e 'AS20001',\n           :domain =\u003e 'twcable.com',\n           :name =\u003e 'Time Warner Cable Internet LLC',\n           :route =\u003e '104.172.0.0/14',\n           :type =\u003e 'isp'},\n:city =\u003e 'Los Angeles',\n:company =\u003e {  :domain =\u003e 'twcable.com',\n               :name =\u003e 'Time Warner Cable Internet LLC',\n               :type =\u003e 'isp'},\n:country =\u003e 'US',\n:country_name =\u003e 'United States',\n:hostname =\u003e 'cpe-104-175-221-247.socal.res.rr.com',\n:ip =\u003e '104.175.221.247',\n:ip_address =\u003e \u003cIPAddr: IPv4:104.175.221.247/255.255.255.255\u003e,\n:loc =\u003e '34.0293,-118.3570',\n:latitude =\u003e '34.0293',\n:longitude =\u003e '-118.3570',\n:phone =\u003e '323',\n:postal =\u003e '90016',\n:region =\u003e 'California'\n}\n```\n\n#### Caching\n\nIn-memory caching of `details` data is provided by default via the\n[`lru_redux`](https://github.com/SamSaffron/lru_redux) gem. This uses an LRU\n(least recently used) cache with a TTL (time to live) by default. This means\nthat values will be cached for the specified duration; if the cache's max size\nis reached, cache values will be invalidated as necessary, starting with the\noldest cached value.\n\n##### Modifying cache options\n\nCache behavior can be modified by setting the `cache_options` keyword argument.\n`cache_options` is a dictionary in which the keys are keyword arguments\nspecified in the `cachetools` library. The nesting of keyword arguments is to\nprevent name collisions between this library and its dependencies.\n\n* Default maximum cache size: 4096 (multiples of 2 are recommended to increase\n  efficiency)\n* Default TTL: 24 hours (in seconds)\n\n```ruby\ntoken = '1234'\nhandler = IPinfo::create(token, {:ttl =\u003e 30, :maxsize =\u003e 30})\n```\n\n##### Using a different cache\n\nIt's possible to use a custom cache by creating a child class of the\n[CacheInterface](https://github.com/jhtimmins/ruby/blob/master/lib/ipinfo/cache/cache_interface.rb)\nclass and passing this into the handler object with the `cache` keyword\nargument. FYI this is known as\n[the Strategy Pattern](https://sourcemaking.com/design_patterns/strategy).\n\n```ruby\nhandler = IPinfo.handler(token, {:cache =\u003e my_fancy_custom_class})\n```\n\n### Using a different HTTP library\n\nRuby is notorious for having lots of HTTP libraries. While `Net::HTTP` is a\nreasonable default, you can set any other that\n[Faradaysupports](https://github.com/lostisland/faraday/tree/29feeb92e3413d38ffc1fd3a3479bb48a0915730#faraday)\nif you prefer.\n\n```ruby\naccess_token = '123456789abc'\nhandler = IPinfo::create(access_token, {:http_client =\u003e my_client})\n```\n\nDon't forget to bundle the custom HTTP library as well.\n\n#### Internationalization\n\nWhen looking up an IP address, the response object includes a\n`details.country_name` attribute which includes the country name based on\nAmerican English. It is possible to return the country name in other languages\nby setting the `countries` setting when creating the `IPinfo` object.\n\n```\n{\n \"BD\" =\u003e \"Bangladesh\",\n \"BE\" =\u003e \"Belgium\",\n \"BF\" =\u003e \"Burkina Faso\",\n \"BG\" =\u003e \"Bulgaria\"\n ...\n}\n```\n\n### Other Libraries\n\nThere are official IPinfo client libraries available for many languages including PHP, Go, Java, Ruby, and many popular frameworks such as Django, Rails, and Laravel. There are also many third-party libraries and integrations available for our API.\n\n### About IPinfo\n\nFounded in 2013, IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier, VPN detection, hosted domains, and IP type data sets. Our API handles over 40 billion requests a month for 100,000 businesses and developers.\n\n[![image](https://avatars3.githubusercontent.com/u/15721521?s=128\u0026u=7bb7dde5c4991335fb234e68a30971944abc6bf3\u0026v=4)](https://ipinfo.io/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipinfo%2Fruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipinfo%2Fruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipinfo%2Fruby/lists"}