oldskool-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.
@@ -0,0 +1,31 @@
1
+ module Oldskool
2
+ class IpinfodbHandler
3
+ def initialize(params, keyword, config)
4
+ require 'geo_ip'
5
+ require 'ipaddr'
6
+
7
+ @params = params
8
+ @keyword = keyword
9
+ @config = config
10
+ self
11
+ end
12
+
13
+ def plugin_template(template)
14
+ File.read(File.expand_path("../../../views/#{template}.erb", __FILE__))
15
+ end
16
+
17
+ def handle_request(keyword, query)
18
+ raise "Please set :ipinfodb_apikey in the config" unless @config[:ipinfodb_apikey]
19
+
20
+ (query == "") ? ip = @params[:http_request].ip : ip = query
21
+
22
+ ipaddr = IPAddr.new(ip)
23
+ return({:template => :error, :error => "Invalid IP #{ip}, only IPv4 addresses are supported"}) unless ipaddr.ipv4?
24
+
25
+ GeoIp.api_key = @config[:ipinfodb_apikey]
26
+ geoip = GeoIp.geolocation(ip)
27
+
28
+ {:template => plugin_template(:ipinfo), :ipinfo => geoip}
29
+ end
30
+ end
31
+ end
@@ -0,0 +1 @@
1
+ require 'oldskool/ipinfodb_handler'
data/views/ipinfo.erb ADDED
@@ -0,0 +1,15 @@
1
+ <% unless @error %>
2
+ <% unless @result[:ipinfo][:status_message] == "" %>
3
+ Failed to retrieve IP Info: <%= @result[:ipinfo][:status_message] %>
4
+ <% else %>
5
+ <table>
6
+ <tr><td><strong>IP Address:</strong></td><td><%= @result[:ipinfo][:ip] %></td></tr>
7
+ <tr><td><strong>City:</strong></td><td><%= @result[:ipinfo][:city].capitalize %></td></tr>
8
+ <tr><td><strong>Country:</strong></td><td><%= @result[:ipinfo][:country_name].capitalize %></td></tr>
9
+ <tr><td><strong>Country Code:</strong></td><td><%= @result[:ipinfo][:country_code] %></td></tr>
10
+ <tr><td><strong>Region:</strong></td><td><%= @result[:ipinfo][:region_name].capitalize %></td></tr>
11
+ <tr><td><strong>ZIP Code:</strong></td><td><%= @result[:ipinfo][:zip_code] %></td></tr>
12
+ <tr><td><strong>Coordinates:</strong></td><td>lon <%= @result[:ipinfo][:longitude] %> lat <%= @result[:ipinfo][:latitude] %></td></tr>
13
+ </table>
14
+ <% end %>
15
+ <% end %>
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oldskool-ipinfodb
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - R.I.Pienaar
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-02 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: geo_ip
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: "description: Display IP information from ipinfodb.com"
36
+ email: rip@devco.net
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - lib/oldskool/ipinfodb_handler.rb
45
+ - lib/oldskool-ipinfodb.rb
46
+ - views/ipinfo.erb
47
+ has_rdoc: true
48
+ homepage: http://devco.net/
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.3.7
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: oldskool-ipinfodb
81
+ test_files: []
82
+