IPinfo 1.1.0 β†’ 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd107edec906894bab2445a4d7bc9b551fc79778c7b941a2dfa486d32c969e47
4
- data.tar.gz: 1a67c2f0a6c7bbb57209982e1c1e92868aa218deec445826cef2f5ecb91eac5d
3
+ metadata.gz: 8f1468d25c477278fcae675ca1b4216bb5b205806dd1d23a18c43e9f5d6c0292
4
+ data.tar.gz: f246e5393f940fff6780227341695b9d25126d2be12f575c587742d14f3196f6
5
5
  SHA512:
6
- metadata.gz: fe484b50604b7ce3dd70aa8cddc0165b0416b358933ef932d2bd93d83587ab6b4892e4e721be2ca53687cba8bc6c849cd9aab67c1aff11e69fd022d62a26faf1
7
- data.tar.gz: b934e0bb1291651ebffe1628ae344294f4a7be1e6ba6c9354eaf9770f8c218e6209df843e2d4d891cd6bce35aee1c090c880fda2e850e0727ee87e954b2d6fd9
6
+ metadata.gz: d58a691406d3f068864a4da3fb340cf0624a4c7963cf0a4347c84a53b31dce106e6d432f7794f430522690ec84c26b2840f71bb113f58d16462aa484150e99ac
7
+ data.tar.gz: 439230365af148fa67ace9677bc1b7405032bff1ed581d03627aea2d9f469a9270b8aa91b56d1bcb7e0a517cf7e9a841328e87a6578d394dffaeb48af81331bc
@@ -14,6 +14,9 @@ jobs:
14
14
  - name: Checkout
15
15
  uses: actions/checkout@v3
16
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
+
17
20
  - name: Set up Ruby
18
21
  uses: ruby/setup-ruby@v1
19
22
 
@@ -12,13 +12,17 @@ jobs:
12
12
  runs-on: ubuntu-latest
13
13
  strategy:
14
14
  matrix:
15
- ruby-version: ['3.1', '3.0', '2.7', '2.6']
15
+ ruby-version: ['3.2', '3.1', '3.0', '2.7', '2.6']
16
16
 
17
17
  steps:
18
- - uses: actions/checkout@v3
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
19
23
 
20
24
  - name: Set up Ruby ${{ matrix.ruby-version }}
21
- uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108
25
+ uses: ruby/setup-ruby@v1
22
26
  with:
23
27
  ruby-version: ${{ matrix.ruby-version }}
24
28
 
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.2
1
+ 3.2.2
data/README.md CHANGED
@@ -40,6 +40,7 @@ handler = IPinfo::create(access_token)
40
40
  ip_address = '216.239.36.21'
41
41
 
42
42
  details = handler.details(ip_address)
43
+ details_v6 = handler.details_v6() # to get details from ipinfo's IPv6 host
43
44
  city = details.city # Emeryville
44
45
  loc = details.loc # 37.8342,-122.2900
45
46
  ```
@@ -58,7 +59,7 @@ require 'ipinfo' unless defined?(IPinfo)
58
59
 
59
60
  #### Usage
60
61
 
61
- The `IPinfo.details()` method accepts an IP address as an optional, positional
62
+ The `IPinfo.details()` and `IPinfo.details_v6()` methods accept an IP address as an optional, positional
62
63
  argument. If no IP address is specified, the API will return data for the IP
63
64
  address from which it receives the request.
64
65
 
@@ -69,6 +70,7 @@ access_token = '123456789abc'
69
70
  handler = IPinfo::create(access_token)
70
71
 
71
72
  details = handler.details()
73
+ details_v6 = handler.details_v6() # to get details from ipinfo's IPv6 host
72
74
  city = details.city # "Emeryville"
73
75
  loc = details.loc # 37.8342,-122.2900
74
76
  ```
@@ -86,7 +88,7 @@ handler = IPinfo::create(access_token)
86
88
 
87
89
  #### Details Data
88
90
 
89
- `handler.details()` will return a `Response` object that contains all fields
91
+ `handler.details()` and `handler.details_v6` will return a `Response` object that contains all fields
90
92
  listed in the [IPinfo developerdocs](https://ipinfo.io/developers/responses#full-response)
91
93
  with a few minor additions. Properties can be accessed directly.
92
94
 
@@ -96,8 +98,8 @@ hostname = details.hostname # cpe-104-175-221-247.socal.res.rr.com
96
98
 
97
99
  ##### Country Name
98
100
 
99
- `details.country_name` will return the country name, as supplied by the
100
- `countries.json` file. See below for instructions on changing that file for use
101
+ `details.country_name` will return the country name, as defined by `DEFAULT_COUNTRY_LIST`
102
+ within `countriesData.rb`. See below for instructions on changing that file for use
101
103
  with non-English languages. `details.country` will still return the country code.
102
104
 
103
105
  ```ruby
@@ -107,7 +109,8 @@ country_name = details.country_name # United States
107
109
 
108
110
  ##### European Union (EU) Country
109
111
 
110
- `details.is_eu` will return `true` if the country is a member of the European Union (EU), as supplied by the `eu.json` file.
112
+ `details.is_eu` will return `true` if the country is a member of the European Union (EU)
113
+ , as defined by `DEFAULT_EU_COUNTRIES_LIST` within `countriesData.rb`.
111
114
 
112
115
  ```ruby
113
116
  is_eu = details.is_eu # false
@@ -115,11 +118,10 @@ is_eu = details.is_eu # false
115
118
 
116
119
  It is possible to change the file by setting the `eu_countries` setting when creating the `IPinfo` object.
117
120
 
118
- The file must be a `.json` file with the [following structure](lib/ipinfo/eu.json).
119
-
120
121
  ##### Country Flag
121
122
 
122
- `details.country_flag` will return `emoji` and `unicode` of a country's flag, as supplied by the `eu.json` file.
123
+ `details.country_flag` will return `emoji` and `unicode` of a country's flag, as defined by
124
+ `DEFAULT_COUNTRIES_FLAG_LIST` within `countriesData.rb`.
123
125
 
124
126
  ```ruby
125
127
  country_flag = details.country_flag # {"emoji"=>"πŸ‡ΊπŸ‡Έ", "unicode"=>"U+1F1FA U+1F1F8"}
@@ -137,7 +139,8 @@ country_flag = details.country_flag_url # {"https://cdn.ipinfo.io/static/images/
137
139
 
138
140
  ##### Country Currency
139
141
 
140
- `details.country_currency` will return `code` and `symbol` of a country's currency, as supplied by the `currency.json` file.
142
+ `details.country_currency` will return `code` and `symbol` of a country's currency, as defined by
143
+ `DEFAULT_COUNTRIES_CURRENCIES_LIST` within `countriesData.rb`.
141
144
 
142
145
  ```ruby
143
146
  country_currency = details.country_currency # {"code"=>"USD", "symbol"=>"$"}
@@ -147,11 +150,10 @@ country_currency_symbol = details.country_currency['symbol'] # $
147
150
 
148
151
  It is possible to change the file by setting the `countries_currencies` setting when creating the `IPinfo` object.
149
152
 
150
- The file must be a `.json` file with the [following structure](lib/ipinfo/currency.json).
151
-
152
153
  ##### Continent
153
154
 
154
- `details.continent` will return `code` and `name` of the continent, as supplied by the `continent.json` file.
155
+ `details.continent` will return `code` and `name` of the continent, as defined by
156
+ `DEFAULT_CONTINENT_LIST` within `countriesData.rb`.
155
157
 
156
158
  ```ruby
157
159
  continent = details.continent # {"code"=>"NA", "name"=>"North America"}
@@ -161,8 +163,6 @@ continent_name = details.continent['name'] # North America
161
163
 
162
164
  It is possible to change the file by setting the `continents` setting when creating the `IPinfo` object.
163
165
 
164
- The file must be a `.json` file with the [following structure](lib/ipinfo/continent.json).
165
-
166
166
  #### IP Address
167
167
 
168
168
  `details.ip_address` will return the `IPAddr` object from the
@@ -273,14 +273,12 @@ When looking up an IP address, the response object includes a
273
273
  American English. It is possible to return the country name in other languages
274
274
  by setting the `countries` setting when creating the `IPinfo` object.
275
275
 
276
- The file must be a `.json` file with the following structure:
277
-
278
276
  ```
279
277
  {
280
- "BD": "Bangladesh",
281
- "BE": "Belgium",
282
- "BF": "Burkina Faso",
283
- "BG": "Bulgaria"
278
+ "BD" => "Bangladesh",
279
+ "BE" => "Belgium",
280
+ "BF" => "Burkina Faso",
281
+ "BG" => "Bulgaria"
284
282
  ...
285
283
  }
286
284
  ```
data/ipinfo.gemspec CHANGED
@@ -16,7 +16,15 @@ Gem::Specification.new do |spec|
16
16
  spec.description = ' This is a ruby wrapper for http://ipinfo.io. '
17
17
  spec.homepage = 'https://ipinfo.io'
18
18
 
19
- spec.add_runtime_dependency 'faraday', '~> 1.0'
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
+
20
28
  spec.add_runtime_dependency 'json', '~> 2.1'
21
29
  spec.add_runtime_dependency 'lru_redux', '~> 1.1'
22
30
 
@@ -3,9 +3,11 @@
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'
9
11
 
10
12
  attr_reader :conn
11
13
 
@@ -14,8 +16,9 @@ class IPinfo::Adapter
14
16
  @conn = connection(adapter)
15
17
  end
16
18
 
17
- def get(uri)
18
- @conn.get(uri) do |req|
19
+ def get(uri, host_type= :v4)
20
+ host = (host_type == :v6) ? HOST_V6 : HOST
21
+ @conn.get(host + uri) do |req|
19
22
  default_headers.each_pair do |key, value|
20
23
  req.headers[key] = value
21
24
  end
@@ -24,7 +27,7 @@ class IPinfo::Adapter
24
27
  end
25
28
 
26
29
  def post(uri, body, timeout = 2)
27
- @conn.post(uri) do |req|
30
+ @conn.post(HOST + uri) do |req|
28
31
  req.body = body
29
32
  req.options.timeout = timeout
30
33
  end
@@ -35,14 +38,14 @@ class IPinfo::Adapter
35
38
  attr_reader :token
36
39
 
37
40
  def connection(adapter)
38
- Faraday.new(url: "https://#{HOST}") do |conn|
41
+ Faraday.new() do |conn|
39
42
  conn.adapter(adapter)
40
43
  end
41
44
  end
42
45
 
43
46
  def default_headers
44
47
  headers = {
45
- 'User-Agent' => 'IPinfoClient/Ruby/1.1.0',
48
+ 'User-Agent' => "IPinfoClient/Ruby/#{IPinfo::VERSION}",
46
49
  'Accept' => 'application/json'
47
50
  }
48
51
  headers['Authorization'] = "Bearer #{CGI.escape(token)}" if token