IPinfo 1.0.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4c7edbf9ea00bfe0f34278ce345a0be0af732787dac8894043640d1c72f3dda
4
- data.tar.gz: a012b52f9d182417c48f96997e80464b37633b46b0e54e2251b36c8d36710174
3
+ metadata.gz: 7fdee7360c5440bb6a71dcfca62b1b006688952535a1f594c3b9c3105505665b
4
+ data.tar.gz: a177efbb1348e47dfe3ea6c1cdaef9327a33db6b0233db1884b1b27379ed49b5
5
5
  SHA512:
6
- metadata.gz: 706d928db455afb05db71bbf170b33616fa141c3f5765ac1045563e24b90e124fd8fbb9743bcdd7ac9b0ba1a7d0ccf30a4615cb2edf0fefe55e5c903f9be8eac
7
- data.tar.gz: f49d989cf52c9b1524ce2d4a177cc906ab5c680745fb23f540fa6395c31f6a4bac304f904849f0b8298a89600e93321a2f6e0165988506f8ad0ede81c7873ad1
6
+ metadata.gz: b4f01041c106a9c69d155ab4981090b94d14cc1637dc2bd522920defb87552640bf8b5e9c540b43e221a76bab8ba961ac7241fe9b602de44167606409440d8c4
7
+ data.tar.gz: 9f7d2ecce9daf619edf12564690a0281f49f8152b1e3159e34d2e43048862cecae4b55c87baae79e21a3b0371d4cbc2ecdeb3549ec6ee16f18f7327a122e401a
@@ -0,0 +1,37 @@
1
+ name: Release package to rubygems.org
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+
12
+ permissions:
13
+ id-token: write
14
+
15
+ steps:
16
+ - name: Checkout
17
+ uses: actions/checkout@v3
18
+
19
+ - name: Install apt dependencies
20
+ run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev # needed by faraday-patron gem
21
+
22
+ - name: Set up Ruby
23
+ uses: ruby/setup-ruby@v1
24
+
25
+ - name: Install dependencies
26
+ run: bundle install
27
+
28
+ - name: Run tests
29
+ run: bundle exec rake
30
+ env:
31
+ IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
32
+
33
+ - name: Build
34
+ run: gem build *.gemspec
35
+
36
+ - name: Publish
37
+ uses: rubygems/release-gem@v1
@@ -0,0 +1,40 @@
1
+ name: Unit Tests
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ jobs:
15
+ run:
16
+
17
+ runs-on: ubuntu-latest
18
+ strategy:
19
+ matrix:
20
+ ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4']
21
+
22
+ steps:
23
+ - name: Checkout
24
+ uses: actions/checkout@v3
25
+
26
+ - name: Install apt dependencies
27
+ run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev # needed by faraday-patron gem
28
+
29
+ - name: Set up Ruby ${{ matrix.ruby-version }}
30
+ uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+
34
+ - name: Install dependencies
35
+ run: bundle install
36
+
37
+ - name: Run tests
38
+ env:
39
+ IPINFO_TOKEN: ${{ secrets.IPINFO_TOKEN }}
40
+ run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -40,3 +40,9 @@ Style/MethodCallWithArgsParentheses:
40
40
 
41
41
  Style/MethodCallWithoutArgsParentheses:
42
42
  Enabled: false
43
+
44
+ Naming/FileName:
45
+ Enabled: false
46
+
47
+ Naming/PredicateName:
48
+ Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.2
1
+ 3.2.2
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # [<img src="https://ipinfo.io/static/ipinfo-small.svg" alt="IPinfo" width="24"/>](https://ipinfo.io/) IPinfo Ruby Client Library
2
2
 
3
- This is the official Ruby client library for the [IPinfo.io](https://ipinfo.io) IP address API, allowing you to lookup 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)
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
6
  - [Firmographic data](https://ipinfo.io/ip-company-api) (the name and domain of the business that uses the IP address)
7
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
8
 
@@ -10,10 +10,12 @@ Check all the data we have for your IP address [here](https://ipinfo.io/what-is-
10
10
 
11
11
  ### Getting Started
12
12
 
13
- You'll need an IPinfo API access token, which you can get by singing up for a free account at [https://ipinfo.io/signup](https://ipinfo.io/signup).
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
14
 
15
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
16
 
17
+ The library also supports the Lite API, see the [Lite API section](#lite-api) for more info.
18
+
17
19
  #### Installation
18
20
 
19
21
  Add this line to your application's Gemfile:
@@ -33,30 +35,44 @@ Or install it yourself as:
33
35
  #### Quick Start
34
36
 
35
37
  ```ruby
36
- require 'IPinfo'
38
+ require 'ipinfo'
37
39
 
38
40
  access_token = '123456789abc'
39
41
  handler = IPinfo::create(access_token)
40
42
  ip_address = '216.239.36.21'
41
43
 
42
44
  details = handler.details(ip_address)
45
+ details_v6 = handler.details_v6() # to get details from ipinfo's IPv6 host
43
46
  city = details.city # Emeryville
44
47
  loc = details.loc # 37.8342,-122.2900
45
48
  ```
46
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
+
47
62
  #### Usage
48
63
 
49
- The `IPinfo.details()` method accepts an IP address as an optional, positional
64
+ The `IPinfo.details()` and `IPinfo.details_v6()` methods accept an IP address as an optional, positional
50
65
  argument. If no IP address is specified, the API will return data for the IP
51
66
  address from which it receives the request.
52
67
 
53
68
  ```ruby
54
- require 'IPinfo'
69
+ require 'ipinfo'
55
70
 
56
71
  access_token = '123456789abc'
57
72
  handler = IPinfo::create(access_token)
58
73
 
59
74
  details = handler.details()
75
+ details_v6 = handler.details_v6() # to get details from ipinfo's IPv6 host
60
76
  city = details.city # "Emeryville"
61
77
  loc = details.loc # 37.8342,-122.2900
62
78
  ```
@@ -74,7 +90,7 @@ handler = IPinfo::create(access_token)
74
90
 
75
91
  #### Details Data
76
92
 
77
- `handler.details()` will return a `Response` object that contains all fields
93
+ `handler.details()` and `handler.details_v6` will return a `Response` object that contains all fields
78
94
  listed in the [IPinfo developerdocs](https://ipinfo.io/developers/responses#full-response)
79
95
  with a few minor additions. Properties can be accessed directly.
80
96
 
@@ -84,18 +100,74 @@ hostname = details.hostname # cpe-104-175-221-247.socal.res.rr.com
84
100
 
85
101
  ##### Country Name
86
102
 
87
- `details.country_name` will return the country name, as supplied by the
88
- `countries.json` file. See below for instructions on changing that file for use
89
- with non-English languages. `details.country` will still return country code.
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.
90
106
 
91
107
  ```ruby
92
108
  country = details.country # US
93
109
  country_name = details.country_name # United States
94
110
  ```
95
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
+
96
168
  #### IP Address
97
169
 
98
- `details.ip_address` will return the an `IPAddr` object from the
170
+ `details.ip_address` will return the `IPAddr` object from the
99
171
  [Ruby Standard Library](https://ruby-doc.org/stdlib-2.5.1/libdoc/ipaddr/rdoc/IPAddr.html).
100
172
  `details.ip` will still return a string.
101
173
 
@@ -145,6 +217,23 @@ details.all = {
145
217
  }
146
218
  ```
147
219
 
220
+ ### Lite API
221
+
222
+ The library gives the possibility to use the [Lite API](https://ipinfo.io/developers/lite-api) too, authentication with your token is still required.
223
+
224
+ The returned details are slightly different from the Core API.
225
+
226
+ ```ruby
227
+ require 'ipinfo_lite'
228
+
229
+ access_token = '123456789abc'
230
+ handler = IPinfoLite::create(access_token)
231
+
232
+ details = handler.details('8.8.8.8')
233
+ details.country_code # US
234
+ details.country # United States
235
+ ```
236
+
148
237
  #### Caching
149
238
 
150
239
  In-memory caching of `details` data is provided by default via the
@@ -203,24 +292,22 @@ When looking up an IP address, the response object includes a
203
292
  American English. It is possible to return the country name in other languages
204
293
  by setting the `countries` setting when creating the `IPinfo` object.
205
294
 
206
- The file must be a `.json` file with the following structure:
207
-
208
295
  ```
209
296
  {
210
- "BD": "Bangladesh",
211
- "BE": "Belgium",
212
- "BF": "Burkina Faso",
213
- "BG": "Bulgaria"
297
+ "BD" => "Bangladesh",
298
+ "BE" => "Belgium",
299
+ "BF" => "Burkina Faso",
300
+ "BG" => "Bulgaria"
214
301
  ...
215
302
  }
216
303
  ```
217
304
 
218
305
  ### Other Libraries
219
306
 
220
- 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.
307
+ 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.
221
308
 
222
309
  ### About IPinfo
223
310
 
224
- 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, privacy detection, reverse IP, and IP type data sets. Our API handles over 20 billion requests a month for 100,000 businesses and developers.
311
+ 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.
225
312
 
226
313
  [![image](https://avatars3.githubusercontent.com/u/15721521?s=128&u=7bb7dde5c4991335fb234e68a30971944abc6bf3&v=4)](https://ipinfo.io/)
data/ipinfo.gemspec CHANGED
@@ -9,24 +9,22 @@ Gem::Specification.new do |spec|
9
9
  spec.name = 'IPinfo'
10
10
  spec.version = IPinfo::VERSION
11
11
  spec.required_ruby_version = '>= 2.5.0'
12
- spec.authors = ['Stanislav K, James Timmins', 'Uman Shahzad']
13
- spec.email = ['jameshtimmins@gmail.com', 'uman@mslm.io']
12
+ spec.authors = ['IPinfo releases']
13
+ spec.email = ['releases@ipinfo.io']
14
14
 
15
15
  spec.summary = ' This is a ruby wrapper for http://ipinfo.io. '
16
16
  spec.description = ' This is a ruby wrapper for http://ipinfo.io. '
17
17
  spec.homepage = 'https://ipinfo.io'
18
18
 
19
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the
20
- # 'allowed_push_host' to allow pushing to a single host or delete this
21
- # section to allow pushing to any host.
22
- if spec.respond_to?(:metadata)
23
- # spec.metadata['allowed_push_host'] = "http://mygemserver.com'"
24
- else
25
- raise 'RubyGems 2.0 or newer is required to protect against ' \
26
- 'public gem pushes.'
27
- end
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'
28
27
 
29
- spec.add_runtime_dependency 'faraday', '~> 1.0'
30
28
  spec.add_runtime_dependency 'json', '~> 2.1'
31
29
  spec.add_runtime_dependency 'lru_redux', '~> 1.1'
32
30
 
@@ -3,9 +3,136 @@
3
3
  require 'faraday'
4
4
  require 'cgi'
5
5
  require 'ipinfo/mod'
6
+ require_relative './version.rb'
6
7
 
7
8
  class IPinfo::Adapter
8
- HOST = 'ipinfo.io'
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
+
56
+ class IPinfo::AdapterLite
57
+ HOST = 'https://api.ipinfo.io/lite/'
58
+
59
+ attr_reader :conn
60
+
61
+ def initialize(token = nil, adapter = :net_http)
62
+ @token = token
63
+ @conn = connection(adapter)
64
+ end
65
+
66
+ def get(uri)
67
+ @conn.get(HOST + uri) do |req|
68
+ default_headers.each_pair do |key, value|
69
+ req.headers[key] = value
70
+ end
71
+ req.params['token'] = CGI.escape(token) if token
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ attr_reader :token
78
+
79
+ def connection(adapter)
80
+ Faraday.new() do |conn|
81
+ conn.adapter(adapter)
82
+ end
83
+ end
84
+
85
+ def default_headers
86
+ headers = {
87
+ 'User-Agent' => "IPinfoClient/Ruby/#{IPinfo::VERSION}",
88
+ 'Accept' => 'application/json'
89
+ }
90
+ headers['Authorization'] = "Bearer #{CGI.escape(token)}" if token
91
+ headers
92
+ end
93
+ end
94
+
95
+ class IPinfo::AdapterCore
96
+ HOST = 'https://api.ipinfo.io/lookup'
97
+
98
+ attr_reader :conn
99
+
100
+ def initialize(token = nil, adapter = :net_http)
101
+ @token = token
102
+ @conn = connection(adapter)
103
+ end
104
+
105
+ def get(uri)
106
+ @conn.get(HOST + uri) do |req|
107
+ default_headers.each_pair do |key, value|
108
+ req.headers[key] = value
109
+ end
110
+ req.params['token'] = CGI.escape(token) if token
111
+ end
112
+ end
113
+
114
+ private
115
+
116
+ attr_reader :token
117
+
118
+ def connection(adapter)
119
+ Faraday.new() do |conn|
120
+ conn.adapter(adapter)
121
+ end
122
+ end
123
+
124
+ def default_headers
125
+ headers = {
126
+ 'User-Agent' => "IPinfoClient/Ruby/#{IPinfo::VERSION}",
127
+ 'Accept' => 'application/json'
128
+ }
129
+ headers['Authorization'] = "Bearer #{CGI.escape(token)}" if token
130
+ headers
131
+ end
132
+ end
133
+
134
+ class IPinfo::AdapterPlus
135
+ HOST = 'https://api.ipinfo.io/lookup'
9
136
 
10
137
  attr_reader :conn
11
138
 
@@ -15,7 +142,7 @@ class IPinfo::Adapter
15
142
  end
16
143
 
17
144
  def get(uri)
18
- @conn.get(uri) do |req|
145
+ @conn.get(HOST + uri) do |req|
19
146
  default_headers.each_pair do |key, value|
20
147
  req.headers[key] = value
21
148
  end
@@ -28,14 +155,14 @@ class IPinfo::Adapter
28
155
  attr_reader :token
29
156
 
30
157
  def connection(adapter)
31
- Faraday.new(url: "https://#{HOST}") do |conn|
158
+ Faraday.new() do |conn|
32
159
  conn.adapter(adapter)
33
160
  end
34
161
  end
35
162
 
36
163
  def default_headers
37
164
  headers = {
38
- 'User-Agent' => 'IPinfoClient/Ruby/1.0',
165
+ 'User-Agent' => "IPinfoClient/Ruby/#{IPinfo::VERSION}",
39
166
  'Accept' => 'application/json'
40
167
  }
41
168
  headers['Authorization'] = "Bearer #{CGI.escape(token)}" if token