simple_geoip 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem "nokogiri"
4
+ gem "ansi"
5
+ gem "turn"
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ ansi (1.2.5)
5
+ curb (0.7.15)
6
+ nokogiri (1.4.4)
7
+ turn (0.8.2)
8
+ ansi (>= 1.2.2)
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ ansi
15
+ curb
16
+ nokogiri
17
+ turn
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Simple Geo IP
2
+ Find the geo info by ip address. Dead simple. Uses [nokogiri][nokogiri] against [http://whatismyipaddress.com][whatsmyip]
3
+
4
+
5
+ # Installing
6
+
7
+ ### Requirements
8
+ * Ruby 1.8.7+
9
+ * nokogiri
10
+
11
+ ### Install the gem
12
+ gem install simple_geoip
13
+
14
+ ### Build gem from source
15
+ git clone git://github.com/chrisledet/simple_geoip.git
16
+ cd simple_geoip
17
+ gem build simple_geoip.gemspec
18
+
19
+ # TODO
20
+ Make an executable so you can run in the command line freely.
21
+
22
+
23
+ [whatsmyip]:http://whatismyipaddress.com
24
+ [nokogiri]:https://github.com/tenderlove/nokogiri
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ task :default => :test
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'test' << 'lib'
8
+ test.pattern = 'test/**/test_*.rb'
9
+ test.verbose = true
10
+ end
@@ -0,0 +1,28 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+
4
+ module SimpleGeoIP
5
+
6
+ API = "http://whatismyipaddress.com/ip/"
7
+
8
+ # parse this the web page and find lat and long, FUCK YEAH!
9
+ def self.find_geo(ip_address)
10
+ url = lookup_url ip_address
11
+ doc = Nokogiri::HTML open(url)
12
+ table = doc.search('table').last
13
+ row = table.content
14
+ starts = row.index 'Latitude'
15
+ geo_str = row[starts..-1]
16
+ geo_str = geo_str.gsub("Latitude:", "")
17
+ geo_str = geo_str.gsub("Longitude", "")
18
+ geo_str = geo_str.gsub("Area Code", "")
19
+ geo_str = geo_str.gsub("Postal Code", "")
20
+ lat, log = geo_str.split(":")
21
+ [lat, log]
22
+ end
23
+
24
+ def self.lookup_url(ip_address)
25
+ API + ip_address
26
+ end
27
+
28
+ end
@@ -0,0 +1,59 @@
1
+
2
+ Gem::Specification.new do |s|
3
+ s.specification_version = 2 if s.respond_to? :specification_version=
4
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
5
+ s.rubygems_version = '1.3.5'
6
+
7
+ ## Leave these as is they will be modified for you by the rake gemspec task.
8
+ ## If your rubyforge_project name is different, then edit it and comment out
9
+ ## the sub! line in the Rakefile
10
+ s.name = 'simple_geoip'
11
+ s.version = '0.0.1'
12
+ s.date = '2011-05-30'
13
+
14
+ ## Make sure your summary is short. The description may be as long
15
+ ## as you like.
16
+ s.summary = "find geolocation information from ip address"
17
+ s.description = "fuck finding geo info from websites, this gem makes it easy & awesome!"
18
+
19
+ ## List the primary authors. If there are a bunch of authors, it's probably
20
+ ## better to set the email to an email list or something. If you don't have
21
+ ## a custom homepage, consider using your GitHub URL or the like.
22
+ s.authors = ["Chris Ledet"]
23
+ s.email = 'chris[at]ledet.io'
24
+ s.homepage = 'https://github.com/chrisledet/simple_geoip'
25
+
26
+ ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
27
+ ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
28
+ s.require_paths = %w[lib]
29
+
30
+ #s.extra_rdoc_files = %w[README LICENSE]
31
+
32
+ ## List your runtime dependencies here. Runtime dependencies are those
33
+ ## that are needed for an end user to actually USE your code.
34
+ s.add_dependency('nokogiri')
35
+
36
+ ## List your development dependencies here. Development dependencies are
37
+ ## those that are only needed during development
38
+ s.add_development_dependency('turn')
39
+
40
+ ## Leave this section as-is. It will be automatically generated from the
41
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
42
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
43
+ # = MANIFEST =
44
+ s.files = %w[
45
+ Gemfile
46
+ Gemfile.lock
47
+ README.md
48
+ Rakefile
49
+ lib/simple_geoip.rb
50
+ simple_geoip.gemspec
51
+ test/test_helper.rb
52
+ test/test_basics.rb
53
+ ]
54
+ # = MANIFEST =
55
+
56
+ ## Test files will be grabbed from the file list. Make sure the path glob
57
+ ## matches what you actually use.
58
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
59
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ class TestSimpleGeoIP < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @random_ip = '173.61.39.60'
7
+ @geo_from_test_ip = ["39.8506", "-74.9099"]
8
+ end
9
+
10
+ def test_match_api_url
11
+ assert_equal "http://whatismyipaddress.com/ip/", SimpleGeoIP::API
12
+ end
13
+
14
+ def test_geo_from_ip
15
+ lat, long = SimpleGeoIP::find_geo @test_ip
16
+ assert_equal @geo_from_test_ip, [lat, long]
17
+ end
18
+
19
+ end
@@ -0,0 +1,3 @@
1
+ require 'turn'
2
+ require 'test/unit'
3
+ require 'simple_geoip'
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_geoip
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Chris Ledet
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-30 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: turn
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :development
36
+ version_requirements: *id002
37
+ description: fuck finding geo info from websites, this gem makes it easy & awesome!
38
+ email: chris[at]ledet.io
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - Gemfile
47
+ - Gemfile.lock
48
+ - README.md
49
+ - Rakefile
50
+ - lib/simple_geoip.rb
51
+ - simple_geoip.gemspec
52
+ - test/test_helper.rb
53
+ - test/test_basics.rb
54
+ homepage: https://github.com/chrisledet/simple_geoip
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.7.2
78
+ signing_key:
79
+ specification_version: 2
80
+ summary: find geolocation information from ip address
81
+ test_files:
82
+ - test/test_helper.rb
83
+ - test/test_basics.rb