├── .editorconfig
├── .github
└── workflows
│ ├── cd_rubygems.yaml
│ └── unittest.yaml
├── .gitignore
├── .rubocop.yml
├── .ruby-version
├── Gemfile
├── LICENSE
├── README.md
├── Rakefile
├── bin
├── console
└── setup
├── ipinfo.gemspec
├── lib
├── ipinfo.rb
└── ipinfo
│ ├── adapter.rb
│ ├── cache
│ ├── cache_interface.rb
│ └── default_cache.rb
│ ├── countriesData.rb
│ ├── errors.rb
│ ├── ipAddressMatcher.rb
│ ├── mod.rb
│ ├── response.rb
│ └── version.rb
└── test
├── ipinfo_test.rb
├── lib
├── adapter_test.rb
└── cache_test.rb
└── test_helper.rb
/.editorconfig:
--------------------------------------------------------------------------------
1 | # top-most EditorConfig file
2 | root = true
3 |
4 | # Unix-style newlines with a newline ending every file
5 | # Two spaces for indenting
6 | [*]
7 | end_of_line = lf
8 | insert_final_newline = true
9 | indent_style = space
10 | indent_size = 2
11 | charset = utf-8
12 | trim_trailing_whitespace = true
13 | max_line_length = 80
14 |
--------------------------------------------------------------------------------
/.github/workflows/cd_rubygems.yaml:
--------------------------------------------------------------------------------
1 | name: Release package to rubygems.org
2 |
3 | on:
4 | push:
5 | tags:
6 | - 'v*'
7 |
8 | jobs:
9 | publish:
10 |
11 | runs-on: ubuntu-latest
12 |
13 | steps:
14 | - name: Checkout
15 | uses: actions/checkout@v3
16 |
17 | - name: Install apt dependencies
18 | run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev # needed by faraday-patron gem
19 |
20 | - name: Set up Ruby
21 | uses: ruby/setup-ruby@v1
22 |
23 | - name: Install dependencies
24 | run: bundle install
25 |
26 | - name: Run tests
27 | run: bundle exec rake
28 | env:
29 | IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
30 |
31 | - name: Build
32 | run: gem build *.gemspec
33 |
34 | - name: Publish
35 | run: gem push *.gem
36 | env:
37 | GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
38 |
--------------------------------------------------------------------------------
/.github/workflows/unittest.yaml:
--------------------------------------------------------------------------------
1 | name: Unit Tests
2 |
3 | on:
4 | pull_request:
5 |
6 | permissions:
7 | contents: read
8 |
9 | jobs:
10 | run:
11 |
12 | runs-on: ubuntu-latest
13 | strategy:
14 | matrix:
15 | ruby-version: ['3.2', '3.1', '3.0', '2.7', '2.6']
16 |
17 | steps:
18 | - name: Checkout
19 | uses: actions/checkout@v3
20 |
21 | - name: Install apt dependencies
22 | run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev # needed by faraday-patron gem
23 |
24 | - name: Set up Ruby ${{ matrix.ruby-version }}
25 | uses: ruby/setup-ruby@v1
26 | with:
27 | ruby-version: ${{ matrix.ruby-version }}
28 |
29 | - name: Install dependencies
30 | run: bundle install
31 |
32 | - name: Run tests
33 | env:
34 | IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
35 | run: bundle exec rake
36 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.bundle/
2 | /.yardoc
3 | /Gemfile.lock
4 | /_yardoc/
5 | /coverage/
6 | /doc/
7 | /pkg/
8 | /spec/reports/
9 | /tmp/
10 | IPinfo-*.gem
11 |
--------------------------------------------------------------------------------
/.rubocop.yml:
--------------------------------------------------------------------------------
1 | AllCops:
2 | TargetRubyVersion: 2.5
3 | NewCops: enable
4 |
5 | Layout/IndentationWidth:
6 | Width: 4
7 |
8 | Layout/LineLength:
9 | Enabled: true
10 | Max: 80
11 |
12 | Lint/MissingSuper:
13 | Enabled: false
14 |
15 | Metrics/MethodLength:
16 | Enabled: false
17 |
18 | Metrics/AbcSize:
19 | Enabled: false
20 |
21 | Metrics/ClassLength:
22 | Enabled: false
23 |
24 | Lint/DuplicateMethods:
25 | Enabled: false
26 |
27 | Style/Documentation:
28 | Enabled: false
29 |
30 | Style/ClassAndModuleChildren:
31 | Enabled: false
32 |
33 | Style/MethodCallWithArgsParentheses:
34 | EnforcedStyle: require_parentheses
35 | IgnoreMacros: false
36 | IgnoredPatterns: []
37 | AllowParenthesesInMultilineCall: true
38 | AllowParenthesesInChaining: true
39 | AllowParenthesesInCamelCaseMethod: true
40 |
41 | Style/MethodCallWithoutArgsParentheses:
42 | Enabled: false
43 |
44 | Naming/FileName:
45 | Enabled: false
46 |
47 | Naming/PredicateName:
48 | Enabled: false
49 |
--------------------------------------------------------------------------------
/.ruby-version:
--------------------------------------------------------------------------------
1 | 3.2.2
2 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source 'https://rubygems.org'
4 |
5 | gemspec
6 |
7 | group :development do
8 | gem 'bundler'
9 | gem 'minitest'
10 | gem 'minitest-reporters'
11 | gem 'rake'
12 | gem 'rubocop'
13 | end
14 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # [
](https://ipinfo.io/) IPinfo Ruby Client Library
2 |
3 | This 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:
4 | - [IP geolocation data](https://ipinfo.io/ip-geolocation-api) (city, region, country, postal code, latitude, and longitude)
5 | - [ASN information](https://ipinfo.io/asn-api) (ISP or network operator, associated domain name, and type, such as business, hosting, or company)
6 | - [Firmographic data](https://ipinfo.io/ip-company-api) (the name and domain of the business that uses the IP address)
7 | - [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)
8 |
9 | Check all the data we have for your IP address [here](https://ipinfo.io/what-is-my-ip).
10 |
11 | ### Getting Started
12 |
13 | You'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).
14 |
15 | The 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)
16 |
17 | ⚠️ 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.
18 |
19 | #### Installation
20 |
21 | Add this line to your application's Gemfile:
22 |
23 | ```ruby
24 | gem 'IPinfo'
25 | ```
26 |
27 | And then execute:
28 |
29 | $ bundle install
30 |
31 | Or install it yourself as:
32 |
33 | $ gem install IPinfo
34 |
35 | #### Quick Start
36 |
37 | ```ruby
38 | require 'ipinfo'
39 |
40 | access_token = '123456789abc'
41 | handler = IPinfo::create(access_token)
42 | ip_address = '216.239.36.21'
43 |
44 | details = handler.details(ip_address)
45 | details_v6 = handler.details_v6() # to get details from ipinfo's IPv6 host
46 | city = details.city # Emeryville
47 | loc = details.loc # 37.8342,-122.2900
48 | ```
49 |
50 | ##### Note about Rails 6+
51 |
52 | If using this package in Rails 6+, the Zeitwerk auto-loader may not properly
53 | recognize the gem due to its naming conventions (uppercased gem/module name).
54 | See issue https://github.com/ipinfo/ruby/issues/24.
55 |
56 | A workaround is to insert this in `application.rb`:
57 |
58 | ```ruby
59 | require 'ipinfo' unless defined?(IPinfo)
60 | ```
61 |
62 | #### Usage
63 |
64 | The `IPinfo.details()` and `IPinfo.details_v6()` methods accept an IP address as an optional, positional
65 | argument. If no IP address is specified, the API will return data for the IP
66 | address from which it receives the request.
67 |
68 | ```ruby
69 | require 'ipinfo'
70 |
71 | access_token = '123456789abc'
72 | handler = IPinfo::create(access_token)
73 |
74 | details = handler.details()
75 | details_v6 = handler.details_v6() # to get details from ipinfo's IPv6 host
76 | city = details.city # "Emeryville"
77 | loc = details.loc # 37.8342,-122.2900
78 | ```
79 |
80 | #### Authentication
81 |
82 | The IPinfo library can be authenticated with your IPinfo API token, which is
83 | passed in as a positional argument. It also works without an authentication
84 | token, but in a more limited capacity.
85 |
86 | ```ruby
87 | access_token = '123456789abc'
88 | handler = IPinfo::create(access_token)
89 | ```
90 |
91 | #### Details Data
92 |
93 | `handler.details()` and `handler.details_v6` will return a `Response` object that contains all fields
94 | listed in the [IPinfo developerdocs](https://ipinfo.io/developers/responses#full-response)
95 | with a few minor additions. Properties can be accessed directly.
96 |
97 | ```ruby
98 | hostname = details.hostname # cpe-104-175-221-247.socal.res.rr.com
99 | ```
100 |
101 | ##### Country Name
102 |
103 | `details.country_name` will return the country name, as defined by `DEFAULT_COUNTRY_LIST`
104 | within `countriesData.rb`. See below for instructions on changing that file for use
105 | with non-English languages. `details.country` will still return the country code.
106 |
107 | ```ruby
108 | country = details.country # US
109 | country_name = details.country_name # United States
110 | ```
111 |
112 | ##### European Union (EU) Country
113 |
114 | `details.is_eu` will return `true` if the country is a member of the European Union (EU)
115 | , as defined by `DEFAULT_EU_COUNTRIES_LIST` within `countriesData.rb`.
116 |
117 | ```ruby
118 | is_eu = details.is_eu # false
119 | ```
120 |
121 | It is possible to change the file by setting the `eu_countries` setting when creating the `IPinfo` object.
122 |
123 | ##### Country Flag
124 |
125 | `details.country_flag` will return `emoji` and `unicode` of a country's flag, as defined by
126 | `DEFAULT_COUNTRIES_FLAG_LIST` within `countriesData.rb`.
127 |
128 | ```ruby
129 | country_flag = details.country_flag # {"emoji"=>"🇺🇸", "unicode"=>"U+1F1FA U+1F1F8"}
130 | country_flag_emoji = details.country_flag['emoji'] # 🇺🇸
131 | country_flag_unicode = details.country_flag['unicode'] # U+1F1FA U+1F1F8
132 | ```
133 |
134 | ##### Country Flag URL
135 |
136 | `details.country_flag_url` will return a public link to the country's flag image as an SVG which can be used anywhere.
137 |
138 | ```ruby
139 | country_flag = details.country_flag_url # {"https://cdn.ipinfo.io/static/images/countries-flags/US.svg"}
140 | ```
141 |
142 | ##### Country Currency
143 |
144 | `details.country_currency` will return `code` and `symbol` of a country's currency, as defined by
145 | `DEFAULT_COUNTRIES_CURRENCIES_LIST` within `countriesData.rb`.
146 |
147 | ```ruby
148 | country_currency = details.country_currency # {"code"=>"USD", "symbol"=>"$"}
149 | country_currency_code = details.country_currency['code'] # USD
150 | country_currency_symbol = details.country_currency['symbol'] # $
151 | ```
152 |
153 | It is possible to change the file by setting the `countries_currencies` setting when creating the `IPinfo` object.
154 |
155 | ##### Continent
156 |
157 | `details.continent` will return `code` and `name` of the continent, as defined by
158 | `DEFAULT_CONTINENT_LIST` within `countriesData.rb`.
159 |
160 | ```ruby
161 | continent = details.continent # {"code"=>"NA", "name"=>"North America"}
162 | continent_code = details.continent['code'] # NA
163 | continent_name = details.continent['name'] # North America
164 | ```
165 |
166 | It is possible to change the file by setting the `continents` setting when creating the `IPinfo` object.
167 |
168 | #### IP Address
169 |
170 | `details.ip_address` will return the `IPAddr` object from the
171 | [Ruby Standard Library](https://ruby-doc.org/stdlib-2.5.1/libdoc/ipaddr/rdoc/IPAddr.html).
172 | `details.ip` will still return a string.
173 |
174 | ```ruby
175 | ip = details.ip # 104.175.221.247
176 | ip_addr = details.ip_address #
177 | ```
178 |
179 | ##### Longitude and Latitude
180 |
181 | `details.latitude` and `details.longitude` will return latitude and longitude,
182 | respectively, as strings. `details.loc` will still return a composite string of
183 | both values.
184 |
185 | ```ruby
186 | loc = details.loc # 34.0293,-118.3570
187 | lat = details.latitude # 34.0293
188 | lon = details.longitude # -118.3570
189 | ```
190 |
191 | ##### Accessing all properties
192 |
193 | `details.all` will return all details data as a dictionary.
194 |
195 | ```ruby
196 | details.all = {
197 | :asn => { :asn => 'AS20001',
198 | :domain => 'twcable.com',
199 | :name => 'Time Warner Cable Internet LLC',
200 | :route => '104.172.0.0/14',
201 | :type => 'isp'},
202 | :city => 'Los Angeles',
203 | :company => { :domain => 'twcable.com',
204 | :name => 'Time Warner Cable Internet LLC',
205 | :type => 'isp'},
206 | :country => 'US',
207 | :country_name => 'United States',
208 | :hostname => 'cpe-104-175-221-247.socal.res.rr.com',
209 | :ip => '104.175.221.247',
210 | :ip_address => ,
211 | :loc => '34.0293,-118.3570',
212 | :latitude => '34.0293',
213 | :longitude => '-118.3570',
214 | :phone => '323',
215 | :postal => '90016',
216 | :region => 'California'
217 | }
218 | ```
219 |
220 | #### Caching
221 |
222 | In-memory caching of `details` data is provided by default via the
223 | [`lru_redux`](https://github.com/SamSaffron/lru_redux) gem. This uses an LRU
224 | (least recently used) cache with a TTL (time to live) by default. This means
225 | that values will be cached for the specified duration; if the cache's max size
226 | is reached, cache values will be invalidated as necessary, starting with the
227 | oldest cached value.
228 |
229 | ##### Modifying cache options
230 |
231 | Cache behavior can be modified by setting the `cache_options` keyword argument.
232 | `cache_options` is a dictionary in which the keys are keyword arguments
233 | specified in the `cachetools` library. The nesting of keyword arguments is to
234 | prevent name collisions between this library and its dependencies.
235 |
236 | * Default maximum cache size: 4096 (multiples of 2 are recommended to increase
237 | efficiency)
238 | * Default TTL: 24 hours (in seconds)
239 |
240 | ```ruby
241 | token = '1234'
242 | handler = IPinfo::create(token, {:ttl => 30, :maxsize => 30})
243 | ```
244 |
245 | ##### Using a different cache
246 |
247 | It's possible to use a custom cache by creating a child class of the
248 | [CacheInterface](https://github.com/jhtimmins/ruby/blob/master/lib/ipinfo/cache/cache_interface.rb)
249 | class and passing this into the handler object with the `cache` keyword
250 | argument. FYI this is known as
251 | [the Strategy Pattern](https://sourcemaking.com/design_patterns/strategy).
252 |
253 | ```ruby
254 | handler = IPinfo.handler(token, {:cache => my_fancy_custom_class})
255 | ```
256 |
257 | ### Using a different HTTP library
258 |
259 | Ruby is notorious for having lots of HTTP libraries. While `Net::HTTP` is a
260 | reasonable default, you can set any other that
261 | [Faradaysupports](https://github.com/lostisland/faraday/tree/29feeb92e3413d38ffc1fd3a3479bb48a0915730#faraday)
262 | if you prefer.
263 |
264 | ```ruby
265 | access_token = '123456789abc'
266 | handler = IPinfo::create(access_token, {:http_client => my_client})
267 | ```
268 |
269 | Don't forget to bundle the custom HTTP library as well.
270 |
271 | #### Internationalization
272 |
273 | When looking up an IP address, the response object includes a
274 | `details.country_name` attribute which includes the country name based on
275 | American English. It is possible to return the country name in other languages
276 | by setting the `countries` setting when creating the `IPinfo` object.
277 |
278 | ```
279 | {
280 | "BD" => "Bangladesh",
281 | "BE" => "Belgium",
282 | "BF" => "Burkina Faso",
283 | "BG" => "Bulgaria"
284 | ...
285 | }
286 | ```
287 |
288 | ### Other Libraries
289 |
290 | There 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.
291 |
292 | ### About IPinfo
293 |
294 | Founded 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.
295 |
296 | [](https://ipinfo.io/)
297 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'bundler/gem_tasks'
4 | require 'rake/testtask'
5 |
6 | Rake::TestTask.new(:test) do |t|
7 | t.libs << 'test'
8 | t.libs << 'lib'
9 | t.test_files = FileList['test/**/*_test.rb']
10 | end
11 |
12 | task default: :test
13 |
--------------------------------------------------------------------------------
/bin/console:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | # frozen_string_literal: true
3 |
4 | require 'bundler/setup'
5 | require 'ipinfo'
6 |
7 | require 'irb'
8 | IRB.start
9 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | set -euo pipefail
4 | IFS=$'\n\t'
5 | set -vx
6 |
7 | bundle install
8 |
--------------------------------------------------------------------------------
/ipinfo.gemspec:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | lib = File.expand_path('lib', __dir__)
4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5 |
6 | require 'ipinfo/version'
7 |
8 | Gem::Specification.new do |spec|
9 | spec.name = 'IPinfo'
10 | spec.version = IPinfo::VERSION
11 | spec.required_ruby_version = '>= 2.5.0'
12 | spec.authors = ['IPinfo releases']
13 | spec.email = ['releases@ipinfo.io']
14 |
15 | spec.summary = ' This is a ruby wrapper for http://ipinfo.io. '
16 | spec.description = ' This is a ruby wrapper for http://ipinfo.io. '
17 | spec.homepage = 'https://ipinfo.io'
18 |
19 | spec.add_runtime_dependency 'faraday', '~> 2.0'
20 | # add development dependency to test against faraday adapters that are been moved out the gem
21 | spec.add_development_dependency 'async-http-faraday'
22 | spec.add_development_dependency 'faraday-net_http_persistent', '~> 2.0'
23 | spec.add_development_dependency 'faraday-typhoeus', '~> 1.0'
24 | spec.add_development_dependency 'faraday-patron', '~> 2.0'
25 | spec.add_development_dependency 'faraday-httpclient', '~> 2.0'
26 | spec.add_development_dependency 'faraday-excon', '~> 2.1'
27 |
28 | spec.add_runtime_dependency 'json', '~> 2.1'
29 | spec.add_runtime_dependency 'lru_redux', '~> 1.1'
30 |
31 | spec.files = `git ls-files -z`.split("\x0").reject do |f|
32 | f.match(%r{^(test|spec|features)/})
33 | end
34 | spec.bindir = 'exe'
35 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36 | spec.require_paths = ['lib']
37 | end
38 |
--------------------------------------------------------------------------------
/lib/ipinfo.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'cgi'
4 | require 'ipaddr'
5 | require 'ipinfo/adapter'
6 | require 'ipinfo/cache/default_cache'
7 | require 'ipinfo/errors'
8 | require 'ipinfo/response'
9 | require 'ipinfo/version'
10 | require 'json'
11 | require_relative 'ipinfo/ipAddressMatcher'
12 | require_relative 'ipinfo/countriesData'
13 |
14 | module IPinfo
15 | include CountriesData
16 | DEFAULT_CACHE_MAXSIZE = 4096
17 | DEFAULT_CACHE_TTL = 60 * 60 * 24
18 | RATE_LIMIT_MESSAGE = 'To increase your limits, please review our ' \
19 | 'paid plans at https://ipinfo.io/pricing'
20 | # Base URL to get country flag image link.
21 | # "PK" -> "https://cdn.ipinfo.io/static/images/countries-flags/PK.svg"
22 | COUNTRY_FLAGS_URL = "https://cdn.ipinfo.io/static/images/countries-flags/"
23 |
24 | class << self
25 | def create(access_token = nil, settings = {})
26 | IPinfo.new(access_token, settings)
27 | end
28 | end
29 | end
30 |
31 | class IPinfo::IPinfo
32 | include IPinfo
33 | attr_accessor :access_token, :countries, :httpc
34 |
35 | def initialize(access_token = nil, settings = {})
36 | @access_token = access_token
37 | prepare_http_client(settings.fetch('http_client', nil))
38 |
39 | maxsize = settings.fetch('maxsize', DEFAULT_CACHE_MAXSIZE)
40 | ttl = settings.fetch('ttl', DEFAULT_CACHE_TTL)
41 | @cache = settings.fetch('cache', DefaultCache.new(ttl, maxsize))
42 | @countries = settings.fetch('countries', DEFAULT_COUNTRY_LIST)
43 | @eu_countries = settings.fetch('eu_countries', DEFAULT_EU_COUNTRIES_LIST)
44 | @countries_flags = settings.fetch('countries_flags', DEFAULT_COUNTRIES_FLAG_LIST)
45 | @countries_currencies = settings.fetch('countries_currencies', DEFAULT_COUNTRIES_CURRENCIES_LIST)
46 | @continents = settings.fetch('continents', DEFAULT_CONTINENT_LIST)
47 | end
48 |
49 | def details(ip_address = nil)
50 | details_base(ip_address, :v4)
51 | end
52 |
53 | def details_v6(ip_address = nil)
54 | details_base(ip_address, :v6)
55 | end
56 |
57 | def get_map_url(ips)
58 | if !ips.kind_of?(Array)
59 | return JSON.generate({:error => 'Invalid input. Array required!'})
60 | end
61 | if ips.length > 500000
62 | return JSON.generate({:error => 'No more than 500,000 ips allowed!'})
63 | end
64 |
65 | json_ips = JSON.generate({:ips => ips})
66 | res = @httpc.post('/tools/map', json_ips)
67 |
68 | obj = JSON.parse(res.body)
69 | obj['reportUrl']
70 | end
71 |
72 | def batch_requests(url_array, api_token)
73 | result = Hash.new
74 | lookup_ips = []
75 |
76 | url_array.each { |url|
77 | ip = @cache.get(cache_key(url))
78 |
79 | unless ip.nil?
80 | result.store(url, ip)
81 | else
82 | lookup_ips << url
83 | end
84 | }
85 |
86 | if lookup_ips.empty?
87 | return result
88 | end
89 |
90 | begin
91 | lookup_ips.each_slice(1000){ |ips|
92 | json_arr = JSON.generate(lookup_ips)
93 | res = @httpc.post("/batch?token=#{api_token}", json_arr, 5)
94 |
95 | raise StandardError, "Request Quota Exceeded" if res.status == 429
96 |
97 | data = JSON.parse(res.body)
98 | data.each { |key, val|
99 | @cache.set(cache_key(key), val)
100 | }
101 |
102 | result.merge!(data)
103 | }
104 |
105 | rescue StandardError => e
106 | return e.message
107 | end
108 |
109 | result
110 | end
111 |
112 | protected
113 |
114 | def prepare_http_client(httpc = nil)
115 | @httpc = Adapter.new(access_token, httpc || :net_http)
116 | end
117 |
118 | private
119 |
120 | def request_details(ip_address = nil, host_type)
121 | if isBogon(ip_address)
122 | details[:ip] = ip_address
123 | details[:bogon] = true
124 | details[:ip_address] = IPAddr.new(ip_address)
125 |
126 | return details
127 | end
128 |
129 | res = @cache.get(cache_key(ip_address))
130 | return res unless res.nil?
131 |
132 | response = @httpc.get(escape_path(ip_address), host_type)
133 |
134 | if response.status.eql?(429)
135 | raise RateLimitError,
136 | RATE_LIMIT_MESSAGE
137 | end
138 |
139 | details = JSON.parse(response.body, symbolize_names: true)
140 | @cache.set(cache_key(ip_address), details)
141 | details
142 | end
143 |
144 | def details_base(ip_address, host_type)
145 | details = request_details(ip_address, host_type)
146 | if details.key? :country
147 | details[:country_name] =
148 | @countries.fetch(details.fetch(:country), nil)
149 | details[:is_eu] =
150 | @eu_countries.include?(details.fetch(:country))
151 | details[:country_flag] =
152 | @countries_flags.fetch(details.fetch(:country), nil)
153 | details[:country_currency] =
154 | @countries_currencies.fetch(details.fetch(:country), nil)
155 | details[:continent] =
156 | @continents.fetch(details.fetch(:country), nil)
157 | details[:country_flag_url] = COUNTRY_FLAGS_URL + details.fetch(:country) + ".svg"
158 | end
159 |
160 | if details.key? :ip
161 | details[:ip_address] =
162 | IPAddr.new(details.fetch(:ip))
163 | end
164 |
165 | if details.key? :loc
166 | loc = details.fetch(:loc).split(',')
167 | details[:latitude] = loc[0]
168 | details[:longitude] = loc[1]
169 | end
170 |
171 | Response.new(details)
172 | end
173 |
174 | def isBogon(ip)
175 | if ip.nil?
176 | return false
177 | end
178 |
179 | matcher_object = IpAddressMatcher.new(ip)
180 | matcher_object.matches
181 | end
182 |
183 | def escape_path(ip)
184 | ip ? "/#{CGI.escape(ip)}" : '/'
185 | end
186 |
187 | def cache_key(ip)
188 | "1:#{ip}"
189 | end
190 | end
191 |
--------------------------------------------------------------------------------
/lib/ipinfo/adapter.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'faraday'
4 | require 'cgi'
5 | require 'ipinfo/mod'
6 | require_relative './version.rb'
7 |
8 | class IPinfo::Adapter
9 | HOST = 'https://ipinfo.io'
10 | HOST_V6 = 'https://v6.ipinfo.io'
11 |
12 | attr_reader :conn
13 |
14 | def initialize(token = nil, adapter = :net_http)
15 | @token = token
16 | @conn = connection(adapter)
17 | end
18 |
19 | def get(uri, host_type= :v4)
20 | host = (host_type == :v6) ? HOST_V6 : HOST
21 | @conn.get(host + uri) do |req|
22 | default_headers.each_pair do |key, value|
23 | req.headers[key] = value
24 | end
25 | req.params['token'] = CGI.escape(token) if token
26 | end
27 | end
28 |
29 | def post(uri, body, timeout = 2)
30 | @conn.post(HOST + uri) do |req|
31 | req.body = body
32 | req.options.timeout = timeout
33 | end
34 | end
35 |
36 | private
37 |
38 | attr_reader :token
39 |
40 | def connection(adapter)
41 | Faraday.new() do |conn|
42 | conn.adapter(adapter)
43 | end
44 | end
45 |
46 | def default_headers
47 | headers = {
48 | 'User-Agent' => "IPinfoClient/Ruby/#{IPinfo::VERSION}",
49 | 'Accept' => 'application/json'
50 | }
51 | headers['Authorization'] = "Bearer #{CGI.escape(token)}" if token
52 | headers
53 | end
54 | end
55 |
--------------------------------------------------------------------------------
/lib/ipinfo/cache/cache_interface.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class IPinfo::CacheInterface
4 | class InterfaceNotImplemented < StandardError; end
5 |
6 | def get(_key)
7 | raise InterfaceNotImplemented
8 | end
9 |
10 | def set(_key, _value)
11 | raise InterfaceNotImplemented
12 | end
13 |
14 | def contains?(_key)
15 | raise InterfaceNotImplemented
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/lib/ipinfo/cache/default_cache.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'ipinfo/cache/cache_interface'
4 | require 'lru_redux'
5 |
6 | class IPinfo::DefaultCache < IPinfo::CacheInterface
7 | def initialize(ttl, max_size)
8 | @cache = LruRedux::TTL::Cache.new(max_size, ttl)
9 | end
10 |
11 | def get(key)
12 | @cache[key]
13 | end
14 |
15 | def set(key, value)
16 | @cache[key] = value
17 | end
18 |
19 | def contains?(key)
20 | !@cache[key].nil?
21 | end
22 | end
23 |
--------------------------------------------------------------------------------
/lib/ipinfo/countriesData.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module CountriesData
4 | DEFAULT_COUNTRY_LIST = {
5 | "BD" => "Bangladesh",
6 | "BE" => "Belgium",
7 | "BF" => "Burkina Faso",
8 | "BG" => "Bulgaria",
9 | "BA" => "Bosnia and Herzegovina",
10 | "BB" => "Barbados",
11 | "WF" => "Wallis and Futuna",
12 | "BL" => "Saint Barthelemy",
13 | "BM" => "Bermuda",
14 | "BN" => "Brunei",
15 | "BO" => "Bolivia",
16 | "BH" => "Bahrain",
17 | "BI" => "Burundi",
18 | "BJ" => "Benin",
19 | "BT" => "Bhutan",
20 | "JM" => "Jamaica",
21 | "BV" => "Bouvet Island",
22 | "BW" => "Botswana",
23 | "WS" => "Samoa",
24 | "BQ" => "Bonaire, Saint Eustatius and Saba ",
25 | "BR" => "Brazil",
26 | "BS" => "Bahamas",
27 | "JE" => "Jersey",
28 | "BY" => "Belarus",
29 | "BZ" => "Belize",
30 | "RU" => "Russia",
31 | "RW" => "Rwanda",
32 | "RS" => "Serbia",
33 | "TL" => "East Timor",
34 | "RE" => "Reunion",
35 | "TM" => "Turkmenistan",
36 | "TJ" => "Tajikistan",
37 | "RO" => "Romania",
38 | "TK" => "Tokelau",
39 | "GW" => "Guinea-Bissau",
40 | "GU" => "Guam",
41 | "GT" => "Guatemala",
42 | "GS" => "South Georgia and the South Sandwich Islands",
43 | "GR" => "Greece",
44 | "GQ" => "Equatorial Guinea",
45 | "GP" => "Guadeloupe",
46 | "JP" => "Japan",
47 | "GY" => "Guyana",
48 | "GG" => "Guernsey",
49 | "GF" => "French Guiana",
50 | "GE" => "Georgia",
51 | "GD" => "Grenada",
52 | "GB" => "United Kingdom",
53 | "GA" => "Gabon",
54 | "SV" => "El Salvador",
55 | "GN" => "Guinea",
56 | "GM" => "Gambia",
57 | "GL" => "Greenland",
58 | "GI" => "Gibraltar",
59 | "GH" => "Ghana",
60 | "OM" => "Oman",
61 | "TN" => "Tunisia",
62 | "JO" => "Jordan",
63 | "HR" => "Croatia",
64 | "HT" => "Haiti",
65 | "HU" => "Hungary",
66 | "HK" => "Hong Kong",
67 | "HN" => "Honduras",
68 | "HM" => "Heard Island and McDonald Islands",
69 | "VE" => "Venezuela",
70 | "PR" => "Puerto Rico",
71 | "PS" => "Palestinian Territory",
72 | "PW" => "Palau",
73 | "PT" => "Portugal",
74 | "SJ" => "Svalbard and Jan Mayen",
75 | "PY" => "Paraguay",
76 | "IQ" => "Iraq",
77 | "PA" => "Panama",
78 | "PF" => "French Polynesia",
79 | "PG" => "Papua New Guinea",
80 | "PE" => "Peru",
81 | "PK" => "Pakistan",
82 | "PH" => "Philippines",
83 | "PN" => "Pitcairn",
84 | "PL" => "Poland",
85 | "PM" => "Saint Pierre and Miquelon",
86 | "ZM" => "Zambia",
87 | "EH" => "Western Sahara",
88 | "EE" => "Estonia",
89 | "EG" => "Egypt",
90 | "ZA" => "South Africa",
91 | "EC" => "Ecuador",
92 | "IT" => "Italy",
93 | "VN" => "Vietnam",
94 | "SB" => "Solomon Islands",
95 | "ET" => "Ethiopia",
96 | "SO" => "Somalia",
97 | "ZW" => "Zimbabwe",
98 | "SA" => "Saudi Arabia",
99 | "ES" => "Spain",
100 | "ER" => "Eritrea",
101 | "ME" => "Montenegro",
102 | "MD" => "Moldova",
103 | "MG" => "Madagascar",
104 | "MF" => "Saint Martin",
105 | "MA" => "Morocco",
106 | "MC" => "Monaco",
107 | "UZ" => "Uzbekistan",
108 | "MM" => "Myanmar",
109 | "ML" => "Mali",
110 | "MO" => "Macao",
111 | "MN" => "Mongolia",
112 | "MH" => "Marshall Islands",
113 | "MK" => "Macedonia",
114 | "MU" => "Mauritius",
115 | "MT" => "Malta",
116 | "MW" => "Malawi",
117 | "MV" => "Maldives",
118 | "MQ" => "Martinique",
119 | "MP" => "Northern Mariana Islands",
120 | "MS" => "Montserrat",
121 | "MR" => "Mauritania",
122 | "IM" => "Isle of Man",
123 | "UG" => "Uganda",
124 | "TZ" => "Tanzania",
125 | "MY" => "Malaysia",
126 | "MX" => "Mexico",
127 | "IL" => "Israel",
128 | "FR" => "France",
129 | "IO" => "British Indian Ocean Territory",
130 | "SH" => "Saint Helena",
131 | "FI" => "Finland",
132 | "FJ" => "Fiji",
133 | "FK" => "Falkland Islands",
134 | "FM" => "Micronesia",
135 | "FO" => "Faroe Islands",
136 | "NI" => "Nicaragua",
137 | "NL" => "Netherlands",
138 | "NO" => "Norway",
139 | "NA" => "Namibia",
140 | "VU" => "Vanuatu",
141 | "NC" => "New Caledonia",
142 | "NE" => "Niger",
143 | "NF" => "Norfolk Island",
144 | "NG" => "Nigeria",
145 | "NZ" => "New Zealand",
146 | "NP" => "Nepal",
147 | "NR" => "Nauru",
148 | "NU" => "Niue",
149 | "CK" => "Cook Islands",
150 | "XK" => "Kosovo",
151 | "CI" => "Ivory Coast",
152 | "CH" => "Switzerland",
153 | "CO" => "Colombia",
154 | "CN" => "China",
155 | "CM" => "Cameroon",
156 | "CL" => "Chile",
157 | "CC" => "Cocos Islands",
158 | "CA" => "Canada",
159 | "CG" => "Republic of the Congo",
160 | "CF" => "Central African Republic",
161 | "CD" => "Democratic Republic of the Congo",
162 | "CZ" => "Czech Republic",
163 | "CY" => "Cyprus",
164 | "CX" => "Christmas Island",
165 | "CR" => "Costa Rica",
166 | "CW" => "Curacao",
167 | "CV" => "Cape Verde",
168 | "CU" => "Cuba",
169 | "SZ" => "Swaziland",
170 | "SY" => "Syria",
171 | "SX" => "Sint Maarten",
172 | "KG" => "Kyrgyzstan",
173 | "KE" => "Kenya",
174 | "SS" => "South Sudan",
175 | "SR" => "Suriname",
176 | "KI" => "Kiribati",
177 | "KH" => "Cambodia",
178 | "KN" => "Saint Kitts and Nevis",
179 | "KM" => "Comoros",
180 | "ST" => "Sao Tome and Principe",
181 | "SK" => "Slovakia",
182 | "KR" => "South Korea",
183 | "SI" => "Slovenia",
184 | "KP" => "North Korea",
185 | "KW" => "Kuwait",
186 | "SN" => "Senegal",
187 | "SM" => "San Marino",
188 | "SL" => "Sierra Leone",
189 | "SC" => "Seychelles",
190 | "KZ" => "Kazakhstan",
191 | "KY" => "Cayman Islands",
192 | "SG" => "Singapore",
193 | "SE" => "Sweden",
194 | "SD" => "Sudan",
195 | "DO" => "Dominican Republic",
196 | "DM" => "Dominica",
197 | "DJ" => "Djibouti",
198 | "DK" => "Denmark",
199 | "VG" => "British Virgin Islands",
200 | "DE" => "Germany",
201 | "YE" => "Yemen",
202 | "DZ" => "Algeria",
203 | "US" => "United States",
204 | "UY" => "Uruguay",
205 | "YT" => "Mayotte",
206 | "UM" => "United States Minor Outlying Islands",
207 | "LB" => "Lebanon",
208 | "LC" => "Saint Lucia",
209 | "LA" => "Laos",
210 | "TV" => "Tuvalu",
211 | "TW" => "Taiwan",
212 | "TT" => "Trinidad and Tobago",
213 | "TR" => "Turkey",
214 | "LK" => "Sri Lanka",
215 | "LI" => "Liechtenstein",
216 | "LV" => "Latvia",
217 | "TO" => "Tonga",
218 | "LT" => "Lithuania",
219 | "LU" => "Luxembourg",
220 | "LR" => "Liberia",
221 | "LS" => "Lesotho",
222 | "TH" => "Thailand",
223 | "TF" => "French Southern Territories",
224 | "TG" => "Togo",
225 | "TD" => "Chad",
226 | "TC" => "Turks and Caicos Islands",
227 | "LY" => "Libya",
228 | "VA" => "Vatican",
229 | "VC" => "Saint Vincent and the Grenadines",
230 | "AE" => "United Arab Emirates",
231 | "AD" => "Andorra",
232 | "AG" => "Antigua and Barbuda",
233 | "AF" => "Afghanistan",
234 | "AI" => "Anguilla",
235 | "VI" => "U.S. Virgin Islands",
236 | "IS" => "Iceland",
237 | "IR" => "Iran",
238 | "AM" => "Armenia",
239 | "AL" => "Albania",
240 | "AO" => "Angola",
241 | "AQ" => "Antarctica",
242 | "AS" => "American Samoa",
243 | "AR" => "Argentina",
244 | "AU" => "Australia",
245 | "AT" => "Austria",
246 | "AW" => "Aruba",
247 | "IN" => "India",
248 | "AX" => "Aland Islands",
249 | "AZ" => "Azerbaijan",
250 | "IE" => "Ireland",
251 | "ID" => "Indonesia",
252 | "UA" => "Ukraine",
253 | "QA" => "Qatar",
254 | "MZ" => "Mozambique"
255 | }
256 |
257 | DEFAULT_EU_COUNTRIES_LIST = [
258 | "IE",
259 | "AT",
260 | "LT",
261 | "LU",
262 | "LV",
263 | "DE",
264 | "DK",
265 | "SE",
266 | "SI",
267 | "SK",
268 | "CZ",
269 | "CY",
270 | "NL",
271 | "FI",
272 | "FR",
273 | "MT",
274 | "ES",
275 | "IT",
276 | "EE",
277 | "PL",
278 | "PT",
279 | "HU",
280 | "HR",
281 | "GR",
282 | "RO",
283 | "BG",
284 | "BE"
285 | ]
286 |
287 | DEFAULT_COUNTRIES_FLAG_LIST = {
288 | "AD" => {"emoji" => "🇦🇩","unicode" => "U+1F1E6 U+1F1E9"},
289 | "AE" => {"emoji" => "🇦🇪","unicode" => "U+1F1E6 U+1F1EA"},
290 | "AF" => {"emoji" => "🇦🇫","unicode" => "U+1F1E6 U+1F1EB"},
291 | "AG" => {"emoji" => "🇦🇬","unicode" => "U+1F1E6 U+1F1EC"},
292 | "AI" => {"emoji" => "🇦🇮","unicode" => "U+1F1E6 U+1F1EE"},
293 | "AL" => {"emoji" => "🇦🇱","unicode" => "U+1F1E6 U+1F1F1"},
294 | "AM" => {"emoji" => "🇦🇲","unicode" => "U+1F1E6 U+1F1F2"},
295 | "AO" => {"emoji" => "🇦🇴","unicode" => "U+1F1E6 U+1F1F4"},
296 | "AQ" => {"emoji" => "🇦🇶","unicode" => "U+1F1E6 U+1F1F6"},
297 | "AR" => {"emoji" => "🇦🇷","unicode" => "U+1F1E6 U+1F1F7"},
298 | "AS" => {"emoji" => "🇦🇸","unicode" => "U+1F1E6 U+1F1F8"},
299 | "AT" => {"emoji" => "🇦🇹","unicode" => "U+1F1E6 U+1F1F9"},
300 | "AU" => {"emoji" => "🇦🇺","unicode" => "U+1F1E6 U+1F1FA"},
301 | "AW" => {"emoji" => "🇦🇼","unicode" => "U+1F1E6 U+1F1FC"},
302 | "AX" => {"emoji" => "🇦🇽","unicode" => "U+1F1E6 U+1F1FD"},
303 | "AZ" => {"emoji" => "🇦🇿","unicode" => "U+1F1E6 U+1F1FF"},
304 | "BA" => {"emoji" => "🇧🇦","unicode" => "U+1F1E7 U+1F1E6"},
305 | "BB" => {"emoji" => "🇧🇧","unicode" => "U+1F1E7 U+1F1E7"},
306 | "BD" => {"emoji" => "🇧🇩","unicode" => "U+1F1E7 U+1F1E9"},
307 | "BE" => {"emoji" => "🇧🇪","unicode" => "U+1F1E7 U+1F1EA"},
308 | "BF" => {"emoji" => "🇧🇫","unicode" => "U+1F1E7 U+1F1EB"},
309 | "BG" => {"emoji" => "🇧🇬","unicode" => "U+1F1E7 U+1F1EC"},
310 | "BH" => {"emoji" => "🇧🇭","unicode" => "U+1F1E7 U+1F1ED"},
311 | "BI" => {"emoji" => "🇧🇮","unicode" => "U+1F1E7 U+1F1EE"},
312 | "BJ" => {"emoji" => "🇧🇯","unicode" => "U+1F1E7 U+1F1EF"},
313 | "BL" => {"emoji" => "🇧🇱","unicode" => "U+1F1E7 U+1F1F1"},
314 | "BM" => {"emoji" => "🇧🇲","unicode" => "U+1F1E7 U+1F1F2"},
315 | "BN" => {"emoji" => "🇧🇳","unicode" => "U+1F1E7 U+1F1F3"},
316 | "BO" => {"emoji" => "🇧🇴","unicode" => "U+1F1E7 U+1F1F4"},
317 | "BQ" => {"emoji" => "🇧🇶","unicode" => "U+1F1E7 U+1F1F6"},
318 | "BR" => {"emoji" => "🇧🇷","unicode" => "U+1F1E7 U+1F1F7"},
319 | "BS" => {"emoji" => "🇧🇸","unicode" => "U+1F1E7 U+1F1F8"},
320 | "BT" => {"emoji" => "🇧🇹","unicode" => "U+1F1E7 U+1F1F9"},
321 | "BV" => {"emoji" => "🇧🇻","unicode" => "U+1F1E7 U+1F1FB"},
322 | "BW" => {"emoji" => "🇧🇼","unicode" => "U+1F1E7 U+1F1FC"},
323 | "BY" => {"emoji" => "🇧🇾","unicode" => "U+1F1E7 U+1F1FE"},
324 | "BZ" => {"emoji" => "🇧🇿","unicode" => "U+1F1E7 U+1F1FF"},
325 | "CA" => {"emoji" => "🇨🇦","unicode" => "U+1F1E8 U+1F1E6"},
326 | "CC" => {"emoji" => "🇨🇨","unicode" => "U+1F1E8 U+1F1E8"},
327 | "CD" => {"emoji" => "🇨🇩","unicode" => "U+1F1E8 U+1F1E9"},
328 | "CF" => {"emoji" => "🇨🇫","unicode" => "U+1F1E8 U+1F1EB"},
329 | "CG" => {"emoji" => "🇨🇬","unicode" => "U+1F1E8 U+1F1EC"},
330 | "CH" => {"emoji" => "🇨🇭","unicode" => "U+1F1E8 U+1F1ED"},
331 | "CI" => {"emoji" => "🇨🇮","unicode" => "U+1F1E8 U+1F1EE"},
332 | "CK" => {"emoji" => "🇨🇰","unicode" => "U+1F1E8 U+1F1F0"},
333 | "CL" => {"emoji" => "🇨🇱","unicode" => "U+1F1E8 U+1F1F1"},
334 | "CM" => {"emoji" => "🇨🇲","unicode" => "U+1F1E8 U+1F1F2"},
335 | "CN" => {"emoji" => "🇨🇳","unicode" => "U+1F1E8 U+1F1F3"},
336 | "CO" => {"emoji" => "🇨🇴","unicode" => "U+1F1E8 U+1F1F4"},
337 | "CR" => {"emoji" => "🇨🇷","unicode" => "U+1F1E8 U+1F1F7"},
338 | "CU" => {"emoji" => "🇨🇺","unicode" => "U+1F1E8 U+1F1FA"},
339 | "CV" => {"emoji" => "🇨🇻","unicode" => "U+1F1E8 U+1F1FB"},
340 | "CW" => {"emoji" => "🇨🇼","unicode" => "U+1F1E8 U+1F1FC"},
341 | "CX" => {"emoji" => "🇨🇽","unicode" => "U+1F1E8 U+1F1FD"},
342 | "CY" => {"emoji" => "🇨🇾","unicode" => "U+1F1E8 U+1F1FE"},
343 | "CZ" => {"emoji" => "🇨🇿","unicode" => "U+1F1E8 U+1F1FF"},
344 | "DE" => {"emoji" => "🇩🇪","unicode" => "U+1F1E9 U+1F1EA"},
345 | "DJ" => {"emoji" => "🇩🇯","unicode" => "U+1F1E9 U+1F1EF"},
346 | "DK" => {"emoji" => "🇩🇰","unicode" => "U+1F1E9 U+1F1F0"},
347 | "DM" => {"emoji" => "🇩🇲","unicode" => "U+1F1E9 U+1F1F2"},
348 | "DO" => {"emoji" => "🇩🇴","unicode" => "U+1F1E9 U+1F1F4"},
349 | "DZ" => {"emoji" => "🇩🇿","unicode" => "U+1F1E9 U+1F1FF"},
350 | "EC" => {"emoji" => "🇪🇨","unicode" => "U+1F1EA U+1F1E8"},
351 | "EE" => {"emoji" => "🇪🇪","unicode" => "U+1F1EA U+1F1EA"},
352 | "EG" => {"emoji" => "🇪🇬","unicode" => "U+1F1EA U+1F1EC"},
353 | "EH" => {"emoji" => "🇪🇭","unicode" => "U+1F1EA U+1F1ED"},
354 | "ER" => {"emoji" => "🇪🇷","unicode" => "U+1F1EA U+1F1F7"},
355 | "ES" => {"emoji" => "🇪🇸","unicode" => "U+1F1EA U+1F1F8"},
356 | "ET" => {"emoji" => "🇪🇹","unicode" => "U+1F1EA U+1F1F9"},
357 | "FI" => {"emoji" => "🇫🇮","unicode" => "U+1F1EB U+1F1EE"},
358 | "FJ" => {"emoji" => "🇫🇯","unicode" => "U+1F1EB U+1F1EF"},
359 | "FK" => {"emoji" => "🇫🇰","unicode" => "U+1F1EB U+1F1F0"},
360 | "FM" => {"emoji" => "🇫🇲","unicode" => "U+1F1EB U+1F1F2"},
361 | "FO" => {"emoji" => "🇫🇴","unicode" => "U+1F1EB U+1F1F4"},
362 | "FR" => {"emoji" => "🇫🇷","unicode" => "U+1F1EB U+1F1F7"},
363 | "GA" => {"emoji" => "🇬🇦","unicode" => "U+1F1EC U+1F1E6"},
364 | "GB" => {"emoji" => "🇬🇧","unicode" => "U+1F1EC U+1F1E7"},
365 | "GD" => {"emoji" => "🇬🇩","unicode" => "U+1F1EC U+1F1E9"},
366 | "GE" => {"emoji" => "🇬🇪","unicode" => "U+1F1EC U+1F1EA"},
367 | "GF" => {"emoji" => "🇬🇫","unicode" => "U+1F1EC U+1F1EB"},
368 | "GG" => {"emoji" => "🇬🇬","unicode" => "U+1F1EC U+1F1EC"},
369 | "GH" => {"emoji" => "🇬🇭","unicode" => "U+1F1EC U+1F1ED"},
370 | "GI" => {"emoji" => "🇬🇮","unicode" => "U+1F1EC U+1F1EE"},
371 | "GL" => {"emoji" => "🇬🇱","unicode" => "U+1F1EC U+1F1F1"},
372 | "GM" => {"emoji" => "🇬🇲","unicode" => "U+1F1EC U+1F1F2"},
373 | "GN" => {"emoji" => "🇬🇳","unicode" => "U+1F1EC U+1F1F3"},
374 | "GP" => {"emoji" => "🇬🇵","unicode" => "U+1F1EC U+1F1F5"},
375 | "GQ" => {"emoji" => "🇬🇶","unicode" => "U+1F1EC U+1F1F6"},
376 | "GR" => {"emoji" => "🇬🇷","unicode" => "U+1F1EC U+1F1F7"},
377 | "GS" => {"emoji" => "🇬🇸","unicode" => "U+1F1EC U+1F1F8"},
378 | "GT" => {"emoji" => "🇬🇹","unicode" => "U+1F1EC U+1F1F9"},
379 | "GU" => {"emoji" => "🇬🇺","unicode" => "U+1F1EC U+1F1FA"},
380 | "GW" => {"emoji" => "🇬🇼","unicode" => "U+1F1EC U+1F1FC"},
381 | "GY" => {"emoji" => "🇬🇾","unicode" => "U+1F1EC U+1F1FE"},
382 | "HK" => {"emoji" => "🇭🇰","unicode" => "U+1F1ED U+1F1F0"},
383 | "HM" => {"emoji" => "🇭🇲","unicode" => "U+1F1ED U+1F1F2"},
384 | "HN" => {"emoji" => "🇭🇳","unicode" => "U+1F1ED U+1F1F3"},
385 | "HR" => {"emoji" => "🇭🇷","unicode" => "U+1F1ED U+1F1F7"},
386 | "HT" => {"emoji" => "🇭🇹","unicode" => "U+1F1ED U+1F1F9"},
387 | "HU" => {"emoji" => "🇭🇺","unicode" => "U+1F1ED U+1F1FA"},
388 | "ID" => {"emoji" => "🇮🇩","unicode" => "U+1F1EE U+1F1E9"},
389 | "IE" => {"emoji" => "🇮🇪","unicode" => "U+1F1EE U+1F1EA"},
390 | "IL" => {"emoji" => "🇮🇱","unicode" => "U+1F1EE U+1F1F1"},
391 | "IM" => {"emoji" => "🇮🇲","unicode" => "U+1F1EE U+1F1F2"},
392 | "IN" => {"emoji" => "🇮🇳","unicode" => "U+1F1EE U+1F1F3"},
393 | "IO" => {"emoji" => "🇮🇴","unicode" => "U+1F1EE U+1F1F4"},
394 | "IQ" => {"emoji" => "🇮🇶","unicode" => "U+1F1EE U+1F1F6"},
395 | "IR" => {"emoji" => "🇮🇷","unicode" => "U+1F1EE U+1F1F7"},
396 | "IS" => {"emoji" => "🇮🇸","unicode" => "U+1F1EE U+1F1F8"},
397 | "IT" => {"emoji" => "🇮🇹","unicode" => "U+1F1EE U+1F1F9"},
398 | "JE" => {"emoji" => "🇯🇪","unicode" => "U+1F1EF U+1F1EA"},
399 | "JM" => {"emoji" => "🇯🇲","unicode" => "U+1F1EF U+1F1F2"},
400 | "JO" => {"emoji" => "🇯🇴","unicode" => "U+1F1EF U+1F1F4"},
401 | "JP" => {"emoji" => "🇯🇵","unicode" => "U+1F1EF U+1F1F5"},
402 | "KE" => {"emoji" => "🇰🇪","unicode" => "U+1F1F0 U+1F1EA"},
403 | "KG" => {"emoji" => "🇰🇬","unicode" => "U+1F1F0 U+1F1EC"},
404 | "KH" => {"emoji" => "🇰🇭","unicode" => "U+1F1F0 U+1F1ED"},
405 | "KI" => {"emoji" => "🇰🇮","unicode" => "U+1F1F0 U+1F1EE"},
406 | "KM" => {"emoji" => "🇰🇲","unicode" => "U+1F1F0 U+1F1F2"},
407 | "KN" => {"emoji" => "🇰🇳","unicode" => "U+1F1F0 U+1F1F3"},
408 | "KP" => {"emoji" => "🇰🇵","unicode" => "U+1F1F0 U+1F1F5"},
409 | "KR" => {"emoji" => "🇰🇷","unicode" => "U+1F1F0 U+1F1F7"},
410 | "KW" => {"emoji" => "🇰🇼","unicode" => "U+1F1F0 U+1F1FC"},
411 | "KY" => {"emoji" => "🇰🇾","unicode" => "U+1F1F0 U+1F1FE"},
412 | "KZ" => {"emoji" => "🇰🇿","unicode" => "U+1F1F0 U+1F1FF"},
413 | "LA" => {"emoji" => "🇱🇦","unicode" => "U+1F1F1 U+1F1E6"},
414 | "LB" => {"emoji" => "🇱🇧","unicode" => "U+1F1F1 U+1F1E7"},
415 | "LC" => {"emoji" => "🇱🇨","unicode" => "U+1F1F1 U+1F1E8"},
416 | "LI" => {"emoji" => "🇱🇮","unicode" => "U+1F1F1 U+1F1EE"},
417 | "LK" => {"emoji" => "🇱🇰","unicode" => "U+1F1F1 U+1F1F0"},
418 | "LR" => {"emoji" => "🇱🇷","unicode" => "U+1F1F1 U+1F1F7"},
419 | "LS" => {"emoji" => "🇱🇸","unicode" => "U+1F1F1 U+1F1F8"},
420 | "LT" => {"emoji" => "🇱🇹","unicode" => "U+1F1F1 U+1F1F9"},
421 | "LU" => {"emoji" => "🇱🇺","unicode" => "U+1F1F1 U+1F1FA"},
422 | "LV" => {"emoji" => "🇱🇻","unicode" => "U+1F1F1 U+1F1FB"},
423 | "LY" => {"emoji" => "🇱🇾","unicode" => "U+1F1F1 U+1F1FE"},
424 | "MA" => {"emoji" => "🇲🇦","unicode" => "U+1F1F2 U+1F1E6"},
425 | "MC" => {"emoji" => "🇲🇨","unicode" => "U+1F1F2 U+1F1E8"},
426 | "MD" => {"emoji" => "🇲🇩","unicode" => "U+1F1F2 U+1F1E9"},
427 | "ME" => {"emoji" => "🇲🇪","unicode" => "U+1F1F2 U+1F1EA"},
428 | "MF" => {"emoji" => "🇲🇫","unicode" => "U+1F1F2 U+1F1EB"},
429 | "MG" => {"emoji" => "🇲🇬","unicode" => "U+1F1F2 U+1F1EC"},
430 | "MH" => {"emoji" => "🇲🇭","unicode" => "U+1F1F2 U+1F1ED"},
431 | "MK" => {"emoji" => "🇲🇰","unicode" => "U+1F1F2 U+1F1F0"},
432 | "ML" => {"emoji" => "🇲🇱","unicode" => "U+1F1F2 U+1F1F1"},
433 | "MM" => {"emoji" => "🇲🇲","unicode" => "U+1F1F2 U+1F1F2"},
434 | "MN" => {"emoji" => "🇲🇳","unicode" => "U+1F1F2 U+1F1F3"},
435 | "MO" => {"emoji" => "🇲🇴","unicode" => "U+1F1F2 U+1F1F4"},
436 | "MP" => {"emoji" => "🇲🇵","unicode" => "U+1F1F2 U+1F1F5"},
437 | "MQ" => {"emoji" => "🇲🇶","unicode" => "U+1F1F2 U+1F1F6"},
438 | "MR" => {"emoji" => "🇲🇷","unicode" => "U+1F1F2 U+1F1F7"},
439 | "MS" => {"emoji" => "🇲🇸","unicode" => "U+1F1F2 U+1F1F8"},
440 | "MT" => {"emoji" => "🇲🇹","unicode" => "U+1F1F2 U+1F1F9"},
441 | "MU" => {"emoji" => "🇲🇺","unicode" => "U+1F1F2 U+1F1FA"},
442 | "MV" => {"emoji" => "🇲🇻","unicode" => "U+1F1F2 U+1F1FB"},
443 | "MW" => {"emoji" => "🇲🇼","unicode" => "U+1F1F2 U+1F1FC"},
444 | "MX" => {"emoji" => "🇲🇽","unicode" => "U+1F1F2 U+1F1FD"},
445 | "MY" => {"emoji" => "🇲🇾","unicode" => "U+1F1F2 U+1F1FE"},
446 | "MZ" => {"emoji" => "🇲🇿","unicode" => "U+1F1F2 U+1F1FF"},
447 | "NA" => {"emoji" => "🇳🇦","unicode" => "U+1F1F3 U+1F1E6"},
448 | "NC" => {"emoji" => "🇳🇨","unicode" => "U+1F1F3 U+1F1E8"},
449 | "NE" => {"emoji" => "🇳🇪","unicode" => "U+1F1F3 U+1F1EA"},
450 | "NF" => {"emoji" => "🇳🇫","unicode" => "U+1F1F3 U+1F1EB"},
451 | "NG" => {"emoji" => "🇳🇬","unicode" => "U+1F1F3 U+1F1EC"},
452 | "NI" => {"emoji" => "🇳🇮","unicode" => "U+1F1F3 U+1F1EE"},
453 | "NL" => {"emoji" => "🇳🇱","unicode" => "U+1F1F3 U+1F1F1"},
454 | "NO" => {"emoji" => "🇳🇴","unicode" => "U+1F1F3 U+1F1F4"},
455 | "NP" => {"emoji" => "🇳🇵","unicode" => "U+1F1F3 U+1F1F5"},
456 | "NR" => {"emoji" => "🇳🇷","unicode" => "U+1F1F3 U+1F1F7"},
457 | "NU" => {"emoji" => "🇳🇺","unicode" => "U+1F1F3 U+1F1FA"},
458 | "NZ" => {"emoji" => "🇳🇿","unicode" => "U+1F1F3 U+1F1FF"},
459 | "OM" => {"emoji" => "🇴🇲","unicode" => "U+1F1F4 U+1F1F2"},
460 | "PA" => {"emoji" => "🇵🇦","unicode" => "U+1F1F5 U+1F1E6"},
461 | "PE" => {"emoji" => "🇵🇪","unicode" => "U+1F1F5 U+1F1EA"},
462 | "PF" => {"emoji" => "🇵🇫","unicode" => "U+1F1F5 U+1F1EB"},
463 | "PG" => {"emoji" => "🇵🇬","unicode" => "U+1F1F5 U+1F1EC"},
464 | "PH" => {"emoji" => "🇵🇭","unicode" => "U+1F1F5 U+1F1ED"},
465 | "PK" => {"emoji" => "🇵🇰","unicode" => "U+1F1F5 U+1F1F0"},
466 | "PL" => {"emoji" => "🇵🇱","unicode" => "U+1F1F5 U+1F1F1"},
467 | "PM" => {"emoji" => "🇵🇲","unicode" => "U+1F1F5 U+1F1F2"},
468 | "PN" => {"emoji" => "🇵🇳","unicode" => "U+1F1F5 U+1F1F3"},
469 | "PR" => {"emoji" => "🇵🇷","unicode" => "U+1F1F5 U+1F1F7"},
470 | "PS" => {"emoji" => "🇵🇸","unicode" => "U+1F1F5 U+1F1F8"},
471 | "PT" => {"emoji" => "🇵🇹","unicode" => "U+1F1F5 U+1F1F9"},
472 | "PW" => {"emoji" => "🇵🇼","unicode" => "U+1F1F5 U+1F1FC"},
473 | "PY" => {"emoji" => "🇵🇾","unicode" => "U+1F1F5 U+1F1FE"},
474 | "QA" => {"emoji" => "🇶🇦","unicode" => "U+1F1F6 U+1F1E6"},
475 | "RE" => {"emoji" => "🇷🇪","unicode" => "U+1F1F7 U+1F1EA"},
476 | "RO" => {"emoji" => "🇷🇴","unicode" => "U+1F1F7 U+1F1F4"},
477 | "RS" => {"emoji" => "🇷🇸","unicode" => "U+1F1F7 U+1F1F8"},
478 | "RU" => {"emoji" => "🇷🇺","unicode" => "U+1F1F7 U+1F1FA"},
479 | "RW" => {"emoji" => "🇷🇼","unicode" => "U+1F1F7 U+1F1FC"},
480 | "SA" => {"emoji" => "🇸🇦","unicode" => "U+1F1F8 U+1F1E6"},
481 | "SB" => {"emoji" => "🇸🇧","unicode" => "U+1F1F8 U+1F1E7"},
482 | "SC" => {"emoji" => "🇸🇨","unicode" => "U+1F1F8 U+1F1E8"},
483 | "SD" => {"emoji" => "🇸🇩","unicode" => "U+1F1F8 U+1F1E9"},
484 | "SE" => {"emoji" => "🇸🇪","unicode" => "U+1F1F8 U+1F1EA"},
485 | "SG" => {"emoji" => "🇸🇬","unicode" => "U+1F1F8 U+1F1EC"},
486 | "SH" => {"emoji" => "🇸🇭","unicode" => "U+1F1F8 U+1F1ED"},
487 | "SI" => {"emoji" => "🇸🇮","unicode" => "U+1F1F8 U+1F1EE"},
488 | "SJ" => {"emoji" => "🇸🇯","unicode" => "U+1F1F8 U+1F1EF"},
489 | "SK" => {"emoji" => "🇸🇰","unicode" => "U+1F1F8 U+1F1F0"},
490 | "SL" => {"emoji" => "🇸🇱","unicode" => "U+1F1F8 U+1F1F1"},
491 | "SM" => {"emoji" => "🇸🇲","unicode" => "U+1F1F8 U+1F1F2"},
492 | "SN" => {"emoji" => "🇸🇳","unicode" => "U+1F1F8 U+1F1F3"},
493 | "SO" => {"emoji" => "🇸🇴","unicode" => "U+1F1F8 U+1F1F4"},
494 | "SR" => {"emoji" => "🇸🇷","unicode" => "U+1F1F8 U+1F1F7"},
495 | "SS" => {"emoji" => "🇸🇸","unicode" => "U+1F1F8 U+1F1F8"},
496 | "ST" => {"emoji" => "🇸🇹","unicode" => "U+1F1F8 U+1F1F9"},
497 | "SV" => {"emoji" => "🇸🇻","unicode" => "U+1F1F8 U+1F1FB"},
498 | "SX" => {"emoji" => "🇸🇽","unicode" => "U+1F1F8 U+1F1FD"},
499 | "SY" => {"emoji" => "🇸🇾","unicode" => "U+1F1F8 U+1F1FE"},
500 | "SZ" => {"emoji" => "🇸🇿","unicode" => "U+1F1F8 U+1F1FF"},
501 | "TC" => {"emoji" => "🇹🇨","unicode" => "U+1F1F9 U+1F1E8"},
502 | "TD" => {"emoji" => "🇹🇩","unicode" => "U+1F1F9 U+1F1E9"},
503 | "TF" => {"emoji" => "🇹🇫","unicode" => "U+1F1F9 U+1F1EB"},
504 | "TG" => {"emoji" => "🇹🇬","unicode" => "U+1F1F9 U+1F1EC"},
505 | "TH" => {"emoji" => "🇹🇭","unicode" => "U+1F1F9 U+1F1ED"},
506 | "TJ" => {"emoji" => "🇹🇯","unicode" => "U+1F1F9 U+1F1EF"},
507 | "TK" => {"emoji" => "🇹🇰","unicode" => "U+1F1F9 U+1F1F0"},
508 | "TL" => {"emoji" => "🇹🇱","unicode" => "U+1F1F9 U+1F1F1"},
509 | "TM" => {"emoji" => "🇹🇲","unicode" => "U+1F1F9 U+1F1F2"},
510 | "TN" => {"emoji" => "🇹🇳","unicode" => "U+1F1F9 U+1F1F3"},
511 | "TO" => {"emoji" => "🇹🇴","unicode" => "U+1F1F9 U+1F1F4"},
512 | "TR" => {"emoji" => "🇹🇷","unicode" => "U+1F1F9 U+1F1F7"},
513 | "TT" => {"emoji" => "🇹🇹","unicode" => "U+1F1F9 U+1F1F9"},
514 | "TV" => {"emoji" => "🇹🇻","unicode" => "U+1F1F9 U+1F1FB"},
515 | "TW" => {"emoji" => "🇹🇼","unicode" => "U+1F1F9 U+1F1FC"},
516 | "TZ" => {"emoji" => "🇹🇿","unicode" => "U+1F1F9 U+1F1FF"},
517 | "UA" => {"emoji" => "🇺🇦","unicode" => "U+1F1FA U+1F1E6"},
518 | "UG" => {"emoji" => "🇺🇬","unicode" => "U+1F1FA U+1F1EC"},
519 | "UM" => {"emoji" => "🇺🇲","unicode" => "U+1F1FA U+1F1F2"},
520 | "US" => {"emoji" => "🇺🇸","unicode" => "U+1F1FA U+1F1F8"},
521 | "UY" => {"emoji" => "🇺🇾","unicode" => "U+1F1FA U+1F1FE"},
522 | "UZ" => {"emoji" => "🇺🇿","unicode" => "U+1F1FA U+1F1FF"},
523 | "VA" => {"emoji" => "🇻🇦","unicode" => "U+1F1FB U+1F1E6"},
524 | "VC" => {"emoji" => "🇻🇨","unicode" => "U+1F1FB U+1F1E8"},
525 | "VE" => {"emoji" => "🇻🇪","unicode" => "U+1F1FB U+1F1EA"},
526 | "VG" => {"emoji" => "🇻🇬","unicode" => "U+1F1FB U+1F1EC"},
527 | "VI" => {"emoji" => "🇻🇮","unicode" => "U+1F1FB U+1F1EE"},
528 | "VN" => {"emoji" => "🇻🇳","unicode" => "U+1F1FB U+1F1F3"},
529 | "VU" => {"emoji" => "🇻🇺","unicode" => "U+1F1FB U+1F1FA"},
530 | "WF" => {"emoji" => "🇼🇫","unicode" => "U+1F1FC U+1F1EB"},
531 | "WS" => {"emoji" => "🇼🇸","unicode" => "U+1F1FC U+1F1F8"},
532 | "XK" => {"emoji" => "🇽🇰","unicode" => "U+1F1FD U+1F1F0"},
533 | "YE" => {"emoji" => "🇾🇪","unicode" => "U+1F1FE U+1F1EA"},
534 | "YT" => {"emoji" => "🇾🇹","unicode" => "U+1F1FE U+1F1F9"},
535 | "ZA" => {"emoji" => "🇿🇦","unicode" => "U+1F1FF U+1F1E6"},
536 | "ZM" => {"emoji" => "🇿🇲","unicode" => "U+1F1FF U+1F1F2"},
537 | "ZW" => {"emoji" => "🇿🇼","unicode" => "U+1F1FF U+1F1FC"}
538 | }
539 |
540 | DEFAULT_COUNTRIES_CURRENCIES_LIST = {
541 | "AD" => {"code" => "EUR" ,"symbol" => "€"},
542 | "AE" => {"code" => "AED" ,"symbol" => "د.إ"},
543 | "AF" => {"code" => "AFN" ,"symbol" => "؋"},
544 | "AG" => {"code" => "XCD" ,"symbol" => "$"},
545 | "AI" => {"code" => "XCD" ,"symbol" => "$"},
546 | "AL" => {"code" => "ALL" ,"symbol" => "L"},
547 | "AM" => {"code" => "AMD" ,"symbol" => "֏"},
548 | "AO" => {"code" => "AOA" ,"symbol" => "Kz"},
549 | "AQ" => {"code" => "" ,"symbol" => "$"},
550 | "AR" => {"code" => "ARS" ,"symbol" => "$"},
551 | "AS" => {"code" => "USD" ,"symbol" => "$"},
552 | "AT" => {"code" => "EUR" ,"symbol" => "€"},
553 | "AU" => {"code" => "AUD" ,"symbol" => "$"},
554 | "AW" => {"code" => "AWG" ,"symbol" => "ƒ"},
555 | "AX" => {"code" => "EUR" ,"symbol" => "€"},
556 | "AZ" => {"code" => "AZN" ,"symbol" => "₼"},
557 | "BA" => {"code" => "BAM" ,"symbol" => "KM"},
558 | "BB" => {"code" => "BBD" ,"symbol" => "$"},
559 | "BD" => {"code" => "BDT" ,"symbol" => "৳"},
560 | "BE" => {"code" => "EUR" ,"symbol" => "€"},
561 | "BF" => {"code" => "XOF" ,"symbol" => "CFA"},
562 | "BG" => {"code" => "BGN" ,"symbol" => "лв"},
563 | "BH" => {"code" => "BHD" ,"symbol" => ".د.ب"},
564 | "BI" => {"code" => "BIF" ,"symbol" => "FBu"},
565 | "BJ" => {"code" => "XOF" ,"symbol" => "CFA"},
566 | "BL" => {"code" => "EUR" ,"symbol" => "€"},
567 | "BM" => {"code" => "BMD" ,"symbol" => "$"},
568 | "BN" => {"code" => "BND" ,"symbol" => "$"},
569 | "BO" => {"code" => "BOB" ,"symbol" => "$b"},
570 | "BQ" => {"code" => "USD" ,"symbol" => "$"},
571 | "BR" => {"code" => "BRL" ,"symbol" => "R$"},
572 | "BS" => {"code" => "BSD" ,"symbol" => "$"},
573 | "BT" => {"code" => "BTN" ,"symbol" => "Nu."},
574 | "BV" => {"code" => "NOK" ,"symbol" => "kr"},
575 | "BW" => {"code" => "BWP" ,"symbol" => "P"},
576 | "BY" => {"code" => "BYR" ,"symbol" => "Br"},
577 | "BZ" => {"code" => "BZD" ,"symbol" => "BZ$"},
578 | "CA" => {"code" => "CAD" ,"symbol" => "$"},
579 | "CC" => {"code" => "AUD" ,"symbol" => "$"},
580 | "CD" => {"code" => "CDF" ,"symbol" => "FC"},
581 | "CF" => {"code" => "XAF" ,"symbol" => "FCFA"},
582 | "CG" => {"code" => "XAF" ,"symbol" => "FCFA"},
583 | "CH" => {"code" => "CHF" ,"symbol" => "CHF"},
584 | "CI" => {"code" => "XOF" ,"symbol" => "CFA"},
585 | "CK" => {"code" => "NZD" ,"symbol" => "$"},
586 | "CL" => {"code" => "CLP" ,"symbol" => "$"},
587 | "CM" => {"code" => "XAF" ,"symbol" => "FCFA"},
588 | "CN" => {"code" => "CNY" ,"symbol" => "¥"},
589 | "CO" => {"code" => "COP" ,"symbol" => "$"},
590 | "CR" => {"code" => "CRC" ,"symbol" => "₡"},
591 | "CU" => {"code" => "CUP" ,"symbol" => "₱"},
592 | "CV" => {"code" => "CVE" ,"symbol" => "$"},
593 | "CW" => {"code" => "ANG" ,"symbol" => "ƒ"},
594 | "CX" => {"code" => "AUD" ,"symbol" => "$"},
595 | "CY" => {"code" => "EUR" ,"symbol" => "€"},
596 | "CZ" => {"code" => "CZK" ,"symbol" => "Kč"},
597 | "DE" => {"code" => "EUR" ,"symbol" => "€"},
598 | "DJ" => {"code" => "DJF" ,"symbol" => "Fdj"},
599 | "DK" => {"code" => "DKK" ,"symbol" => "kr"},
600 | "DM" => {"code" => "XCD" ,"symbol" => "$"},
601 | "DO" => {"code" => "DOP" ,"symbol" => "RD$"},
602 | "DZ" => {"code" => "DZD" ,"symbol" => "دج"},
603 | "EC" => {"code" => "USD" ,"symbol" => "$"},
604 | "EE" => {"code" => "EUR" ,"symbol" => "€"},
605 | "EG" => {"code" => "EGP" ,"symbol" => "£"},
606 | "EH" => {"code" => "MAD" ,"symbol" => "MAD"},
607 | "ER" => {"code" => "ERN" ,"symbol" => "Nfk"},
608 | "ES" => {"code" => "EUR" ,"symbol" => "€"},
609 | "ET" => {"code" => "ETB" ,"symbol" => "Br"},
610 | "FI" => {"code" => "EUR" ,"symbol" => "€"},
611 | "FJ" => {"code" => "FJD" ,"symbol" => "$"},
612 | "FK" => {"code" => "FKP" ,"symbol" => "£"},
613 | "FM" => {"code" => "USD" ,"symbol" => "$"},
614 | "FO" => {"code" => "DKK" ,"symbol" => "kr"},
615 | "FR" => {"code" => "EUR" ,"symbol" => "€"},
616 | "GA" => {"code" => "XAF" ,"symbol" => "FCFA"},
617 | "GB" => {"code" => "GBP" ,"symbol" => "£"},
618 | "GD" => {"code" => "XCD" ,"symbol" => "$"},
619 | "GE" => {"code" => "GEL" ,"symbol" => "ლ"},
620 | "GF" => {"code" => "EUR" ,"symbol" => "€"},
621 | "GG" => {"code" => "GBP" ,"symbol" => "£"},
622 | "GH" => {"code" => "GHS" ,"symbol" => "GH₵"},
623 | "GI" => {"code" => "GIP" ,"symbol" => "£"},
624 | "GL" => {"code" => "DKK" ,"symbol" => "kr"},
625 | "GM" => {"code" => "GMD" ,"symbol" => "D"},
626 | "GN" => {"code" => "GNF" ,"symbol" => "FG"},
627 | "GP" => {"code" => "EUR" ,"symbol" => "€"},
628 | "GQ" => {"code" => "XAF" ,"symbol" => "FCFA"},
629 | "GR" => {"code" => "EUR" ,"symbol" => "€"},
630 | "GS" => {"code" => "GBP" ,"symbol" => "£"},
631 | "GT" => {"code" => "GTQ" ,"symbol" => "Q"},
632 | "GU" => {"code" => "USD" ,"symbol" => "$"},
633 | "GW" => {"code" => "XOF" ,"symbol" => "CFA"},
634 | "GY" => {"code" => "GYD" ,"symbol" => "$"},
635 | "HK" => {"code" => "HKD" ,"symbol" => "$"},
636 | "HM" => {"code" => "AUD" ,"symbol" => "$"},
637 | "HN" => {"code" => "HNL" ,"symbol" => "L"},
638 | "HR" => {"code" => "HRK" ,"symbol" => "kn"},
639 | "HT" => {"code" => "HTG" ,"symbol" => "G"},
640 | "HU" => {"code" => "HUF" ,"symbol" => "Ft"},
641 | "ID" => {"code" => "IDR" ,"symbol" => "Rp"},
642 | "IE" => {"code" => "EUR" ,"symbol" => "€"},
643 | "IL" => {"code" => "ILS" ,"symbol" => "₪"},
644 | "IM" => {"code" => "GBP" ,"symbol" => "£"},
645 | "IN" => {"code" => "INR" ,"symbol" => "₹"},
646 | "IO" => {"code" => "USD" ,"symbol" => "$"},
647 | "IQ" => {"code" => "IQD" ,"symbol" => "ع.د"},
648 | "IR" => {"code" => "IRR" ,"symbol" => "﷼"},
649 | "IS" => {"code" => "ISK" ,"symbol" => "kr"},
650 | "IT" => {"code" => "EUR" ,"symbol" => "€"},
651 | "JE" => {"code" => "GBP" ,"symbol" => "£"},
652 | "JM" => {"code" => "JMD" ,"symbol" => "J$"},
653 | "JO" => {"code" => "JOD" ,"symbol" => "JD"},
654 | "JP" => {"code" => "JPY" ,"symbol" => "¥"},
655 | "KE" => {"code" => "KES" ,"symbol" => "KSh"},
656 | "KG" => {"code" => "KGS" ,"symbol" => "лв"},
657 | "KH" => {"code" => "KHR" ,"symbol" => "៛"},
658 | "KI" => {"code" => "AUD" ,"symbol" => "$"},
659 | "KM" => {"code" => "KMF" ,"symbol" => "CF"},
660 | "KN" => {"code" => "XCD" ,"symbol" => "$"},
661 | "KP" => {"code" => "KPW" ,"symbol" => "₩"},
662 | "KR" => {"code" => "KRW" ,"symbol" => "₩"},
663 | "KW" => {"code" => "KWD" ,"symbol" => "KD"},
664 | "KY" => {"code" => "KYD" ,"symbol" => "$"},
665 | "KZ" => {"code" => "KZT" ,"symbol" => "₸"},
666 | "LA" => {"code" => "LAK" ,"symbol" => "₭"},
667 | "LB" => {"code" => "LBP" ,"symbol" => "£"},
668 | "LC" => {"code" => "XCD" ,"symbol" => "$"},
669 | "LI" => {"code" => "CHF" ,"symbol" => "CHF"},
670 | "LK" => {"code" => "LKR" ,"symbol" => "₨"},
671 | "LR" => {"code" => "LRD" ,"symbol" => "$"},
672 | "LS" => {"code" => "LSL" ,"symbol" => "M"},
673 | "LT" => {"code" => "LTL" ,"symbol" => "Lt"},
674 | "LU" => {"code" => "EUR" ,"symbol" => "€"},
675 | "LV" => {"code" => "EUR" ,"symbol" => "€"},
676 | "LY" => {"code" => "LYD" ,"symbol" => "LD"},
677 | "MA" => {"code" => "MAD" ,"symbol" => "MAD"},
678 | "MC" => {"code" => "EUR" ,"symbol" => "€"},
679 | "MD" => {"code" => "MDL" ,"symbol" => "lei"},
680 | "ME" => {"code" => "EUR" ,"symbol" => "€"},
681 | "MF" => {"code" => "EUR" ,"symbol" => "€"},
682 | "MG" => {"code" => "MGA" ,"symbol" => "Ar"},
683 | "MH" => {"code" => "USD" ,"symbol" => "$"},
684 | "MK" => {"code" => "MKD" ,"symbol" => "ден"},
685 | "ML" => {"code" => "XOF" ,"symbol" => "CFA"},
686 | "MM" => {"code" => "MMK" ,"symbol" => "K"},
687 | "MN" => {"code" => "MNT" ,"symbol" => "₮"},
688 | "MO" => {"code" => "MOP" ,"symbol" => "MOP$"},
689 | "MP" => {"code" => "USD" ,"symbol" => "$"},
690 | "MQ" => {"code" => "EUR" ,"symbol" => "€"},
691 | "MR" => {"code" => "MRO" ,"symbol" => "UM"},
692 | "MS" => {"code" => "XCD" ,"symbol" => "$"},
693 | "MT" => {"code" => "EUR" ,"symbol" => "€"},
694 | "MU" => {"code" => "MUR" ,"symbol" => "₨"},
695 | "MV" => {"code" => "MVR" ,"symbol" => "Rf"},
696 | "MW" => {"code" => "MWK" ,"symbol" => "MK"},
697 | "MX" => {"code" => "MXN" ,"symbol" => "$"},
698 | "MY" => {"code" => "MYR" ,"symbol" => "RM"},
699 | "MZ" => {"code" => "MZN" ,"symbol" => "MT"},
700 | "NA" => {"code" => "NAD" ,"symbol" => "$"},
701 | "NC" => {"code" => "XPF" ,"symbol" => "₣"},
702 | "NE" => {"code" => "XOF" ,"symbol" => "CFA"},
703 | "NF" => {"code" => "AUD" ,"symbol" => "$"},
704 | "NG" => {"code" => "NGN" ,"symbol" => "₦"},
705 | "NI" => {"code" => "NIO" ,"symbol" => "C$"},
706 | "NL" => {"code" => "EUR" ,"symbol" => "€"},
707 | "NO" => {"code" => "NOK" ,"symbol" => "kr"},
708 | "NP" => {"code" => "NPR" ,"symbol" => "₨"},
709 | "NR" => {"code" => "AUD" ,"symbol" => "$"},
710 | "NU" => {"code" => "NZD" ,"symbol" => "$"},
711 | "NZ" => {"code" => "NZD" ,"symbol" => "$"},
712 | "OM" => {"code" => "OMR" ,"symbol" => "﷼"},
713 | "PA" => {"code" => "PAB" ,"symbol" => "B/."},
714 | "PE" => {"code" => "PEN" ,"symbol" => "S/."},
715 | "PF" => {"code" => "XPF" ,"symbol" => "₣"},
716 | "PG" => {"code" => "PGK" ,"symbol" => "K"},
717 | "PH" => {"code" => "PHP" ,"symbol" => "₱"},
718 | "PK" => {"code" => "PKR" ,"symbol" => "₨"},
719 | "PL" => {"code" => "PLN" ,"symbol" => "zł"},
720 | "PM" => {"code" => "EUR" ,"symbol" => "€"},
721 | "PN" => {"code" => "NZD" ,"symbol" => "$"},
722 | "PR" => {"code" => "USD" ,"symbol" => "$"},
723 | "PS" => {"code" => "ILS" ,"symbol" => "₪"},
724 | "PT" => {"code" => "EUR" ,"symbol" => "€"},
725 | "PW" => {"code" => "USD" ,"symbol" => "$"},
726 | "PY" => {"code" => "PYG" ,"symbol" => "Gs"},
727 | "QA" => {"code" => "QAR" ,"symbol" => "﷼"},
728 | "RE" => {"code" => "EUR" ,"symbol" => "€"},
729 | "RO" => {"code" => "RON" ,"symbol" => "lei"},
730 | "RS" => {"code" => "RSD" ,"symbol" => "Дин."},
731 | "RU" => {"code" => "RUB" ,"symbol" => "₽"},
732 | "RW" => {"code" => "RWF" ,"symbol" => "R₣"},
733 | "SA" => {"code" => "SAR" ,"symbol" => "﷼"},
734 | "SB" => {"code" => "SBD" ,"symbol" => "$"},
735 | "SC" => {"code" => "SCR" ,"symbol" => "₨"},
736 | "SD" => {"code" => "SDG" ,"symbol" => "ج.س."},
737 | "SE" => {"code" => "SEK" ,"symbol" => "kr"},
738 | "SG" => {"code" => "SGD" ,"symbol" => "S$"},
739 | "SH" => {"code" => "SHP" ,"symbol" => "£"},
740 | "SI" => {"code" => "EUR" ,"symbol" => "€"},
741 | "SJ" => {"code" => "NOK" ,"symbol" => "kr"},
742 | "SK" => {"code" => "EUR" ,"symbol" => "€"},
743 | "SL" => {"code" => "SLL" ,"symbol" => "Le"},
744 | "SM" => {"code" => "EUR" ,"symbol" => "€"},
745 | "SN" => {"code" => "XOF" ,"symbol" => "CFA"},
746 | "SO" => {"code" => "SOS" ,"symbol" => "S"},
747 | "SR" => {"code" => "SRD" ,"symbol" => "$"},
748 | "SS" => {"code" => "SSP" ,"symbol" => "£"},
749 | "ST" => {"code" => "STD" ,"symbol" => "Db"},
750 | "SV" => {"code" => "USD" ,"symbol" => "$"},
751 | "SX" => {"code" => "ANG" ,"symbol" => "ƒ"},
752 | "SY" => {"code" => "SYP" ,"symbol" => "£"},
753 | "SZ" => {"code" => "SZL" ,"symbol" => "E"},
754 | "TC" => {"code" => "USD" ,"symbol" => "$"},
755 | "TD" => {"code" => "XAF" ,"symbol" => "FCFA"},
756 | "TF" => {"code" => "EUR" ,"symbol" => "€"},
757 | "TG" => {"code" => "XOF" ,"symbol" => "CFA"},
758 | "TH" => {"code" => "THB" ,"symbol" => "฿"},
759 | "TJ" => {"code" => "TJS" ,"symbol" => "SM"},
760 | "TK" => {"code" => "NZD" ,"symbol" => "$"},
761 | "TL" => {"code" => "USD" ,"symbol" => "$"},
762 | "TM" => {"code" => "TMT" ,"symbol" => "T"},
763 | "TN" => {"code" => "TND" ,"symbol" => "د.ت"},
764 | "TO" => {"code" => "TOP" ,"symbol" => "T$"},
765 | "TR" => {"code" => "TRY" ,"symbol" => "₺"},
766 | "TT" => {"code" => "TTD" ,"symbol" => "TT$"},
767 | "TV" => {"code" => "AUD" ,"symbol" => "$"},
768 | "TW" => {"code" => "TWD" ,"symbol" => "NT$"},
769 | "TZ" => {"code" => "TZS" ,"symbol" => "TSh"},
770 | "UA" => {"code" => "UAH" ,"symbol" => "₴"},
771 | "UG" => {"code" => "UGX" ,"symbol" => "USh"},
772 | "UM" => {"code" => "USD" ,"symbol" => "$"},
773 | "US" => {"code" => "USD" ,"symbol" => "$"},
774 | "UY" => {"code" => "UYU" ,"symbol" => "$U"},
775 | "UZ" => {"code" => "UZS" ,"symbol" => "лв"},
776 | "VA" => {"code" => "EUR" ,"symbol" => "€"},
777 | "VC" => {"code" => "XCD" ,"symbol" => "$"},
778 | "VE" => {"code" => "VEF" ,"symbol" => "Bs"},
779 | "VG" => {"code" => "USD" ,"symbol" => "$"},
780 | "VI" => {"code" => "USD" ,"symbol" => "$"},
781 | "VN" => {"code" => "VND" ,"symbol" => "₫"},
782 | "VU" => {"code" => "VUV" ,"symbol" => "VT"},
783 | "WF" => {"code" => "XPF" ,"symbol" => "₣"},
784 | "WS" => {"code" => "WST" ,"symbol" => "WS$"},
785 | "XK" => {"code" => "EUR" ,"symbol" => "€"},
786 | "YE" => {"code" => "YER" ,"symbol" => "﷼"},
787 | "YT" => {"code" => "EUR" ,"symbol" => "€"},
788 | "ZA" => {"code" => "ZAR" ,"symbol" => "R"},
789 | "ZM" => {"code" => "ZMK" ,"symbol" => "ZK"},
790 | "ZW" => {"code" => "ZWL" ,"symbol" => "$"}
791 | }
792 |
793 | DEFAULT_CONTINENT_LIST = {
794 | "BD" => {"code" => "AS", "name" => "Asia"},
795 | "BE" => {"code" => "EU", "name" => "Europe"},
796 | "BF" => {"code" => "AF", "name" => "Africa"},
797 | "BG" => {"code" => "EU", "name" => "Europe"},
798 | "BA" => {"code" => "EU", "name" => "Europe"},
799 | "BB" => {"code" => "NA", "name" => "North America"},
800 | "WF" => {"code" => "OC", "name" => "Oceania"},
801 | "BL" => {"code" => "NA", "name" => "North America"},
802 | "BM" => {"code" => "NA", "name" => "North America"},
803 | "BN" => {"code" => "AS", "name" => "Asia"},
804 | "BO" => {"code" => "SA", "name" => "South America"},
805 | "BH" => {"code" => "AS", "name" => "Asia"},
806 | "BI" => {"code" => "AF", "name" => "Africa"},
807 | "BJ" => {"code" => "AF", "name" => "Africa"},
808 | "BT" => {"code" => "AS", "name" => "Asia"},
809 | "JM" => {"code" => "NA", "name" => "North America"},
810 | "BV" => {"code" => "AN", "name" => "Antarctica"},
811 | "BW" => {"code" => "AF", "name" => "Africa"},
812 | "WS" => {"code" => "OC", "name" => "Oceania"},
813 | "BQ" => {"code" => "NA", "name" => "North America"},
814 | "BR" => {"code" => "SA", "name" => "South America"},
815 | "BS" => {"code" => "NA", "name" => "North America"},
816 | "JE" => {"code" => "EU", "name" => "Europe"},
817 | "BY" => {"code" => "EU", "name" => "Europe"},
818 | "BZ" => {"code" => "NA", "name" => "North America"},
819 | "RU" => {"code" => "EU", "name" => "Europe"},
820 | "RW" => {"code" => "AF", "name" => "Africa"},
821 | "RS" => {"code" => "EU", "name" => "Europe"},
822 | "TL" => {"code" => "OC", "name" => "Oceania"},
823 | "RE" => {"code" => "AF", "name" => "Africa"},
824 | "TM" => {"code" => "AS", "name" => "Asia"},
825 | "TJ" => {"code" => "AS", "name" => "Asia"},
826 | "RO" => {"code" => "EU", "name" => "Europe"},
827 | "TK" => {"code" => "OC", "name" => "Oceania"},
828 | "GW" => {"code" => "AF", "name" => "Africa"},
829 | "GU" => {"code" => "OC", "name" => "Oceania"},
830 | "GT" => {"code" => "NA", "name" => "North America"},
831 | "GS" => {"code" => "AN", "name" => "Antarctica"},
832 | "GR" => {"code" => "EU", "name" => "Europe"},
833 | "GQ" => {"code" => "AF", "name" => "Africa"},
834 | "GP" => {"code" => "NA", "name" => "North America"},
835 | "JP" => {"code" => "AS", "name" => "Asia"},
836 | "GY" => {"code" => "SA", "name" => "South America"},
837 | "GG" => {"code" => "EU", "name" => "Europe"},
838 | "GF" => {"code" => "SA", "name" => "South America"},
839 | "GE" => {"code" => "AS", "name" => "Asia"},
840 | "GD" => {"code" => "NA", "name" => "North America"},
841 | "GB" => {"code" => "EU", "name" => "Europe"},
842 | "GA" => {"code" => "AF", "name" => "Africa"},
843 | "SV" => {"code" => "NA", "name" => "North America"},
844 | "GN" => {"code" => "AF", "name" => "Africa"},
845 | "GM" => {"code" => "AF", "name" => "Africa"},
846 | "GL" => {"code" => "NA", "name" => "North America"},
847 | "GI" => {"code" => "EU", "name" => "Europe"},
848 | "GH" => {"code" => "AF", "name" => "Africa"},
849 | "OM" => {"code" => "AS", "name" => "Asia"},
850 | "TN" => {"code" => "AF", "name" => "Africa"},
851 | "JO" => {"code" => "AS", "name" => "Asia"},
852 | "HR" => {"code" => "EU", "name" => "Europe"},
853 | "HT" => {"code" => "NA", "name" => "North America"},
854 | "HU" => {"code" => "EU", "name" => "Europe"},
855 | "HK" => {"code" => "AS", "name" => "Asia"},
856 | "HN" => {"code" => "NA", "name" => "North America"},
857 | "HM" => {"code" => "AN", "name" => "Antarctica"},
858 | "VE" => {"code" => "SA", "name" => "South America"},
859 | "PR" => {"code" => "NA", "name" => "North America"},
860 | "PS" => {"code" => "AS", "name" => "Asia"},
861 | "PW" => {"code" => "OC", "name" => "Oceania"},
862 | "PT" => {"code" => "EU", "name" => "Europe"},
863 | "SJ" => {"code" => "EU", "name" => "Europe"},
864 | "PY" => {"code" => "SA", "name" => "South America"},
865 | "IQ" => {"code" => "AS", "name" => "Asia"},
866 | "PA" => {"code" => "NA", "name" => "North America"},
867 | "PF" => {"code" => "OC", "name" => "Oceania"},
868 | "PG" => {"code" => "OC", "name" => "Oceania"},
869 | "PE" => {"code" => "SA", "name" => "South America"},
870 | "PK" => {"code" => "AS", "name" => "Asia"},
871 | "PH" => {"code" => "AS", "name" => "Asia"},
872 | "PN" => {"code" => "OC", "name" => "Oceania"},
873 | "PL" => {"code" => "EU", "name" => "Europe"},
874 | "PM" => {"code" => "NA", "name" => "North America"},
875 | "ZM" => {"code" => "AF", "name" => "Africa"},
876 | "EH" => {"code" => "AF", "name" => "Africa"},
877 | "EE" => {"code" => "EU", "name" => "Europe"},
878 | "EG" => {"code" => "AF", "name" => "Africa"},
879 | "ZA" => {"code" => "AF", "name" => "Africa"},
880 | "EC" => {"code" => "SA", "name" => "South America"},
881 | "IT" => {"code" => "EU", "name" => "Europe"},
882 | "VN" => {"code" => "AS", "name" => "Asia"},
883 | "SB" => {"code" => "OC", "name" => "Oceania"},
884 | "ET" => {"code" => "AF", "name" => "Africa"},
885 | "SO" => {"code" => "AF", "name" => "Africa"},
886 | "ZW" => {"code" => "AF", "name" => "Africa"},
887 | "SA" => {"code" => "AS", "name" => "Asia"},
888 | "ES" => {"code" => "EU", "name" => "Europe"},
889 | "ER" => {"code" => "AF", "name" => "Africa"},
890 | "ME" => {"code" => "EU", "name" => "Europe"},
891 | "MD" => {"code" => "EU", "name" => "Europe"},
892 | "MG" => {"code" => "AF", "name" => "Africa"},
893 | "MF" => {"code" => "NA", "name" => "North America"},
894 | "MA" => {"code" => "AF", "name" => "Africa"},
895 | "MC" => {"code" => "EU", "name" => "Europe"},
896 | "UZ" => {"code" => "AS", "name" => "Asia"},
897 | "MM" => {"code" => "AS", "name" => "Asia"},
898 | "ML" => {"code" => "AF", "name" => "Africa"},
899 | "MO" => {"code" => "AS", "name" => "Asia"},
900 | "MN" => {"code" => "AS", "name" => "Asia"},
901 | "MH" => {"code" => "OC", "name" => "Oceania"},
902 | "MK" => {"code" => "EU", "name" => "Europe"},
903 | "MU" => {"code" => "AF", "name" => "Africa"},
904 | "MT" => {"code" => "EU", "name" => "Europe"},
905 | "MW" => {"code" => "AF", "name" => "Africa"},
906 | "MV" => {"code" => "AS", "name" => "Asia"},
907 | "MQ" => {"code" => "NA", "name" => "North America"},
908 | "MP" => {"code" => "OC", "name" => "Oceania"},
909 | "MS" => {"code" => "NA", "name" => "North America"},
910 | "MR" => {"code" => "AF", "name" => "Africa"},
911 | "IM" => {"code" => "EU", "name" => "Europe"},
912 | "UG" => {"code" => "AF", "name" => "Africa"},
913 | "TZ" => {"code" => "AF", "name" => "Africa"},
914 | "MY" => {"code" => "AS", "name" => "Asia"},
915 | "MX" => {"code" => "NA", "name" => "North America"},
916 | "IL" => {"code" => "AS", "name" => "Asia"},
917 | "FR" => {"code" => "EU", "name" => "Europe"},
918 | "IO" => {"code" => "AS", "name" => "Asia"},
919 | "SH" => {"code" => "AF", "name" => "Africa"},
920 | "FI" => {"code" => "EU", "name" => "Europe"},
921 | "FJ" => {"code" => "OC", "name" => "Oceania"},
922 | "FK" => {"code" => "SA", "name" => "South America"},
923 | "FM" => {"code" => "OC", "name" => "Oceania"},
924 | "FO" => {"code" => "EU", "name" => "Europe"},
925 | "NI" => {"code" => "NA", "name" => "North America"},
926 | "NL" => {"code" => "EU", "name" => "Europe"},
927 | "NO" => {"code" => "EU", "name" => "Europe"},
928 | "NA" => {"code" => "AF", "name" => "Africa"},
929 | "VU" => {"code" => "OC", "name" => "Oceania"},
930 | "NC" => {"code" => "OC", "name" => "Oceania"},
931 | "NE" => {"code" => "AF", "name" => "Africa"},
932 | "NF" => {"code" => "OC", "name" => "Oceania"},
933 | "NG" => {"code" => "AF", "name" => "Africa"},
934 | "NZ" => {"code" => "OC", "name" => "Oceania"},
935 | "NP" => {"code" => "AS", "name" => "Asia"},
936 | "NR" => {"code" => "OC", "name" => "Oceania"},
937 | "NU" => {"code" => "OC", "name" => "Oceania"},
938 | "CK" => {"code" => "OC", "name" => "Oceania"},
939 | "XK" => {"code" => "EU", "name" => "Europe"},
940 | "CI" => {"code" => "AF", "name" => "Africa"},
941 | "CH" => {"code" => "EU", "name" => "Europe"},
942 | "CO" => {"code" => "SA", "name" => "South America"},
943 | "CN" => {"code" => "AS", "name" => "Asia"},
944 | "CM" => {"code" => "AF", "name" => "Africa"},
945 | "CL" => {"code" => "SA", "name" => "South America"},
946 | "CC" => {"code" => "AS", "name" => "Asia"},
947 | "CA" => {"code" => "NA", "name" => "North America"},
948 | "CG" => {"code" => "AF", "name" => "Africa"},
949 | "CF" => {"code" => "AF", "name" => "Africa"},
950 | "CD" => {"code" => "AF", "name" => "Africa"},
951 | "CZ" => {"code" => "EU", "name" => "Europe"},
952 | "CY" => {"code" => "EU", "name" => "Europe"},
953 | "CX" => {"code" => "AS", "name" => "Asia"},
954 | "CR" => {"code" => "NA", "name" => "North America"},
955 | "CW" => {"code" => "NA", "name" => "North America"},
956 | "CV" => {"code" => "AF", "name" => "Africa"},
957 | "CU" => {"code" => "NA", "name" => "North America"},
958 | "SZ" => {"code" => "AF", "name" => "Africa"},
959 | "SY" => {"code" => "AS", "name" => "Asia"},
960 | "SX" => {"code" => "NA", "name" => "North America"},
961 | "KG" => {"code" => "AS", "name" => "Asia"},
962 | "KE" => {"code" => "AF", "name" => "Africa"},
963 | "SS" => {"code" => "AF", "name" => "Africa"},
964 | "SR" => {"code" => "SA", "name" => "South America"},
965 | "KI" => {"code" => "OC", "name" => "Oceania"},
966 | "KH" => {"code" => "AS", "name" => "Asia"},
967 | "KN" => {"code" => "NA", "name" => "North America"},
968 | "KM" => {"code" => "AF", "name" => "Africa"},
969 | "ST" => {"code" => "AF", "name" => "Africa"},
970 | "SK" => {"code" => "EU", "name" => "Europe"},
971 | "KR" => {"code" => "AS", "name" => "Asia"},
972 | "SI" => {"code" => "EU", "name" => "Europe"},
973 | "KP" => {"code" => "AS", "name" => "Asia"},
974 | "KW" => {"code" => "AS", "name" => "Asia"},
975 | "SN" => {"code" => "AF", "name" => "Africa"},
976 | "SM" => {"code" => "EU", "name" => "Europe"},
977 | "SL" => {"code" => "AF", "name" => "Africa"},
978 | "SC" => {"code" => "AF", "name" => "Africa"},
979 | "KZ" => {"code" => "AS", "name" => "Asia"},
980 | "KY" => {"code" => "NA", "name" => "North America"},
981 | "SG" => {"code" => "AS", "name" => "Asia"},
982 | "SE" => {"code" => "EU", "name" => "Europe"},
983 | "SD" => {"code" => "AF", "name" => "Africa"},
984 | "DO" => {"code" => "NA", "name" => "North America"},
985 | "DM" => {"code" => "NA", "name" => "North America"},
986 | "DJ" => {"code" => "AF", "name" => "Africa"},
987 | "DK" => {"code" => "EU", "name" => "Europe"},
988 | "VG" => {"code" => "NA", "name" => "North America"},
989 | "DE" => {"code" => "EU", "name" => "Europe"},
990 | "YE" => {"code" => "AS", "name" => "Asia"},
991 | "DZ" => {"code" => "AF", "name" => "Africa"},
992 | "US" => {"code" => "NA", "name" => "North America"},
993 | "UY" => {"code" => "SA", "name" => "South America"},
994 | "YT" => {"code" => "AF", "name" => "Africa"},
995 | "UM" => {"code" => "OC", "name" => "Oceania"},
996 | "LB" => {"code" => "AS", "name" => "Asia"},
997 | "LC" => {"code" => "NA", "name" => "North America"},
998 | "LA" => {"code" => "AS", "name" => "Asia"},
999 | "TV" => {"code" => "OC", "name" => "Oceania"},
1000 | "TW" => {"code" => "AS", "name" => "Asia"},
1001 | "TT" => {"code" => "NA", "name" => "North America"},
1002 | "TR" => {"code" => "AS", "name" => "Asia"},
1003 | "LK" => {"code" => "AS", "name" => "Asia"},
1004 | "LI" => {"code" => "EU", "name" => "Europe"},
1005 | "LV" => {"code" => "EU", "name" => "Europe"},
1006 | "TO" => {"code" => "OC", "name" => "Oceania"},
1007 | "LT" => {"code" => "EU", "name" => "Europe"},
1008 | "LU" => {"code" => "EU", "name" => "Europe"},
1009 | "LR" => {"code" => "AF", "name" => "Africa"},
1010 | "LS" => {"code" => "AF", "name" => "Africa"},
1011 | "TH" => {"code" => "AS", "name" => "Asia"},
1012 | "TF" => {"code" => "AN", "name" => "Antarctica"},
1013 | "TG" => {"code" => "AF", "name" => "Africa"},
1014 | "TD" => {"code" => "AF", "name" => "Africa"},
1015 | "TC" => {"code" => "NA", "name" => "North America"},
1016 | "LY" => {"code" => "AF", "name" => "Africa"},
1017 | "VA" => {"code" => "EU", "name" => "Europe"},
1018 | "VC" => {"code" => "NA", "name" => "North America"},
1019 | "AE" => {"code" => "AS", "name" => "Asia"},
1020 | "AD" => {"code" => "EU", "name" => "Europe"},
1021 | "AG" => {"code" => "NA", "name" => "North America"},
1022 | "AF" => {"code" => "AS", "name" => "Asia"},
1023 | "AI" => {"code" => "NA", "name" => "North America"},
1024 | "VI" => {"code" => "NA", "name" => "North America"},
1025 | "IS" => {"code" => "EU", "name" => "Europe"},
1026 | "IR" => {"code" => "AS", "name" => "Asia"},
1027 | "AM" => {"code" => "AS", "name" => "Asia"},
1028 | "AL" => {"code" => "EU", "name" => "Europe"},
1029 | "AO" => {"code" => "AF", "name" => "Africa"},
1030 | "AQ" => {"code" => "AN", "name" => "Antarctica"},
1031 | "AS" => {"code" => "OC", "name" => "Oceania"},
1032 | "AR" => {"code" => "SA", "name" => "South America"},
1033 | "AU" => {"code" => "OC", "name" => "Oceania"},
1034 | "AT" => {"code" => "EU", "name" => "Europe"},
1035 | "AW" => {"code" => "NA", "name" => "North America"},
1036 | "IN" => {"code" => "AS", "name" => "Asia"},
1037 | "AX" => {"code" => "EU", "name" => "Europe"},
1038 | "AZ" => {"code" => "AS", "name" => "Asia"},
1039 | "IE" => {"code" => "EU", "name" => "Europe"},
1040 | "ID" => {"code" => "AS", "name" => "Asia"},
1041 | "UA" => {"code" => "EU", "name" => "Europe"},
1042 | "QA" => {"code" => "AS", "name" => "Asia"},
1043 | "MZ" => {"code" => "AF", "name" => "Africa"}
1044 | }
1045 | end
--------------------------------------------------------------------------------
/lib/ipinfo/errors.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | class IPinfo::RateLimitError < StandardError; end
4 |
--------------------------------------------------------------------------------
/lib/ipinfo/ipAddressMatcher.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'resolv'
4 | require 'ipaddr'
5 |
6 | class IPinfo::IpAddressMatcher
7 | attr_accessor :required_address
8 |
9 | @@bogon_list = [
10 | "0.0.0.0/8",
11 | "10.0.0.0/8",
12 | "100.64.0.0/10",
13 | "127.0.0.0/8",
14 | "169.254.0.0/16",
15 | "172.16.0.0/12",
16 | "192.0.0.0/24",
17 | "192.0.2.0/24",
18 | "192.168.0.0/16",
19 | "198.18.0.0/15",
20 | "198.51.100.0/24",
21 | "203.0.113.0/24",
22 | "224.0.0.0/4",
23 | "240.0.0.0/4",
24 | "255.255.255.255/32",
25 | "::/128",
26 | "::1/128",
27 | "::ffff:0:0/96",
28 | "::/96",
29 | "100::/64",
30 | "2001:10::/28",
31 | "2001:db8::/32",
32 | "fc00::/7",
33 | "fe80::/10",
34 | "fec0::/10",
35 | "ff00::/8",
36 | "2002::/24",
37 | "2002:a00::/24",
38 | "2002:7f00::/24",
39 | "2002:a9fe::/32",
40 | "2002:ac10::/28",
41 | "2002:c000::/40",
42 | "2002:c000:200::/40",
43 | "2002:c0a8::/32",
44 | "2002:c612::/31",
45 | "2002:c633:6400::/40",
46 | "2002:cb00:7100::/40",
47 | "2002:e000::/20",
48 | "2002:f000::/20",
49 | "2002:ffff:ffff::/48",
50 | "2001::/40",
51 | "2001:0:a00::/40",
52 | "2001:0:7f00::/40",
53 | "2001:0:a9fe::/48",
54 | "2001:0:ac10::/44",
55 | "2001:0:c000::/56",
56 | "2001:0:c000:200::/56",
57 | "2001:0:c0a8::/48",
58 | "2001:0:c612::/47",
59 | "2001:0:c633:6400::/56",
60 | "2001:0:cb00:7100::/56",
61 | "2001:0:e000::/36",
62 | "2001:0:f000::/36",
63 | "2001:0:ffff:ffff::/64"
64 | ]
65 |
66 | def initialize(ip)
67 | if !ip.index('/').nil? and ip.index('/') > 0
68 | addr_mask = ip.split('/')
69 | ip = addr_mask[0]
70 | end
71 |
72 | @required_address = parseAddress(ip)
73 | end
74 |
75 | def parseAddress(ip)
76 | begin
77 | Resolv.getaddress ip
78 | rescue Resolv::ResolvError => e
79 | pp e
80 | end
81 | end
82 |
83 | def matches
84 | for bogon in @@bogon_list do
85 | if bogon.include? required_address
86 | return true
87 | end
88 | end
89 |
90 | false
91 | end
92 | end
--------------------------------------------------------------------------------
/lib/ipinfo/mod.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module IPinfo
4 | end
5 |
--------------------------------------------------------------------------------
/lib/ipinfo/response.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'ipaddr'
4 | require 'json'
5 |
6 | class IPinfo::Response
7 | attr_reader :all
8 |
9 | def initialize(response)
10 | @all = response
11 |
12 | @all.each do |name, value|
13 | instance_variable_set("@#{name}", value)
14 |
15 | c = class << self; self end
16 | c.send(:attr_accessor, name)
17 | end
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/lib/ipinfo/version.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | module IPinfo
4 | VERSION = '2.2.4'
5 | end
6 |
--------------------------------------------------------------------------------
/test/ipinfo_test.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require_relative './test_helper'
4 |
5 | class IPinfoTest < Minitest::Test
6 | TEST_IPV4 = '8.8.8.8'
7 | TEST_IPV6 = '2001:240:2a54:3900::'
8 |
9 | def assert_ip6(resp)
10 | assert_equal(resp.ip, TEST_IPV6)
11 | assert_equal(resp.ip_address, IPAddr.new(TEST_IPV6))
12 | assert_equal(resp.city, 'Hiroshima')
13 | assert_equal(resp.region, 'Hiroshima')
14 | assert_equal(resp.country, 'JP')
15 | assert_equal(resp.country_name, 'Japan')
16 | assert_equal(resp.is_eu, false)
17 | assert_equal(resp.loc, '34.4000,132.4500')
18 | assert_equal(resp.latitude, '34.4000')
19 | assert_equal(resp.longitude, '132.4500')
20 | assert_equal(resp.postal, '730-0011')
21 | assert_equal(resp.timezone, 'Asia/Tokyo')
22 | assert_equal(resp.country_flag_url, 'https://cdn.ipinfo.io/static/images/countries-flags/JP.svg')
23 | assert_equal(
24 | resp.asn,
25 | {
26 | "asn": 'AS2497',
27 | "name": 'Internet Initiative Japan Inc.',
28 | "domain": 'iij.ad.jp',
29 | "route": '2001:240::/32',
30 | "type": 'isp'
31 | }
32 | )
33 | assert_equal(
34 | resp.company,
35 | {
36 | "name": 'Internet Initiative Japan Inc.',
37 | "domain": 'iij.ad.jp',
38 | "type": 'isp'
39 | }
40 | )
41 | assert_equal(
42 | resp.privacy,
43 | {
44 | "vpn": false,
45 | "proxy": false,
46 | "tor": false,
47 | "relay": false,
48 | "hosting": false,
49 | "service": ''
50 | }
51 | )
52 | assert_equal(
53 | resp.abuse,
54 | {
55 | "address": 'Brisbane, Australia',
56 | "country": 'AU',
57 | "email": 'helpdesk@apnic.net',
58 | "name": 'ABUSE APNICAP',
59 | "network": '2001:200::/23',
60 | "phone": '+000000000'
61 | }
62 | )
63 | assert_equal(
64 | resp.domains,
65 | {
66 | "page": 0,
67 | "total": 0,
68 | "domains": []
69 | }
70 | )
71 | end
72 |
73 | def assert_ip4(resp)
74 | assert_equal(resp.ip, TEST_IPV4)
75 | assert_equal(resp.ip_address, IPAddr.new(TEST_IPV4))
76 | assert_equal(resp.hostname, 'dns.google')
77 | assert_equal(resp.anycast, true)
78 | assert_equal(resp.city, 'Mountain View')
79 | assert_equal(resp.region, 'California')
80 | assert_equal(resp.country, 'US')
81 | assert_equal(resp.country_name, 'United States')
82 | assert_equal(resp.is_eu, false)
83 | assert_equal(resp.country_flag['emoji'], '🇺🇸')
84 | assert_equal(resp.country_flag['unicode'], 'U+1F1FA U+1F1F8')
85 | assert_equal(resp.country_flag_url, 'https://cdn.ipinfo.io/static/images/countries-flags/US.svg')
86 | assert_equal(resp.country_currency['code'], 'USD')
87 | assert_equal(resp.country_currency['symbol'], '$')
88 | assert_equal(resp.continent['code'], 'NA')
89 | assert_equal(resp.continent['name'], 'North America')
90 | assert_equal(resp.loc, '37.4056,-122.0775')
91 | assert_equal(resp.latitude, '37.4056')
92 | assert_equal(resp.longitude, '-122.0775')
93 | assert_equal(resp.postal, '94043')
94 | assert_equal(resp.timezone, 'America/Los_Angeles')
95 | assert_equal(
96 | resp.asn,
97 | {
98 | "asn": 'AS15169',
99 | "name": 'Google LLC',
100 | "domain": 'google.com',
101 | "route": '8.8.8.0/24',
102 | "type": 'hosting'
103 | }
104 | )
105 | assert_equal(
106 | resp.company,
107 | {
108 | "name": 'Google LLC',
109 | "domain": 'google.com',
110 | "type": 'hosting'
111 | }
112 | )
113 | assert_equal(
114 | resp.privacy,
115 | {
116 | "vpn": false,
117 | "proxy": false,
118 | "tor": false,
119 | "relay": false,
120 | "hosting": true,
121 | "service": ''
122 | }
123 | )
124 | assert_equal(
125 | resp.abuse,
126 | {
127 | "address": 'US, CA, Mountain View, ' \
128 | '1600 Amphitheatre Parkway, 94043',
129 | "country": 'US',
130 | "email": 'network-abuse@google.com',
131 | "name": 'Abuse',
132 | "network": '8.8.8.0/24',
133 | "phone": '+1-650-253-0000'
134 | }
135 | )
136 | assert_equal(resp.domains[:ip], TEST_IPV4)
137 | refute_nil(resp.domains[:total])
138 | refute_nil(resp.domains[:domains])
139 | end
140 |
141 | def test_that_it_has_a_version_number
142 | refute_nil ::IPinfo::VERSION
143 | end
144 |
145 | def test_set_adapter_v4
146 | ipinfo = IPinfo.create(
147 | ENV['IPINFO_TOKEN'],
148 | { http_client: :excon }
149 | )
150 |
151 | assert(ipinfo.httpc = :excon)
152 | end
153 |
154 | def test_lookup_ip6
155 | ipinfo = IPinfo.create(ENV['IPINFO_TOKEN'])
156 |
157 | # multiple checks for cache
158 | (0...5).each do |_|
159 | resp = ipinfo.details(TEST_IPV6)
160 | assert_ip6(resp)
161 | end
162 | end
163 |
164 | # # Requires IPv6 support
165 | # def test_lookup_ip6_on_host_v6
166 | # ipinfo = IPinfo.create(ENV['IPINFO_TOKEN'])
167 |
168 | # # multiple checks for cache
169 | # (0...5).each do |_|
170 | # resp = ipinfo.details_v6(TEST_IPV6)
171 | # assert_ip6(resp)
172 | # end
173 | # end
174 |
175 | def test_lookup_ip4
176 | ipinfo = IPinfo.create(ENV['IPINFO_TOKEN'])
177 |
178 | # multiple checks for cache
179 | (0...5).each do |_|
180 | resp = ipinfo.details(TEST_IPV4)
181 | assert_ip4(resp)
182 | end
183 | end
184 |
185 | # # Requires IPv6 support
186 | # def test_lookup_ip4_on_host_v6
187 | # ipinfo = IPinfo.create(ENV['IPINFO_TOKEN'])
188 |
189 | # # multiple checks for cache
190 | # (0...5).each do |_|
191 | # resp = ipinfo.details_v6(TEST_IPV4)
192 | # assert_ip4(resp)
193 | # end
194 | # end
195 | end
196 |
--------------------------------------------------------------------------------
/test/lib/adapter_test.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'test_helper'
4 | require_relative '../../lib/ipinfo/adapter'
5 |
6 | require 'faraday/net_http_persistent'
7 | require 'faraday/typhoeus'
8 | require 'faraday/patron'
9 | require 'faraday/httpclient'
10 | require 'faraday/excon'
11 |
12 | class IPinfo::AdapterTest < Minitest::Test
13 | def test_default
14 | adapter = IPinfo::Adapter.new
15 | assert_equal(
16 | adapter.conn.adapter,
17 | Faraday::Adapter::NetHttp
18 | )
19 | end
20 |
21 | SUPPORTED_ADAPTERS = {
22 | net_http: Faraday::Adapter::NetHttp,
23 | net_http_persistent: Faraday::Adapter::NetHttpPersistent,
24 | typhoeus: Faraday::Adapter::Typhoeus,
25 | patron: Faraday::Adapter::Patron,
26 | excon: Faraday::Adapter::Excon,
27 | httpclient: Faraday::Adapter::HTTPClient
28 | }.freeze
29 |
30 | def test_unsupported_adapter
31 | error = assert_raises(Faraday::Error) do
32 | IPinfo::Adapter.new(nil, :missing_adapter)
33 | end
34 | assert_equal(
35 | error.message,
36 | ':missing_adapter is not registered on Faraday::Adapter'
37 | )
38 | end
39 |
40 | def test_all_possible_adapters
41 | SUPPORTED_ADAPTERS.each_key do |key|
42 | adapter = IPinfo::Adapter.new(nil, key)
43 | assert_equal(
44 | adapter.conn.adapter,
45 | SUPPORTED_ADAPTERS[key]
46 | )
47 | end
48 | end
49 | end
50 |
--------------------------------------------------------------------------------
/test/lib/cache_test.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | require 'test_helper'
4 | require_relative '../../lib/ipinfo/cache/default_cache'
5 |
6 | class IPinfo::CacheTest < Minitest::Test
7 | def test_get
8 | cache = IPinfo::DefaultCache.new(5, 3)
9 | cache.set(:a, 2)
10 | cache.set(:b, 3)
11 | assert_equal(2, cache.get(:a))
12 | assert_equal(3, cache.get(:b))
13 | end
14 |
15 | def test_contains?
16 | cache = IPinfo::DefaultCache.new(5, 3)
17 | assert_equal(false, cache.contains?(:a))
18 | cache.set(:a, 2)
19 | assert_equal(true, cache.contains?(:a))
20 | end
21 |
22 | def test_max_size
23 | cache = IPinfo::DefaultCache.new(5, 2)
24 | cache.set(:a, 2)
25 | cache.set(:b, 3)
26 | assert_equal(true, cache.contains?(:a))
27 | assert_equal(true, cache.contains?(:b))
28 | cache.set(:c, 3)
29 | cache.set(:d, 5)
30 | assert_equal(false, cache.contains?(:a))
31 | assert_equal(false, cache.contains?(:b))
32 | assert_equal(true, cache.contains?(:c))
33 | assert_equal(true, cache.contains?(:d))
34 | end
35 |
36 | def test_ttl
37 | cache = IPinfo::DefaultCache.new(0.1, 2)
38 | cache.set(:a, 2)
39 | assert_equal(true, cache.contains?(:a))
40 | sleep(0.2)
41 | assert_equal(false, cache.contains?(:a))
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4 | require 'ipinfo'
5 |
6 | require 'minitest/autorun'
7 | require 'minitest/reporters'
8 |
9 | Minitest::Reporters.use!(
10 | Minitest::Reporters::SpecReporter.new
11 | )
12 |
--------------------------------------------------------------------------------