hostip 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e4401e8218709f87b556408950d6cd1128649866
4
+ data.tar.gz: 056c6d80a71cfc2fca77029adb1182b7578bd81f
5
+ SHA512:
6
+ metadata.gz: 66c38885955adfdda6355a99665aabca561125fb446181011578be5836bf2b27f02948974fc2ed3f81a1db9b69b33b77bf77bde097e5629255ee1c1ffeefed50
7
+ data.tar.gz: ca1d9a61d195af272b29626c7cbc748e655149b4f3f41e59c707a1bfbac1cecb9fd29b2f95efbe03760c0128fe94abf068efe09d8b2b8024c65fc28c3237367e
@@ -1,33 +1,52 @@
1
- == hostip
1
+ ![Status](https://travis-ci.org/sideshowcoder/hostip-gem.png)
2
+
3
+ # hostip
2
4
 
3
5
  A simple Ruby Gem wrapper for hostip.info
6
+
4
7
  Includes a command line tool hostip to get all information from the command line as well
5
- == example
6
-
7
- require 'rubygems'
8
- require 'hostip'
9
-
10
- hip = Hostip.new
11
-
12
- # get current ip
13
- hip.ip
14
-
15
- # get current country
16
- hip.country_name
17
- # get country abbriviated
18
- hip.country_abbrev
19
- # get current geo location
20
- hip.geo_location
21
-
22
- # all this also works for a given ip like 74.125.77.104 (google.com)
23
- hip.geo_location "74.125.77.104"
24
- hip.country_name "74.125.77.104"
25
-
26
- == license
8
+
9
+ ## example
10
+
11
+ ```ruby
12
+ require 'hostip'
13
+
14
+ hip = Hostip.new
15
+
16
+ # get current ip
17
+ hip.ip
18
+
19
+ # get current country
20
+ hip.country_name
21
+ # get country abbriviated
22
+ hip.country_abbrev
23
+ # get current geo location
24
+ hip.geo_location
25
+
26
+ # all this also works for a given ip like 74.125.77.104 (google.com)
27
+ hip.geo_location "74.125.77.104"
28
+ hip.country_name "74.125.77.104"
29
+ ```
30
+
31
+ ## command line
32
+ ```shell
33
+ $ hostip --help
34
+ hostip version 0.2.0
35
+ Usage: hostip [options]
36
+ -v, --version display version
37
+ -h, --help display help
38
+ -V, --verbose be more verbose
39
+ --city get the city only i.e. Munich
40
+ --geo get longtitude and latitude, i.e. 12.45, 12.23
41
+ --country get the country i.e. Germany
42
+ --country-abbrev get the country abbreviation i.e. US
43
+ ```
44
+
45
+ ## license
27
46
 
28
47
  (the BSD license)
29
48
 
30
- Copyright 2010 Philipp Fehre. All rights reserved.
49
+ Copyright 2013 Philipp Fehre. All rights reserved.
31
50
 
32
51
  Redistribution and use in source and binary forms, with or without modification, are
33
52
  permitted provided that the following conditions are met:
data/bin/hostip CHANGED
@@ -1,191 +1,124 @@
1
- #!/usr/bin/env ruby
2
-
3
- # == Synopsis
4
- # Get info from hostip.info service about current IP and Geo Location
5
- #
6
- # == Examples
7
- # Get ip
8
- # hostip
9
- # Get city
10
- # hostip --city
11
- # Get longtitude and latitude
12
- # hostip --geo
13
- #
14
- # Also works for any given IP
15
- # hostip --city 123.456.789.1
16
- #
17
- # == Usage
18
- # hostip [options] [ip]
19
- #
20
- # For help use: hostip -h
21
- #
22
- # == Options
23
- # -h, --help Displays help message
24
- # -v, --version Display version
25
- # -V, --verbose Be more verbose
26
- # --city Get city (Munich)
27
- # --geo Get longtitude and latitude (12.4567,12.2345)
28
- # --country Get country (ie Germany)
29
- # --country-abbrev Get country abbreviation (ie US)
30
- #
31
- # == Author
32
- # Philipp Fehre (philipp.fehre@googlemail.com)
33
- #
34
- # == Copyright
35
- # (the BSD license)
36
- #
37
- # Copyright 2010 Philipp Fehre. All rights reserved.
38
- #
39
- # Redistribution and use in source and binary forms, with or without modification, are
40
- # permitted provided that the following conditions are met:
41
- #
42
- # 1. Redistributions of source code must retain the above copyright notice, this list of
43
- # conditions and the following disclaimer.
44
- #
45
- # 2. Redistributions in binary form must reproduce the above copyright notice, this list
46
- # of conditions and the following disclaimer in the documentation and/or other materials
47
- # provided with the distribution.
48
- #
49
- # THIS SOFTWARE IS PROVIDED BY PHILIPP FEHRE ``AS IS'' AND ANY EXPRESS OR IMPLIED
50
- # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
51
- # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
52
- # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
53
- # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
54
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
55
- # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
56
- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
57
- # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58
- #
59
- # The views and conclusions contained in the software and documentation are those of the
60
- # authors and should not be interpreted as representing official policies,
61
- # either expressed or implied, of Philipp Fehre.
62
- #
63
-
64
-
65
- require 'optparse'
66
- require 'rdoc/usage'
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
67
4
  require 'ostruct'
68
5
  require 'date'
69
- require 'hostip'
6
+ require_relative '../lib/hostip'
70
7
  require 'ipaddr'
71
8
 
72
9
  class App
73
- VERSION = '0.2.0'
74
-
75
- attr_reader :options
76
-
77
- def initialize(arguments)
78
- @arguments = arguments
79
-
80
- # Set defaults
81
- @options = OpenStruct.new
82
- @options.verbose = false
83
- @options.city = false
84
- @options.geo = false
85
- @options.country = false
86
- @options.abbrev = false
87
- @options.ip = nil
88
- end
89
-
90
- # Parse options, check arguments, then process the command
91
- def run
92
-
93
- if parsed_options? && arguments_valid?
94
-
95
- puts "Start at #{DateTime.now}\n\n" if @options.verbose
96
-
97
- process_command
98
-
99
- puts "\nFinished at #{DateTime.now}" if @options.verbose
100
-
101
- else
102
- output_usage
103
- end
104
-
105
- end
106
-
107
- protected
108
-
109
- def parsed_options?
110
-
111
- # Specify options
112
- opts = OptionParser.new
113
-
114
- opts.on('-v', '--version') { output_version ; exit 0 }
115
- opts.on('-h', '--help') { output_help }
116
- opts.on('-V', '--verbose') { @options.verbose = true }
117
- opts.on('--city') { @options.city = true }
118
- opts.on('--geo') { @options.geo = true }
119
- opts.on('--country') { @options.country = true }
120
- opts.on('--country-abbrev') { @options.abbrev = true }
121
-
122
- opts.parse!(@arguments) rescue return false
123
-
124
- process_options
125
-
126
- true
127
- end
128
-
129
- # Performs post-parse processing on options
130
- def process_options
131
-
132
- end
133
-
134
- # True if required arguments were provided
135
- def arguments_valid?
136
- # Check if IP is passed and IP is a valid IP
137
- begin
138
- if @arguments[0] && IPAddr.new(@arguments[0])
139
- @options.ip = @arguments[0]
140
- return true
141
- end
142
- rescue Exception
143
- return false
144
- end
145
- # No IP passed, also good!
146
- true
147
- end
148
-
149
- def output_help
150
- output_version
151
- RDoc::usage() #exits app
152
- end
153
-
154
- def output_usage
155
- RDoc::usage('usage') # gets usage from comments above and exit
156
- end
157
-
158
- def output_version
159
- puts "#{File.basename(__FILE__)} version #{VERSION}"
160
- end
161
-
162
- def process_command
163
- hostip = Hostip.new
164
-
165
- unless @options.ip
166
- @options.ip = hostip.ip
167
- puts @options.ip
168
- end
169
- if @options.city
170
- puts hostip.city(@options.ip)
171
- end
172
- if @options.geo
173
- puts "#{hostip.geo_location(@options.ip)["lat"]} #{hostip.geo_location(@options.ip)["long"]}"
174
- end
175
- if @options.country
176
- puts hostip.country_name(@options.ip)
177
- end
178
- if @options.abbrev
179
- puts hostip.country_abbrev(@options.ip)
180
- end
181
-
182
- end
10
+ VERSION = '0.2.0'
183
11
 
184
- end
12
+ attr_reader :options
13
+
14
+ def initialize(arguments)
15
+ @arguments = arguments
16
+
17
+ # Set defaults
18
+ @options = OpenStruct.new
19
+ @options.verbose = false
20
+ @options.city = false
21
+ @options.geo = false
22
+ @options.country = false
23
+ @options.abbrev = false
24
+ @options.ip = nil
25
+
26
+ @opts = OptionParser.new
27
+ end
28
+
29
+ # Parse options, check arguments, then process the command
30
+ def run
31
+
32
+ if parsed_options? && arguments_valid?
33
+
34
+ puts "Start at #{DateTime.now}\n\n" if @options.verbose
35
+
36
+ process_command
37
+
38
+ puts "\nFinished at #{DateTime.now}" if @options.verbose
39
+
40
+ else
41
+ output_usage
42
+ end
43
+
44
+ end
45
+
46
+ protected
185
47
 
48
+ def parsed_options?
49
+ @opts.on('-v', '--version', 'display version') { output_version ; exit 0 }
50
+ @opts.on('-h', '--help', 'display help') { output_help }
51
+ @opts.on('-V', '--verbose', 'be more verbose') { @options.verbose = true }
52
+ @opts.on('--city', 'get the city only i.e. Munich') { @options.city = true }
53
+ @opts.on('--geo', 'get longtitude and latitude, i.e. 12.45, 12.23') { @options.geo = true }
54
+ @opts.on('--country', 'get the country i.e. Germany') { @options.country = true }
55
+ @opts.on('--country-abbrev', 'get the country abbreviation i.e. US') { @options.abbrev = true }
186
56
 
57
+ @opts.parse!(@arguments) rescue return false
58
+
59
+ process_options
60
+
61
+ true
62
+ end
63
+
64
+ # Performs post-parse processing on options
65
+ def process_options
66
+
67
+ end
68
+
69
+ # True if required arguments were provided
70
+ def arguments_valid?
71
+ # Check if IP is passed and IP is a valid IP
72
+ begin
73
+ if @arguments[0] && IPAddr.new(@arguments[0])
74
+ @options.ip = @arguments[0]
75
+ return true
76
+ end
77
+ rescue Exception
78
+ return false
79
+ end
80
+ # No IP passed, also good!
81
+ true
82
+ end
83
+
84
+ def output_help
85
+ output_version
86
+ output_usage
87
+ end
88
+
89
+ def output_usage
90
+ puts @opts.help
91
+ exit 1
92
+ end
93
+
94
+ def output_version
95
+ puts "#{File.basename(__FILE__)} version #{VERSION}"
96
+ end
97
+
98
+ def process_command
99
+ hostip = Hostip.new
100
+
101
+ unless @options.ip
102
+ @options.ip = hostip.ip
103
+ puts @options.ip
104
+ end
105
+ if @options.city
106
+ puts hostip.city(@options.ip)
107
+ end
108
+ if @options.geo
109
+ puts "#{hostip.geo_location(@options.ip)["lat"]} #{hostip.geo_location(@options.ip)["long"]}"
110
+ end
111
+ if @options.country
112
+ puts hostip.country_name(@options.ip)
113
+ end
114
+ if @options.abbrev
115
+ puts hostip.country_abbrev(@options.ip)
116
+ end
117
+
118
+ end
119
+
120
+ end
187
121
 
188
- # Create and run the application
189
122
  app = App.new(ARGV)
190
123
  app.run
191
124
 
@@ -1,50 +1,47 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "rubygems"
4
1
  require "httparty"
5
2
 
6
3
  class Hostip
7
4
  include HTTParty
8
5
  base_uri('api.hostip.info')
9
6
  format :xml
10
-
7
+
11
8
  # get country name for ip, if no ip is passed use own ip
12
9
  def country_name(ip=nil)
13
10
  self.class.request(ip)["countryName"]
14
11
  end
15
12
 
16
- # get country abbreviation for ip, if no ip is passed use own ip
13
+ # get country abbreviation for ip, if no ip is passed use own ip
17
14
  def country_abbrev(ip=nil)
18
15
  self.class.request(ip)["countryAbbrev"]
19
16
  end
20
-
17
+
21
18
  # get city name for ip, if no ip is passed use own ip
22
19
  def city(ip=nil)
23
- self.class.request(ip)["gml:name"]
20
+ self.class.request(ip)["name"]
24
21
  end
25
-
22
+
26
23
  # get current ip
27
24
  def ip
28
25
  self.class.request["ip"]
29
26
  end
30
-
31
- # Returns a hash with
27
+
28
+ # Returns a hash with
32
29
  # long => "xxxx" and lat => "xxx"
33
30
  # or raise exception if location is unknown
34
31
  def geo_location(ip=nil)
35
32
  begin
36
33
  # Get Comma seperated coordinates and return as hash
37
- coordinates = self.class.request(ip, true)["ipLocation"]["gml:pointProperty"]["gml:Point"]["gml:coordinates"].split(',')
34
+ coordinates = self.class.request(ip, true)["ipLocation"]["pointProperty"]["Point"]["coordinates"].split(',')
38
35
  return { "long" => coordinates[0], "lat" => coordinates[1] }
39
- rescue
36
+ rescue
40
37
  raise "geo location unknown"
41
38
  end
42
39
  end
43
-
40
+
44
41
  class << self
45
-
42
+
46
43
  # Make a request and strip unwanted XML before returning result
47
- # options:
44
+ # options:
48
45
  # ip => xxx.xxx.xxx.xxx
49
46
  # postion => true (Documented but does nothing!)
50
47
  def request(ip=nil, position=false)
@@ -58,12 +55,12 @@ class Hostip
58
55
  end
59
56
  # sent request
60
57
  if params == {}
61
- self.get('/get_xml.php')["HostipLookupResultSet"]["gml:featureMember"]["Hostip"]
58
+ self.get('/get_xml.php')["HostipLookupResultSet"]["featureMember"]["Hostip"]
62
59
  else
63
- self.get('/get_xml.php', :query => params)["HostipLookupResultSet"]["gml:featureMember"]["Hostip"]
60
+ self.get('/get_xml.php', :query => params)["HostipLookupResultSet"]["featureMember"]["Hostip"]
64
61
  end
65
62
  end
66
-
63
+
67
64
  end
68
-
65
+
69
66
  end
@@ -0,0 +1 @@
1
+ HOSTIP_VERSION = "0.3.0"
@@ -0,0 +1,40 @@
1
+ require_relative "./test_helper"
2
+
3
+ class HostipiBinTest < Minitest::Test
4
+
5
+ def setup
6
+ @hostipbin = File.expand_path("../bin/hostip", File.dirname(__FILE__))
7
+ end
8
+
9
+ def test_get_ip
10
+ assert IPAddr.new(%x[ruby #{@hostipbin}].chomp)
11
+ end
12
+
13
+ def test_city
14
+ city = %x[ruby #{@hostipbin} --city 74.125.77.147].chomp
15
+ assert_equal "Mountain View, CA", city
16
+ end
17
+
18
+ def test_multiple
19
+ mult = %x[ruby #{@hostipbin} --geo --city --country 66.102.13.103].chomp
20
+ exp_res = "Mountain View, CA\n37.402 -122.078\nUNITED STATES"
21
+ assert_equal exp_res, mult
22
+ end
23
+
24
+ def test_country
25
+ country = %x[ruby #{@hostipbin} --country 74.125.77.147].chomp
26
+ assert_equal "UNITED STATES", country
27
+ end
28
+
29
+ def test_country_abbrev
30
+ abbrev = %x[ruby #{@hostipbin} --country-abbrev 74.125.77.147].chomp
31
+ assert_equal "US", abbrev
32
+ end
33
+
34
+ def test_geo_location
35
+ geo = %x[ruby #{@hostipbin} --geo 74.125.77.147].chomp
36
+ assert_equal "37.402 -122.078", geo
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,30 @@
1
+ require_relative "./test_helper"
2
+ require "ipaddr"
3
+
4
+ class HostipTest < Minitest::Test
5
+
6
+ def setup
7
+ @hip = Hostip.new
8
+ end
9
+
10
+ def test_ip
11
+ assert IPAddr.new(@hip.ip)
12
+ end
13
+
14
+ def test_country_name
15
+ assert_equal @hip.country_name("66.102.13.103"), "UNITED STATES"
16
+ end
17
+
18
+ def test_country_abbrev
19
+ assert_equal @hip.country_abbrev("66.102.13.103"), "US"
20
+ end
21
+
22
+ def test_city
23
+ assert_equal @hip.city("66.102.13.103"), "Mountain View, CA"
24
+ end
25
+
26
+ def test_geo_location
27
+ assert_equal @hip.geo_location("66.102.13.103"), {"lat"=>"37.402", "long"=>"-122.078"}
28
+ end
29
+
30
+ end
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
2
- $LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/../lib' )
3
- $LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/../bin' )
1
+ require "minitest/autorun"
2
+ require_relative "../lib/hostip"
3
+ require "ipaddr"
4
4
 
metadata CHANGED
@@ -1,30 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hostip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Philipp Fehre
9
- autorequire: hostip
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-09 00:00:00.000000000 Z
11
+ date: 2013-10-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: httparty
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
28
53
  - !ruby/object:Gem::Version
29
54
  version: '0'
30
55
  description: A simple Ruby wrapper for hostip.info
@@ -33,43 +58,41 @@ executables:
33
58
  - hostip
34
59
  extensions: []
35
60
  extra_rdoc_files:
36
- - README.rdoc
61
+ - README.md
37
62
  files:
38
- - README.rdoc
39
- - Rakefile
63
+ - README.md
40
64
  - lib/hostip.rb
41
- - tests/tc_hostip.rb
42
- - tests/tc_hostipbin.rb
65
+ - lib/version.rb
66
+ - tests/hostip_bin_test.rb
67
+ - tests/hostip_test.rb
43
68
  - tests/test_helper.rb
44
- - tests/ts_alltests.rb
45
69
  - bin/hostip
46
70
  homepage: https://github.com/sideshowcoder/hostip-gem
47
- licenses: []
71
+ licenses:
72
+ - BSD
73
+ metadata: {}
48
74
  post_install_message:
49
75
  rdoc_options: []
50
76
  require_paths:
51
77
  - lib
52
78
  required_ruby_version: !ruby/object:Gem::Requirement
53
- none: false
54
79
  requirements:
55
- - - ! '>='
80
+ - - '>='
56
81
  - !ruby/object:Gem::Version
57
82
  version: '0'
58
83
  required_rubygems_version: !ruby/object:Gem::Requirement
59
- none: false
60
84
  requirements:
61
- - - ! '>='
85
+ - - '>='
62
86
  - !ruby/object:Gem::Version
63
87
  version: '0'
64
88
  requirements: []
65
- rubyforge_project:
66
- rubygems_version: 1.8.23
89
+ rubyforge_project: hostip
90
+ rubygems_version: 2.0.2
67
91
  signing_key:
68
- specification_version: 3
92
+ specification_version: 4
69
93
  summary: Get geolocation, ip, country and city information for current or any other
70
94
  ip from hostip.info
71
95
  test_files:
72
- - tests/tc_hostip.rb
73
- - tests/tc_hostipbin.rb
96
+ - tests/hostip_bin_test.rb
97
+ - tests/hostip_test.rb
74
98
  - tests/test_helper.rb
75
- - tests/ts_alltests.rb
data/Rakefile DELETED
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems' unless ENV['NO_RUBYGEMS']
4
- require 'rake/gempackagetask'
5
- require 'rubygems/specification'
6
-
7
-
8
- spec = Gem::Specification.new do |s|
9
- s.name = "hostip"
10
- s.version = "0.2.1"
11
- s.authors = ['Philipp Fehre']
12
- s.email = "philipp.fehre@googlemail.com"
13
- s.homepage = "https://github.com/sideshowcoder/hostip-gem"
14
- s.description = s.summary = "A simple Ruby wrapper for hostip.info"
15
- s.summary = "Get geolocation, ip, country and city information for current or any other ip from hostip.info"
16
-
17
- s.platform = Gem::Platform::RUBY
18
- s.has_rdoc = true
19
- s.extra_rdoc_files = ["README.rdoc"]
20
-
21
- s.require_path = 'lib'
22
- s.autorequire = 'hostip'
23
- s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,tests,bin}/*")
24
-
25
- s.bindir = 'bin'
26
- s.executables = ['hostip']
27
- s.test_files = Dir.glob('tests/*.rb')
28
- s.add_dependency('httparty')
29
- end
30
-
31
- Rake::GemPackageTask.new(spec) do |pkg|
32
- pkg.need_tar = true
33
- end
34
-
35
- task :default => "pkg/#{spec.name}-#{spec.version}.gem" do
36
- puts "generated latest version"
37
- end
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "test_helper"
4
- require "test/unit"
5
- require "hostip"
6
- require "ipaddr"
7
-
8
-
9
- class HostipTest < Test::Unit::TestCase
10
-
11
- def setup
12
- @hip = Hostip.new
13
- end
14
-
15
- def test_ip
16
- assert_nothing_raised() do
17
- IPAddr.new(@hip.ip)
18
- end
19
- end
20
-
21
- def test_country_name
22
- assert_equal(@hip.country_name("66.102.13.103"), "UNITED STATES")
23
- end
24
-
25
- def test_country_abbrev
26
- assert_equal(@hip.country_abbrev("66.102.13.103"), "US")
27
- end
28
-
29
- def test_city
30
- assert_equal(@hip.city("66.102.13.103"), "Mountain View, CA")
31
- end
32
-
33
- def test_geo_location
34
- assert_equal(@hip.geo_location("66.102.13.103"), {"lat"=>"37.402", "long"=>"-122.078"})
35
- end
36
-
37
- end
@@ -1,48 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "test_helper"
4
- require "test/unit"
5
- require "hostip"
6
- require "ipaddr"
7
-
8
-
9
- class HostipiBinTest < Test::Unit::TestCase
10
-
11
- def setup
12
- @hostipbin = "../bin/hostip"
13
- end
14
-
15
- def test_get_ip
16
- assert_nothing_raised() do
17
- IPAddr.new(%x[ruby ../bin/hostip].chomp)
18
- end
19
- end
20
-
21
- def test_city
22
- city = %x[ruby ../bin/hostip --city 74.125.77.147].chomp
23
- assert_equal(city, "Buren")
24
- end
25
-
26
- def test_multiple
27
- mult = %x[ruby ../bin/hostip --geo --city --country 74.125.77.147].chomp
28
- exp_res = "Buren\n51.9167 5.3333\nNETHERLANDS"
29
- assert_equal(mult, exp_res)
30
- end
31
-
32
- def test_country
33
- country = %x[ruby ../bin/hostip --country 74.125.77.147].chomp
34
- assert_equal(country, "NETHERLANDS")
35
- end
36
-
37
- def test_country_abbrev
38
- abbrev = %x[ruby ../bin/hostip --country-abbrev 74.125.77.147].chomp
39
- assert_equal(abbrev, "NL")
40
- end
41
-
42
- def test_geo_location
43
- geo = %x[ruby ../bin/hostip --geo 74.125.77.147].chomp
44
- assert_equal(geo, "51.9167 5.3333")
45
- end
46
-
47
- end
48
-
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require "test/unit"
3
- require "tc_hostip"
4
- require "tc_hostipbin"