ipinfodb 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README +1 -0
- data/Rakefile +2 -0
- data/ipinfodb.gemspec +23 -0
- data/lib/ipinfodb.rb +28 -0
- data/test/ipinfodb_test.rb +30 -0
- data/test/test_helper.rb +4 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
IPINFODB_API_KEY=<apikey> rake test
|
data/Rakefile
ADDED
data/ipinfodb.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ipinfodb"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ipinfodb"
|
7
|
+
s.version = Ipinfodb::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Tomasz Mazur"]
|
10
|
+
s.email = ["defkode@gmail.com"]
|
11
|
+
s.homepage = "http://ipinfodb.com"
|
12
|
+
s.summary = %q{Free IP address geolocation tools}
|
13
|
+
s.description = %q{Free IP address geolocation tools}
|
14
|
+
|
15
|
+
s.rubyforge_project = "ipinfodb"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency('httparty', '~> 0.6')
|
23
|
+
end
|
data/lib/ipinfodb.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
class Ipinfodb
|
4
|
+
VERSION = '0.0.1'
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_accessor :api_key
|
8
|
+
end
|
9
|
+
|
10
|
+
include HTTParty
|
11
|
+
|
12
|
+
base_uri "api.ipinfodb.com"
|
13
|
+
|
14
|
+
def self.lookup(ip)
|
15
|
+
params = {
|
16
|
+
:output => "json",
|
17
|
+
:key => api_key,
|
18
|
+
:ip => ip
|
19
|
+
}
|
20
|
+
|
21
|
+
body = get("/v2/ip_query_country.php", :query => params).parsed_response
|
22
|
+
if body["Status"] == "OK"
|
23
|
+
body
|
24
|
+
else
|
25
|
+
raise ArgumentError, body["Status"]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class IpinfodbTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# def setup
|
6
|
+
# Ipinfodb.api_key = nil
|
7
|
+
# end
|
8
|
+
|
9
|
+
def test_invalid_api_key
|
10
|
+
assert_raise ArgumentError, "INVALID API KEY" do
|
11
|
+
Ipinfodb.api_key = "xxx"
|
12
|
+
Ipinfodb.lookup("127.0.0.1")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_missing_api_key
|
17
|
+
assert_raise ArgumentError, "MISSING API KEY" do
|
18
|
+
Ipinfodb.lookup("127.0.0.1")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_valid_api_key
|
23
|
+
puts "IPINFODB_API_KEY=<your_api_key> required to run this test" unless ENV["IPINFODB_API_KEY"]
|
24
|
+
assert_nothing_raised do
|
25
|
+
Ipinfodb.api_key = ENV["IPINFODB_API_KEY"]
|
26
|
+
Ipinfodb.lookup("127.0.0.1")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ipinfodb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Tomasz Mazur
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-18 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: httparty
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 6
|
33
|
+
version: "0.6"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description: Free IP address geolocation tools
|
37
|
+
email:
|
38
|
+
- defkode@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- .gitignore
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
49
|
+
- README
|
50
|
+
- Rakefile
|
51
|
+
- ipinfodb.gemspec
|
52
|
+
- lib/ipinfodb.rb
|
53
|
+
- test/ipinfodb_test.rb
|
54
|
+
- test/test_helper.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://ipinfodb.com
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project: ipinfodb
|
85
|
+
rubygems_version: 1.4.2
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Free IP address geolocation tools
|
89
|
+
test_files:
|
90
|
+
- test/ipinfodb_test.rb
|
91
|
+
- test/test_helper.rb
|