geo_ip_client 0.0.2

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 ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in geo_ip_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Enrico Carlesso
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,49 @@
1
+ GeoIpClient
2
+ ===========
3
+
4
+ GeoIpClient is a simple gem which allows you to speak with your [RubyGeoIp](https://github.com/carlesso/RubyGeoIp) server.
5
+
6
+
7
+ Installation
8
+ ------------
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'geo_ip_client'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install geo_ip_client
21
+
22
+ Configuration
23
+ -------------
24
+
25
+ Edit your `config/initializers/geo_ip_client.rb` like:
26
+
27
+ ```ruby
28
+ GeoIpClient.configure do |config|
29
+ config.server_path = "" # Insert the location of your server
30
+ config.secret_key = nil # Inser your secret key if your RubyGeoIp server requires it
31
+ end
32
+
33
+ ```
34
+
35
+ Usage
36
+ -----
37
+ ```ruby
38
+ > GeoIpClient.search("64.71.22.18")
39
+ => {"request"=>"64.71.22.18", "ip"=>"64.71.22.18", "country_code2"=>"US", "country_code3"=>"USA", "country_name"=>"United States", "continent_code"=>"NA", "region_name"=>"CA", "city_name"=>"Santa Clara", "postal_code"=>"95054", "latitude"=>37.39609999999999, "longitude"=>-121.96170000000001, "dma_code"=>807, "area_code"=>408, "timezone"=>"America/Los_Angeles"}
40
+ ```
41
+
42
+ Contributing
43
+ ------------
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'geo_ip_client/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "geo_ip_client"
8
+ gem.version = GeoIpClient::VERSION
9
+ gem.authors = ["Enrico Carlesso"]
10
+ gem.email = ["enricocarlesso@gmail.com"]
11
+ gem.description = "A simple gem to be used in combination with https://github.com/carlesso/RubyGeoIp"
12
+ gem.summary = "Client for RubyGeoIp Project"
13
+ gem.homepage = "https://github.com/carlesso/geo_ip_client"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "json"
21
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/active_record'
3
+
4
+ class GeoIpClientGenerator < Rails::Generators::Base
5
+
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ desc "This generator creates the initializer file at config/initializers"
9
+ def copy_initializer_file
10
+ copy_file "geo_ip_client.rb", "config/initializers/geo_ip_client.rb"
11
+ end
12
+
13
+ end
@@ -0,0 +1,4 @@
1
+ GeoIpClient.configure do |config|
2
+ config.server_path = "" # Insert the location of your server
3
+ config.secret_key = nil # Inser your secret key if your RubyGeoIp server requires it
4
+ end
@@ -0,0 +1,3 @@
1
+ module GeoIpClient
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,30 @@
1
+ require "geo_ip_client/version"
2
+ require "open-uri"
3
+ require "json"
4
+
5
+ module GeoIpClient
6
+ class << self
7
+ attr_accessor :server_path, :secret_key
8
+
9
+ def configure
10
+ yield self
11
+ end
12
+
13
+ def search(ip)
14
+ if server_path.nil?
15
+ raise "No server path specified!"
16
+ end
17
+ if secret_key.nil?
18
+ req = open("#{server_path}/?q=#{ip}")
19
+ else
20
+ req = open("#{server_path}/?auth=#{secret_key}&q=#{ip}")
21
+ end
22
+ if req.status[0].to_s == "200"
23
+ return JSON.parse req.read
24
+ else
25
+ raise JSON.parse(req.read)["error"]
26
+ end
27
+ end
28
+
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geo_ip_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Enrico Carlesso
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: A simple gem to be used in combination with https://github.com/carlesso/RubyGeoIp
31
+ email:
32
+ - enricocarlesso@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - geo_ip_client.gemspec
43
+ - lib/generators/geo_ip_client_generator.rb
44
+ - lib/generators/template/geo_ip_client.rb
45
+ - lib/geo_ip_client.rb
46
+ - lib/geo_ip_client/version.rb
47
+ homepage: https://github.com/carlesso/geo_ip_client
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.24
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Client for RubyGeoIp Project
71
+ test_files: []