seventeen_mon 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: a67565bb88595073803e59351a86c4756ab42185
4
- data.tar.gz: 098be274cac30f71f87e03655fc07168d0f4beaf
3
+ metadata.gz: b6663d4ddeb5e3ea04c62da49b527bc038fe49a5
4
+ data.tar.gz: ba29fe84dbae2548803f64b3c6617ddfa17d38f1
5
5
  SHA512:
6
- metadata.gz: b829112def8be294ffce2ac952f9245e0d82e7bd95f528ee2564e42cdcd17c3c2391389718fc36b3d720db98c739c39f0bcf1bc18c114fd802f091cf4540dd79
7
- data.tar.gz: 84574fdbd059f0b7e640879a03b0db94f2ee48fddd1942d95bd151ed2391350dac9ca3442533e19a1b167d8424467aa1e2d82442e78c838dcec8fd1288253312
6
+ metadata.gz: 4cc0bb55fc45741bbef57719e27ad1f3c5d49cb32ba9d643760895ee34f1f3eb99e5175f80d18d36f597fe5d1b5947c5797c4b2b9f4d8ed2f55310efdfdf1ccd
7
+ data.tar.gz: 3ca3c66c11d64e171a6d04f8c76d889bfbae22efa660bc10b1c012d8ac46cca6bedbd189e3dc5548c4a48829ee55aec648dd873536ca9254b8efcaf65e2294c8
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SeventeenMon
2
2
 
3
- Simply find location by IP.
3
+ SeventeenMon simply help you find location by IP address. Data is totally based on [17MON.CN](http://tool.17mon.cn/).
4
4
 
5
5
 
6
6
  ## Installation
@@ -19,14 +19,28 @@ Or you can install simply by
19
19
 
20
20
  ## Usage
21
21
 
22
+ ### In Ruby
22
23
  ```(ruby)
23
- SeventeenMon.find_by_ip ip: "YOUR_IP_ADDRESS"
24
+ SM.find_by_ip "YOUR_IP_ADDRESS"
24
25
  # => {:country=>"英国", :city=>"英国"}
25
26
 
26
- SM.find_by_address address: "ruby-lang.com", protocol: "http"
27
+ SM.find_by_address "http://ruby-lang.com"
27
28
  # => {:country=>"荷兰", :city=>"荷兰"}
28
29
  ```
29
30
 
31
+ ### In Command Line
32
+
33
+ ```(bash)
34
+ $ seventeen ip 188.74.78.234
35
+ Country: 英国
36
+ City: 英国
37
+
38
+
39
+ $ seventeen address https://github.com
40
+ Country: 美国
41
+ City: 美国
42
+ ```
43
+
30
44
  ## Contributing
31
45
 
32
46
  1. Fork it ( http://github.com/<my-github-username>/seventeen_mom/fork )
@@ -34,3 +48,7 @@ SM.find_by_address address: "ruby-lang.com", protocol: "http"
34
48
  3. Commit your changes (`git commit -am 'Add some feature'`)
35
49
  4. Push to the branch (`git push origin my-new-feature`)
36
50
  5. Create new Pull Request
51
+
52
+ ## Thanks
53
+
54
+ [高春辉 Paul Gao](http://tool.17mon.cn/) - for his awesome data.
data/bin/seventeen ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH << File.dirname(__FILE__) + "/../lib" if $0 == __FILE__
3
+
4
+ require 'optparse'
5
+ require 'seventeen_mon'
6
+
7
+ CONFIG = {}
8
+ OPERATIONS = %w(ip address)
9
+
10
+ option_parser = OptionParser.new do |opts|
11
+ opts.banner = "Seventeen Mon #{SeventeenMon::VERSION}, a location finder for human\n" \
12
+ "Usage: #{File.basename(__FILE__)} [#{OPERATIONS.join('|')}] [pattern]"
13
+
14
+ opts.separator <<-EOS
15
+
16
+ Supported commands:
17
+
18
+ ip [pattern] Display the location by ip
19
+ address [pattern] Display the location by address
20
+
21
+
22
+ Example:
23
+ seventeen ip 188.74.78.234
24
+ seventeen address http://ruby-lang.com
25
+
26
+ Note: NSFW if you run seventeen as root.
27
+ EOS
28
+ end
29
+ option_parser.parse!
30
+
31
+
32
+ op = ARGV.shift
33
+ if OPERATIONS.include?(op)
34
+ begin
35
+ result = SM.send("find_by_#{op}".to_sym, ARGV.first)
36
+ puts <<-EOS
37
+ Country: #{result[:country]}
38
+ City: #{result[:city]}
39
+ EOS
40
+
41
+ rescue ArgumentError => ex
42
+ puts ex.message
43
+
44
+ rescue Exception => e
45
+ puts "Mmmmm, I didn't expect this:"
46
+ puts e.message
47
+ puts e.backtrace.join("\n")
48
+ end
49
+ else
50
+ puts option_parser.help
51
+ end
data/lib/seventeen_mon.rb CHANGED
@@ -12,8 +12,9 @@ module SeventeenMon
12
12
  IP.new(ip: _ip).find
13
13
  end
14
14
 
15
- def self.find_by_address(address: nil, protocol: "http")
16
- IP.new(address: address, protocol: protocol).find
15
+ def self.find_by_address(_address)
16
+ prot, addr = _address.split("://")
17
+ IP.new(address: addr, protocol: prot).find
17
18
  end
18
19
  end
19
20
 
@@ -1,3 +1,3 @@
1
1
  module SeventeenMon
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -13,10 +13,7 @@ describe SeventeenMon do
13
13
  describe "# query test" do
14
14
  before do
15
15
  @ip_param = "129.215.5.255"
16
- @url_params = {
17
- address: "www.ruby-lang.com",
18
- protocol: "http"
19
- }
16
+ @url_param = "http://www.ruby-lang.com"
20
17
  end
21
18
 
22
19
  it "can find location by ip" do
@@ -26,7 +23,7 @@ describe SeventeenMon do
26
23
  end
27
24
 
28
25
  it "can find location by address" do
29
- result = SM.find_by_address @url_params
26
+ result = SM.find_by_address @url_param
30
27
  result.should include(:city)
31
28
  result.should include(:country)
32
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seventeen_mon
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
  - Jingkai He
@@ -69,7 +69,8 @@ dependencies:
69
69
  description: Simply find location by IP.
70
70
  email:
71
71
  - jaxihe@gmail.com
72
- executables: []
72
+ executables:
73
+ - seventeen
73
74
  extensions: []
74
75
  extra_rdoc_files: []
75
76
  files:
@@ -78,6 +79,7 @@ files:
78
79
  - LICENSE.txt
79
80
  - README.md
80
81
  - Rakefile
82
+ - bin/seventeen
81
83
  - lib/data/17monipdb.dat
82
84
  - lib/seventeen_mon.rb
83
85
  - lib/seventeen_mon/ip.rb