maxminddb 0.1.5 → 0.1.6

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
  SHA1:
3
- metadata.gz: 1ccc719cee1ac141b4abaf9117a8435c83b62bab
4
- data.tar.gz: 3ed0d4ce4aca0205a28ab3385ffaae351be18e66
3
+ metadata.gz: e4123fd648335c765ce70e82b825f7f86b0622c7
4
+ data.tar.gz: 24ff23c932348c1e92e3d700eda52cca12c48a2f
5
5
  SHA512:
6
- metadata.gz: 1b20b63de9020ef9022a9366c4b09b16f054cd262966427c11f97c7732239f6ea7e54a5f43d8694a79cc2096e8fca693f2ff83012aadb1c103398e29038da3ff
7
- data.tar.gz: 06ed3cf8dd0b3cc30ee3c1cc325838e96e930f236c8fbae1183886349127ad0468018a3d65370a1f5d8855afdba0a820fbcdc472941b1ad45940a2cdfe67ad0c
6
+ metadata.gz: c9f55ee36337167a41a434b81fbeb005db3afee197286d0c5563b042492f8cd1835c207b6641945bdbdb40aedd9164eb6d6e1fd92c22c67b4e928a02d8577406
7
+ data.tar.gz: d2692e6285d4782c1c557ee11c0585ea59e6520bcba5f6a9898fbf5f1db1079051a9b054a5120567b1ca989af2b423f6e1fb52bfccbde7568b3d0548222a50e4
@@ -1,6 +1,7 @@
1
1
  require_relative 'result/location'
2
2
  require_relative 'result/named_location'
3
3
  require_relative 'result/postal'
4
+ require_relative 'result/traits'
4
5
 
5
6
  module MaxMindDB
6
7
  class Result
@@ -48,6 +49,10 @@ module MaxMindDB
48
49
  @_subdivisions ||= Array(raw['subdivisions']).map { |hash| NamedLocation.new(hash) }
49
50
  end
50
51
 
52
+ def traits
53
+ @_traits ||= Traits.new(raw['traits'])
54
+ end
55
+
51
56
  private
52
57
 
53
58
  attr_reader :raw
@@ -0,0 +1,21 @@
1
+ module MaxMindDB
2
+ class Result
3
+ class Traits
4
+ def initialize(raw)
5
+ @raw = raw || {}
6
+ end
7
+
8
+ def is_anonymous_proxy
9
+ raw['is_anonymous_proxy']
10
+ end
11
+
12
+ def is_satellite_provider
13
+ raw['is_satellite_provider']
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :raw
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module MaxMindDB
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -0,0 +1,40 @@
1
+ require 'maxminddb'
2
+
3
+ describe MaxMindDB::Result::Traits do
4
+ subject(:result) { described_class.new(raw_result) }
5
+
6
+ context "with an is_anonymous_proxy result" do
7
+ let(:raw_result) { {
8
+ "is_anonymous_proxy"=>true
9
+ } }
10
+
11
+ its(:is_anonymous_proxy) { should eq(true) }
12
+ its(:is_satellite_provider) { should eq(nil) }
13
+ end
14
+
15
+ context "with an is_satellite_provider result" do
16
+ let(:raw_result) { {
17
+ "is_satellite_provider"=>true
18
+ } }
19
+
20
+ its(:is_anonymous_proxy) { should eq(nil) }
21
+ its(:is_satellite_provider) { should eq(true) }
22
+ end
23
+
24
+ context "with an all traits result" do
25
+ let(:raw_result) { {
26
+ "is_anonymous_proxy"=>true,
27
+ "is_satellite_provider"=>true
28
+ } }
29
+
30
+ its(:is_anonymous_proxy) { should eq(true) }
31
+ its(:is_satellite_provider) { should eq(true) }
32
+ end
33
+
34
+ context "without a result" do
35
+ let(:raw_result) { nil }
36
+
37
+ its(:is_anonymous_proxy) { should eq(nil) }
38
+ its(:is_satellite_provider) { should eq(nil) }
39
+ end
40
+ end
@@ -37,6 +37,9 @@ describe MaxMindDB::Result do
37
37
  "iso_code"=>"US",
38
38
  "names"=>{"de"=>"USA", "en"=>"United States", "es"=>"Estados Unidos", "fr"=>"États-Unis", "ja"=>"アメリカ合衆国", "pt-BR"=>"Estados Unidos", "ru"=>"США", "zh-CN"=>"美国"}
39
39
  },
40
+ "traits"=>{
41
+ "is_satellite_provider"=>true
42
+ },
40
43
  "subdivisions"=>[
41
44
  {
42
45
  "geoname_id"=>5332921,
@@ -239,4 +242,26 @@ describe MaxMindDB::Result do
239
242
  end
240
243
  end
241
244
  end
245
+
246
+ describe '#traits' do
247
+ context 'with a result' do
248
+ it 'should return a kind of MaxMindDB::Result::Traits' do
249
+ expect(result.traits).to be_kind_of(MaxMindDB::Result::Traits)
250
+ end
251
+
252
+ it 'should initialize the object with the traits attributes' do
253
+ expect(MaxMindDB::Result::Traits).to receive(:new).with(raw_result['traits'])
254
+
255
+ result.traits
256
+ end
257
+ end
258
+
259
+ context "without a result" do
260
+ let(:raw_result) { nil }
261
+
262
+ it 'should be a kind of MaxMindDB::Result::Traits' do
263
+ expect(result.traits).to be_kind_of(MaxMindDB::Result::Traits)
264
+ end
265
+ end
266
+ end
242
267
  end
@@ -23,6 +23,10 @@ describe MaxMindDB do
23
23
  expect(city_db.lookup(ip).location.longitude).to eq(-122.0574)
24
24
  end
25
25
 
26
+ it 'returns nil for is_anonymous_proxy' do
27
+ expect(city_db.lookup(ip).traits.is_anonymous_proxy).to eq(nil)
28
+ end
29
+
26
30
  it 'returns United States as the English country name' do
27
31
  expect(country_db.lookup(ip).country.name).to eq('United States')
28
32
  end
@@ -99,6 +103,14 @@ describe MaxMindDB do
99
103
  end
100
104
  end
101
105
  end
106
+
107
+ context 'test boolean data' do
108
+ let(:ip) { '41.194.0.1' }
109
+
110
+ it 'returns true for the is_satellite_provider trait' do
111
+ expect(city_db.lookup(ip).traits.is_satellite_provider).to eq(true)
112
+ end
113
+ end
102
114
  end
103
115
 
104
116
  # vim: et ts=2 sw=2 ff=unix
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maxminddb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - yhirose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-16 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,12 +85,14 @@ files:
85
85
  - lib/maxminddb/result/location.rb
86
86
  - lib/maxminddb/result/named_location.rb
87
87
  - lib/maxminddb/result/postal.rb
88
+ - lib/maxminddb/result/traits.rb
88
89
  - lib/maxminddb/version.rb
89
90
  - maxminddb.gemspec
90
91
  - spec/cache/.gitkeep
91
92
  - spec/maxminddb/result/location_spec.rb
92
93
  - spec/maxminddb/result/named_location_spec.rb
93
94
  - spec/maxminddb/result/postal_spec.rb
95
+ - spec/maxminddb/result/trait_spec.rb
94
96
  - spec/maxminddb/result_spec.rb
95
97
  - spec/maxminddb_spec.rb
96
98
  homepage: https://github.com/yhirose/maxminddb
@@ -122,5 +124,6 @@ test_files:
122
124
  - spec/maxminddb/result/location_spec.rb
123
125
  - spec/maxminddb/result/named_location_spec.rb
124
126
  - spec/maxminddb/result/postal_spec.rb
127
+ - spec/maxminddb/result/trait_spec.rb
125
128
  - spec/maxminddb/result_spec.rb
126
129
  - spec/maxminddb_spec.rb