ipcountry 0.0.2 → 0.0.3

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: 80afd824ed97342e6da6f8f5a9525b64cccb2941
4
- data.tar.gz: 643a91130e0839e7bc0b820ce06de07aee04aef0
3
+ metadata.gz: a7e7cd2da87a4288e825bbd8f34702e518775304
4
+ data.tar.gz: bfbfe3e58b80a6dd8bcb2c281443b79c06345b47
5
5
  SHA512:
6
- metadata.gz: 58c6b459f11b6448c3c7c0df0455f1830cdb90edd6f7e155815b709cd9448363b566f93f5f613af21cec8f1583cb2bb3e4b2213d15e219f296dadfcc1f8db861
7
- data.tar.gz: 81601dd17eb38cc1a8a94cfc6812f010bbff2370ceeec96a42076d6461787edd0139c1c41d9d854aa431f1f8b3929c1cb7bbe7fe8e2fead6d2322ff20bc5d68a
6
+ metadata.gz: b53ca649dfcee681e392a03b09361736b35807ba112c68751ecdf06a64696cd4eefab817ee8c4d5ffda484c20af545002189b38c1eecfe9a9e3b4cbfeb7c7111
7
+ data.tar.gz: dd4fa776a7d03b06560d1977523fde0d42985fd067c240592b07b349d1d688d1d4d86d8634c083d6baaa270a32f1c086959600aaab4d26b12eca4aee887f7f24
data/bin/ipcountry ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ipcountry'
4
+
5
+ info = Ipcountry::Info.new(ARGV[0])
6
+ result = ''
7
+ if info.status == 'success'
8
+ result = info.query + ':' + info.country
9
+ else
10
+ result = info.query + ':' + info.message
11
+ end
12
+
13
+ p result
data/lib/ipcountry.rb CHANGED
@@ -10,12 +10,7 @@ module Ipcountry
10
10
  attr_accessor :result
11
11
 
12
12
  def initialize(ip)
13
- uri = URI.parse('http://ip-api.com/json/' + ip.to_s)
14
- https = Net::HTTP.new(uri.host, uri.port)
15
- res = https.start {
16
- https.get(uri.request_uri)
17
- }
18
-
13
+ res = connect(ip)
19
14
  if res.code == '200'
20
15
  @result = JSON.parse(res.body)
21
16
  else
@@ -23,20 +18,44 @@ module Ipcountry
23
18
  end
24
19
  end
25
20
 
21
+ def status
22
+ @result['status']
23
+ end
24
+
25
+ def message
26
+ @result['message']
27
+ end
28
+
26
29
  def country
27
- @result["country"]
30
+ @result['country']
28
31
  end
29
32
 
30
- def countryCode
31
- @result["countryCode"]
33
+ def countrycode
34
+ @result['countryCode']
32
35
  end
33
36
 
34
37
  def isp
35
- @result["isp"]
38
+ @result['isp']
36
39
  end
37
40
 
38
41
  def organization
39
- @result["org"]
42
+ @result['org']
43
+ end
44
+
45
+ def query
46
+ @result['query']
47
+ end
48
+
49
+ private
50
+
51
+ def connect(ip)
52
+ uri = URI.parse('http://ip-api.com/json/' + ip.to_s)
53
+ http = Net::HTTP.new(uri.host, uri.port)
54
+ http.use_ssl = true if uri.scheme == 'https'
55
+ res = http.start do |h|
56
+ h.get(uri.request_uri)
57
+ end
58
+ res
40
59
  end
41
60
  end
42
61
  end
@@ -1,3 +1,3 @@
1
1
  module Ipcountry
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipcountry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke Ohashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-09 00:00:00.000000000 Z
11
+ date: 2014-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -41,7 +41,8 @@ dependencies:
41
41
  description: This gem looks up ip address infomation. I use this api. http://ip-api.com/docs/api:json
42
42
  email:
43
43
  - yusuke@junkpiano.me
44
- executables: []
44
+ executables:
45
+ - ipcountry
45
46
  extensions: []
46
47
  extra_rdoc_files: []
47
48
  files:
@@ -50,6 +51,7 @@ files:
50
51
  - LICENSE.txt
51
52
  - README.md
52
53
  - Rakefile
54
+ - bin/ipcountry
53
55
  - ipcountry.gemspec
54
56
  - lib/ipcountry.rb
55
57
  - lib/ipcountry/version.rb