geo_ips 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +1 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.rvmrc +48 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +36 -0
- data/LICENSE +22 -0
- data/README.md +54 -0
- data/Rakefile +7 -0
- data/geo_ips.gemspec +24 -0
- data/lib/geo_ips/version.rb +3 -0
- data/lib/geo_ips.rb +35 -0
- data/spec/geo_ips_spec.rb +29 -0
- data/spec/spec_helper.rb +15 -0
- metadata +118 -0
data/.autotest
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "autotest/bundler"
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p125@geo_ips"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.10.3" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
35
|
+
|
36
|
+
# If you use bundler, this might be useful to you:
|
37
|
+
# if [[ -s Gemfile ]] && {
|
38
|
+
# ! builtin command -v bundle >/dev/null ||
|
39
|
+
# builtin command -v bundle | grep $rvm_path/bin/bundle >/dev/null
|
40
|
+
# }
|
41
|
+
# then
|
42
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
43
|
+
# gem install bundler
|
44
|
+
# fi
|
45
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
46
|
+
# then
|
47
|
+
# bundle install | grep -vE '^Using|Your bundle is complete'
|
48
|
+
# fi
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
geo_ips (0.1.0)
|
5
|
+
multi_json
|
6
|
+
typhoeus (~> 0.3.3)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ZenTest (4.6.2)
|
12
|
+
autotest (4.4.6)
|
13
|
+
ZenTest (>= 4.4.1)
|
14
|
+
diff-lcs (1.1.3)
|
15
|
+
mime-types (1.17.2)
|
16
|
+
multi_json (1.1.0)
|
17
|
+
rspec (2.8.0)
|
18
|
+
rspec-core (~> 2.8.0)
|
19
|
+
rspec-expectations (~> 2.8.0)
|
20
|
+
rspec-mocks (~> 2.8.0)
|
21
|
+
rspec-core (2.8.0)
|
22
|
+
rspec-expectations (2.8.0)
|
23
|
+
diff-lcs (~> 1.1.2)
|
24
|
+
rspec-mocks (2.8.0)
|
25
|
+
typhoeus (0.3.3)
|
26
|
+
mime-types
|
27
|
+
vcr (2.0.0.rc2)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
autotest
|
34
|
+
geo_ips!
|
35
|
+
rspec (~> 2.8.0)
|
36
|
+
vcr (= 2.0.0rc2)
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ezekiel Templin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# GeoIPs
|
2
|
+
|
3
|
+
Ruby library to interact with the [GeoIPS.com](http://www.geoips.com/developer) IP geo-location API.
|
4
|
+
|
5
|
+
### Note
|
6
|
+
I have no association with the company running this service. All support questions not related to the library itself should be forwarded to them.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'geo_ips'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install geo_ips
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
require 'geo_ips'
|
25
|
+
require 'yajl' # The library uses multi_json, so this is recommended, but not required.
|
26
|
+
|
27
|
+
@geoips = GeoIPs.new("your-api-key-here")
|
28
|
+
@geoips.lookup("66.147.244.214")
|
29
|
+
|
30
|
+
#=> { "status" : "Success",
|
31
|
+
# "ip" : "66.147.244.214",
|
32
|
+
# "hostname" : "box714.bluehost.com",
|
33
|
+
# "owner" : "BLUEHOST INC.",
|
34
|
+
# "continent_name" : "NORTH AMERICA",
|
35
|
+
# "continent_code" : "NA",
|
36
|
+
# "country_name" : "UNITED STATES",
|
37
|
+
# "country_code" : "US",
|
38
|
+
# "region_name" : "UTAH",
|
39
|
+
# "region_code" : "UT",
|
40
|
+
# "county_name" : "UTAH",
|
41
|
+
# "city_name" : "PROVO",
|
42
|
+
# "latitude" : "40.3402",
|
43
|
+
# "longitude" : "-111.6073" }
|
44
|
+
|
45
|
+
## Testing
|
46
|
+
To test the library, you'll need to [signup for an API key](http://www.geoips.com/auth/register) and place the key in a file called `.api_key` in the root directory of the library.
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/geo_ips.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/geo_ips/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Ezekiel Templin"]
|
6
|
+
gem.email = ["zeke@templ.in"]
|
7
|
+
gem.description = %q{Ruby library to access the GeoIPs.com IP geo-location API}
|
8
|
+
gem.summary = %q{Simple library to lookup IP geo-location information with the GeoIPs.com API.}
|
9
|
+
gem.homepage = "https://github.com/ezkl/geo_ips"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "geo_ips"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = GeoIPs::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency("typhoeus", "~> 0.3.3")
|
19
|
+
gem.add_runtime_dependency("multi_json")
|
20
|
+
|
21
|
+
gem.add_development_dependency("rspec", "~> 2.8.0")
|
22
|
+
gem.add_development_dependency("autotest")
|
23
|
+
gem.add_development_dependency("vcr", "2.0.0rc2")
|
24
|
+
end
|
data/lib/geo_ips.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
require 'geo_ips/version'
|
5
|
+
|
6
|
+
class GeoIPs
|
7
|
+
attr_writer :api_key
|
8
|
+
|
9
|
+
def initialize api_key
|
10
|
+
@api_key = api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def lookup ip
|
14
|
+
request(ip)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def request ip
|
19
|
+
response = Typhoeus::Request.get("http://api.geoips.com/ip/#{ip}/key/#{@api_key}/output/json")
|
20
|
+
|
21
|
+
if response.success?
|
22
|
+
parse(response.body)
|
23
|
+
else
|
24
|
+
raise "Request Error!"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse response
|
29
|
+
MultiJson.decode(fix_response(response))
|
30
|
+
end
|
31
|
+
|
32
|
+
def fix_response response_string
|
33
|
+
response_string.gsub(/,\n}$/,"\n}")
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "GeoIPs" do
|
4
|
+
before(:all) do
|
5
|
+
@api_key = File.read(File.dirname(__FILE__) + '/../.api_key')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should require an API key at initialization" do
|
9
|
+
expect { GeoIPs.new }.to raise_error
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#lookup", :vcr => 'geoips_response' do
|
13
|
+
before(:all) do
|
14
|
+
@geo_ips = GeoIPs.new(@api_key)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should respond to lookup" do
|
18
|
+
@geo_ips.respond_to?(:lookup).should be true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should require an IP" do
|
22
|
+
expect { @geo_ips.lookup }.to raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should respond with 13 items" do
|
26
|
+
@geo_ips.lookup("8.8.8.8").should have(13).items
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/geo_ips')
|
2
|
+
require 'vcr'
|
3
|
+
|
4
|
+
VCR.configure do |c|
|
5
|
+
c.cassette_library_dir = 'spec/cassettes'
|
6
|
+
c.hook_into :typhoeus
|
7
|
+
c.configure_rspec_metadata!
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
config.extend VCR::RSpec::Macros
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geo_ips
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ezekiel Templin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: typhoeus
|
16
|
+
requirement: &2152158600 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.3.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152158600
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: multi_json
|
27
|
+
requirement: &2152157480 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2152157480
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &2152155960 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.8.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2152155960
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: autotest
|
49
|
+
requirement: &2152154920 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2152154920
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: vcr
|
60
|
+
requirement: &2152153380 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - =
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.0.0rc2
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2152153380
|
69
|
+
description: Ruby library to access the GeoIPs.com IP geo-location API
|
70
|
+
email:
|
71
|
+
- zeke@templ.in
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .autotest
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- .rvmrc
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- geo_ips.gemspec
|
86
|
+
- lib/geo_ips.rb
|
87
|
+
- lib/geo_ips/version.rb
|
88
|
+
- spec/geo_ips_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
homepage: https://github.com/ezkl/geo_ips
|
91
|
+
licenses: []
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 1.8.17
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: Simple library to lookup IP geo-location information with the GeoIPs.com
|
114
|
+
API.
|
115
|
+
test_files:
|
116
|
+
- spec/geo_ips_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
has_rdoc:
|