geo_ip 0.6.2 → 0.7.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.
Files changed (5) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES.md +7 -0
  3. data/lib/geo_ip.rb +3 -2
  4. data/spec/geo_ip_spec.rb +52 -40
  5. metadata +10 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 50054c411a52ff7b1fe638e97720c28c4692f765
4
- data.tar.gz: dfa433e0664d7eee413191f6f8982d71f819bb70
2
+ SHA256:
3
+ metadata.gz: 1b657b45c91e3977b4d16e5f890e24c0acf9ce70cbcec8a29c72ab2c7ac7c0a1
4
+ data.tar.gz: 521cb290641b1011acb6d62364788f084569872803e94b475549c90b3851f38f
5
5
  SHA512:
6
- metadata.gz: 4580ba6425fcaf90b3cc0c5fbbb7e6bda60ec19d43e8523cd7cc822455fccbecb3f1776aa2b945d37a67de7dd0cb0bba9d4932156948cbf4c14490d962050dd4
7
- data.tar.gz: c56a070d072d073b20c73098247deda556bf90be1554c88f6c159a6c4b3cdcf3c2a57f9c0b2a80cbf0482d92a981cec43b5c1e040b38f2f8c741008bf29f7835
6
+ metadata.gz: 358758b68eee3a17a27082ec69242cf46a6e1760e6f6dd14e5f9d7b01b634e2b53ac0193351ee44b931de2ce060d7c4b6d8d9cb03a9a2933f1c80c63757c6252
7
+ data.tar.gz: 8b8f3e731d78609f6eb188b53a95e380d65a122bedb18214b797724ad30104ef126001d3d49dfa443a155ad6a52787ca95a1b03a2817918cd544f4ef70cf5502
data/CHANGES.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 0.7.0 (2018-03-03)
2
+
3
+ * Requires ruby >= 1.9.3 from the gemspec.
4
+ * Adds ruby 2.4 and 2.5 to the Travis build matrix
5
+ * Removes dependency on rest-client. By [elfenars](https://github.com/elfenars)
6
+ * Updates test suite to RSpec 3.x. By [elfenars](https://github.com/elfenars)
7
+
1
8
  ### 0.6.2 (2016-02-10)
2
9
 
3
10
  * Removes explicit json (gem) dependency as it is bundled with all supported ruby versions.
@@ -1,5 +1,6 @@
1
1
  require 'json'
2
- require 'rest-client'
2
+ require 'resolv'
3
+ require 'net/http'
3
4
 
4
5
  class GeoIp
5
6
  class InvalidPrecissionError < ArgumentError; end
@@ -66,7 +67,7 @@ class GeoIp
66
67
  def geolocation(ip, options = {})
67
68
  location = nil
68
69
  Timeout.timeout(fallback_timeout) do
69
- parsed_response = JSON.parse RestClient::Request.execute(method: :get, url: lookup_url(ip, options), timeout: timeout)
70
+ parsed_response = JSON.parse Net::HTTP.get(URI(lookup_url(ip, options)))
70
71
  location = convert_keys(parsed_response, options)
71
72
  end
72
73
 
@@ -12,6 +12,7 @@ USE_WEBMOCK = true
12
12
 
13
13
  describe 'GeoIp' do
14
14
  before :all do
15
+ @ruby_19 = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2')
15
16
  unless USE_WEBMOCK
16
17
  puts 'Running tests WITHOUT WebMock. You will need an internet connection. You may need to increase the GeoIp.fallback_timeout amount.'
17
18
  WebMock.disable!
@@ -19,9 +20,20 @@ describe 'GeoIp' do
19
20
  end
20
21
 
21
22
  def stub_geolocation(ip, options = {}, &_block)
23
+ headers = {
24
+ 'Accept' => '*/*',
25
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
26
+ 'Host' => 'api.ipinfodb.com',
27
+ 'User-Agent' => 'Ruby'
28
+ }
29
+ if @ruby_19
30
+ headers.delete('Accept-Encoding')
31
+ headers.delete('Host')
32
+ end
33
+
22
34
  if USE_WEBMOCK
23
35
  stub_request(:get, GeoIp.lookup_url(ip, options))
24
- .with(headers: { 'Accept' => '*/*; q=0.5, application/xml', 'Accept-Encoding' => 'gzip, deflate' })
36
+ .with(headers: headers)
25
37
  .to_return(status: 200, body: yield, headers: {})
26
38
  end
27
39
  end
@@ -34,12 +46,12 @@ describe 'GeoIp' do
34
46
  context 'api_key' do
35
47
  it 'should return the API key when set' do
36
48
  GeoIp.api_key = 'my_api_key'
37
- GeoIp.api_key.should == 'my_api_key'
49
+ expect(GeoIp.api_key).to eq('my_api_key')
38
50
  end
39
51
 
40
52
  it 'should throw an error when API key is not set' do
41
53
  GeoIp.api_key = nil
42
- -> { GeoIp.geolocation(IP_GOOGLE_US) }.should raise_error
54
+ expect { GeoIp.geolocation(IP_GOOGLE_US) }.to raise_error(GeoIp::ApiKeyError)
43
55
  end
44
56
  end
45
57
 
@@ -62,9 +74,9 @@ describe 'GeoIp' do
62
74
  end
63
75
 
64
76
  geolocation = GeoIp.geolocation(IP_GOOGLE_US)
65
- geolocation[:country_code].should == 'US'
66
- geolocation[:country_name].should == 'UNITED STATES'
67
- geolocation[:city].should == 'MONTEREY PARK'
77
+ expect(geolocation[:country_code]).to eq('US')
78
+ expect(geolocation[:country_name]).to eq('UNITED STATES')
79
+ expect(geolocation[:city]).to eq('MONTEREY PARK')
68
80
  end
69
81
 
70
82
  it 'should return nothing city for a private ip address' do
@@ -85,9 +97,9 @@ describe 'GeoIp' do
85
97
  end
86
98
 
87
99
  geolocation = GeoIp.geolocation(IP_PRIVATE)
88
- geolocation[:country_code].should == '-'
89
- geolocation[:country_name].should == '-'
90
- geolocation[:city].should == '-'
100
+ expect(geolocation[:country_code]).to eq('-')
101
+ expect(geolocation[:country_name]).to eq('-')
102
+ expect(geolocation[:city]).to eq('-')
91
103
  end
92
104
 
93
105
  it 'should return nothing for localhost ip address' do
@@ -108,9 +120,9 @@ describe 'GeoIp' do
108
120
  end
109
121
 
110
122
  geolocation = GeoIp.geolocation(IP_LOCAL)
111
- geolocation[:country_code].should == '-'
112
- geolocation[:country_name].should == '-'
113
- geolocation[:city].should == '-'
123
+ expect(geolocation[:country_code]).to eq('-')
124
+ expect(geolocation[:country_name]).to eq('-')
125
+ expect(geolocation[:city]).to eq('-')
114
126
  end
115
127
 
116
128
  it 'should return the correct city for a public ip address when explicitly requiring it' do
@@ -131,9 +143,9 @@ describe 'GeoIp' do
131
143
  end
132
144
 
133
145
  geolocation = GeoIp.geolocation(IP_GOOGLE_US, precision: :city)
134
- geolocation[:country_code].should == 'US'
135
- geolocation[:country_name].should == 'UNITED STATES'
136
- geolocation[:city].should == 'MONTEREY PARK'
146
+ expect(geolocation[:country_code]).to eq('US')
147
+ expect(geolocation[:country_name]).to eq('UNITED STATES')
148
+ expect(geolocation[:city]).to eq('MONTEREY PARK')
137
149
  end
138
150
  end
139
151
 
@@ -149,8 +161,8 @@ describe 'GeoIp' do
149
161
  })
150
162
  end
151
163
  geolocation = GeoIp.geolocation(IP_GOOGLE_US, precision: :country)
152
- geolocation[:country_code].should == 'US'
153
- geolocation[:country_name].should == 'UNITED STATES'
164
+ expect(geolocation[:country_code]).to eq('US')
165
+ expect(geolocation[:country_name]).to eq('UNITED STATES')
154
166
  end
155
167
 
156
168
  it 'should return nothing country for a private ip address' do
@@ -164,8 +176,8 @@ describe 'GeoIp' do
164
176
  })
165
177
  end
166
178
  geolocation = GeoIp.geolocation(IP_PRIVATE, precision: :country)
167
- geolocation[:country_code].should == '-'
168
- geolocation[:country_name].should == '-'
179
+ expect(geolocation[:country_code]).to eq('-')
180
+ expect(geolocation[:country_name]).to eq('-')
169
181
  end
170
182
 
171
183
  it 'should return nothing country for localhost ip address' do
@@ -179,8 +191,8 @@ describe 'GeoIp' do
179
191
  })
180
192
  end
181
193
  geolocation = GeoIp.geolocation(IP_LOCAL, precision: :country)
182
- geolocation[:country_code].should == '-'
183
- geolocation[:country_name].should == '-'
194
+ expect(geolocation[:country_code]).to eq('-')
195
+ expect(geolocation[:country_name]).to eq('-')
184
196
  end
185
197
 
186
198
  it 'should not return the city for a public ip address' do
@@ -194,9 +206,9 @@ describe 'GeoIp' do
194
206
  })
195
207
  end
196
208
  geolocation = GeoIp.geolocation(IP_GOOGLE_US, precision: :country)
197
- geolocation[:country_code].should == 'US'
198
- geolocation[:country_name].should == 'UNITED STATES'
199
- geolocation[:city].should be_nil
209
+ expect(geolocation[:country_code]).to eq('US')
210
+ expect(geolocation[:country_name]).to eq('UNITED STATES')
211
+ expect(geolocation[:city]).to eq(nil)
200
212
  end
201
213
  end
202
214
 
@@ -218,7 +230,7 @@ describe 'GeoIp' do
218
230
  })
219
231
  end
220
232
  geolocation = GeoIp.geolocation(IP_GOOGLE_US, timezone: true)
221
- geolocation[:timezone].should == '-08:00' # This one is likely to break when dst changes.
233
+ expect(geolocation[:timezone]).to eq('-08:00') # This one is likely to break when dst changes.
222
234
  end
223
235
 
224
236
  it 'should not return the timezone information when explicitly not requesting it' do
@@ -238,7 +250,7 @@ describe 'GeoIp' do
238
250
  })
239
251
  end
240
252
  geolocation = GeoIp.geolocation(IP_GOOGLE_US, timezone: false)
241
- geolocation[:timezone].should be_nil
253
+ expect(geolocation[:timezone]).to eq(nil)
242
254
  end
243
255
 
244
256
  it 'should not return the timezone information when not requesting it' do
@@ -258,7 +270,7 @@ describe 'GeoIp' do
258
270
  })
259
271
  end
260
272
  geolocation = GeoIp.geolocation(IP_GOOGLE_US)
261
- geolocation[:timezone].should be_nil
273
+ expect(geolocation[:timezone]).to eq(nil)
262
274
  end
263
275
 
264
276
  it 'should not return the timezone information when country precision is selected' do
@@ -278,26 +290,26 @@ describe 'GeoIp' do
278
290
  })
279
291
  end
280
292
  geolocation = GeoIp.geolocation(IP_GOOGLE_US, precision: :country, timezone: true)
281
- geolocation[:timezone].should be_nil
293
+ expect(geolocation[:timezone]).to eq(nil)
282
294
  end
283
295
  end
284
296
 
285
297
  context 'timeout' do
286
298
  it 'should trigger timeout when the request is taking too long' do
287
299
  stub_request(:get, GeoIp.lookup_url(IP_GOOGLE_US)).to_timeout
288
- -> { GeoIp.geolocation(IP_GOOGLE_US) }.should raise_exception('Request Timeout')
300
+ expect { GeoIp.geolocation(IP_GOOGLE_US) }.to raise_error(Timeout::Error)
289
301
  end
290
302
 
291
- it 'should trigger fallback timeout when RestClient is taking too long to send the request', focus: true do
303
+ it 'should trigger fallback timeout when Net::HTTP is taking too long to send the request', focus: true do
292
304
  GeoIp.fallback_timeout = 1
293
- RestClient::Request.stub(:execute) { sleep 2 }
294
- -> { GeoIp.geolocation(IP_GOOGLE_US) }.should raise_exception(Timeout::Error)
305
+ allow(Net::HTTP).to receive(:get) { sleep 2 }
306
+ expect { GeoIp.geolocation(IP_GOOGLE_US) }.to raise_error(Timeout::Error)
295
307
  end
296
308
  end
297
309
 
298
310
  context 'ip' do
299
311
  it 'should trigger invalid ip when invalid IPv4 address is provided' do
300
- RestClient::Request.stub(:execute) do
312
+ allow(Net::HTTP).to receive(:get) do
301
313
  %({
302
314
  "statusCode" : "OK",
303
315
  "statusMessage" : "",
@@ -312,11 +324,11 @@ describe 'GeoIp' do
312
324
  "timeZone" : "-08:00"
313
325
  })
314
326
  end
315
- -> { GeoIp.geolocation(IPV4_INVALID) }.should raise_error(GeoIp::InvalidIpError)
327
+ expect { GeoIp.geolocation(IPV4_INVALID) }.to raise_error(GeoIp::InvalidIpError)
316
328
  end
317
329
 
318
330
  it 'should not trigger invalid ip when valid IPv4 address is provided' do
319
- RestClient::Request.stub(:execute) do
331
+ allow(Net::HTTP).to receive(:get) do
320
332
  %({
321
333
  "statusCode" : "OK",
322
334
  "statusMessage" : "",
@@ -331,11 +343,11 @@ describe 'GeoIp' do
331
343
  "timeZone" : "-08:00"
332
344
  })
333
345
  end
334
- -> { GeoIp.geolocation(IP_GOOGLE_US) }.should_not raise_error(GeoIp::InvalidIpError)
346
+ expect { GeoIp.geolocation(IP_GOOGLE_US) }.not_to raise_error
335
347
  end
336
348
 
337
349
  it 'should trigger invalid ip when invalid IPv6 address is provided' do
338
- RestClient::Request.stub(:execute) do
350
+ allow(Net::HTTP).to receive(:get) do
339
351
  %({
340
352
  "statusCode" : "OK",
341
353
  "statusMessage" : "",
@@ -350,11 +362,11 @@ describe 'GeoIp' do
350
362
  "timeZone" : "-08:00"
351
363
  })
352
364
  end
353
- -> { GeoIp.geolocation(IPV6_INVALID) }.should raise_error(GeoIp::InvalidIpError)
365
+ expect { GeoIp.geolocation(IPV6_INVALID) }.to raise_error(GeoIp::InvalidIpError)
354
366
  end
355
367
 
356
368
  it 'should not trigger invalid ip when valid IPv6 address is provided' do
357
- RestClient::Request.stub(:execute) do
369
+ allow(Net::HTTP).to receive(:get) do
358
370
  %({
359
371
  "statusCode" : "OK",
360
372
  "statusMessage" : "",
@@ -369,7 +381,7 @@ describe 'GeoIp' do
369
381
  "timeZone" : "-08:00"
370
382
  })
371
383
  end
372
- -> { GeoIp.geolocation(IPV6) }.should_not raise_error(GeoIp::InvalidIpError)
384
+ expect { GeoIp.geolocation(IPV6) }.not_to raise_error
373
385
  end
374
386
  end
375
387
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geo_ip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeroen Jacobs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-10 00:00:00.000000000 Z
11
+ date: 2018-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rest-client
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.6'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.6'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +30,28 @@ dependencies:
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '2.5'
33
+ version: '3.0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '2.5'
40
+ version: '3.0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: webmock
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: 1.7.10
47
+ version: 2.3.2
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: 1.7.10
54
+ version: 2.3.2
69
55
  description: A call to the ipinfodb.com will be done to retreive the geolocation based
70
56
  on the IP address. No need to include a database file in the application.
71
57
  email: gems@jeroenj.be
@@ -93,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - ">="
95
81
  - !ruby/object:Gem::Version
96
- version: '0'
82
+ version: 1.9.3
97
83
  required_rubygems_version: !ruby/object:Gem::Requirement
98
84
  requirements:
99
85
  - - ">="
@@ -101,14 +87,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
87
  version: '0'
102
88
  requirements: []
103
89
  rubyforge_project:
104
- rubygems_version: 2.4.5.1
90
+ rubygems_version: 2.7.3
105
91
  signing_key:
106
92
  specification_version: 4
107
93
  summary: Retreive the geolocation of an IP address based on the ipinfodb.com webservice
108
94
  test_files:
109
95
  - spec/api.yml
96
+ - spec/spec_helper.rb
97
+ - spec/spec.opts
110
98
  - spec/api.yml.example
111
99
  - spec/geo_ip_spec.rb
112
- - spec/spec.opts
113
- - spec/spec_helper.rb
114
- has_rdoc: