forked from mokevnin/ipgeobase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
104 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,39 @@ | ||
# Ipgeobase | ||
|
||
## Install | ||
[![Build Status](https://travis-ci.org/mokevnin/ipgeobase.png)](https://travis-ci.org/mokevnin/ipgeobase) | ||
|
||
Add this to your `Gemfile`: | ||
Simple format validators for Rails 3 | ||
|
||
gem "ipgeobase" | ||
## Installation | ||
|
||
## Examples | ||
Add this line to your application's Gemfile: | ||
|
||
gem 'ipgeobase' | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install 'ipgeobase' | ||
|
||
## Usage | ||
|
||
ip_meta = Ipgeobase.lookup('10.11.12.134') | ||
ip_meta.city # => Москва | ||
ip_meta.country # => Россия | ||
|
||
|
||
## Contributing | ||
|
||
1. Fork it | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Added some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create new Pull Request | ||
|
||
run tests: | ||
|
||
turn -Itest test/lib | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
require "bundler/gem_tasks" | ||
|
||
require 'rake/testtask' | ||
|
||
Rake::TestTask.new do |t| | ||
t.libs << "test" | ||
t.test_files = FileList['test/lib/*_test.rb'] | ||
t.verbose = true | ||
end | ||
|
||
task :default => :test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
require 'uri' | ||
require 'net/http' | ||
require 'happymapper' | ||
|
||
module Ipgeobase | ||
autoload 'Version', 'ipgeobase/version' | ||
URL = 'http://ipgeobase.ru:7020/geo' | ||
autoload 'IpMetaData', 'ipgeobase/ip_meta_data' | ||
|
||
def self.lookup(ip) | ||
uri = URI.parse('http://ipgeobase.ru:7020/geo') | ||
uri = URI.parse(URL) | ||
uri.query = URI.encode_www_form :ip => ip | ||
|
||
IpMetaData.parse(Net::HTTP.get(uri)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<ip-answer> | ||
<ip value="46.8.114.116"> | ||
<inetnum>46.8.112.0 - 46.8.127.255</inetnum> | ||
<country>RU</country> | ||
<city>Ульяновск</city> | ||
<region>Ульяновская область</region> | ||
<district>Приволжский федеральный округ</district> | ||
<lat>54.321480</lat> | ||
<lng>48.385651</lng> | ||
</ip> | ||
</ip-answer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'test_helper' | ||
|
||
class IpgeobaseTest < TestCase | ||
def setup | ||
@ip = '46.8.114.116' | ||
@stub = stub_request(:get, "#{Ipgeobase::URL}?ip=#{@ip}"). | ||
with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}). | ||
to_return(:status => 200, :body => load_fixture('response.xml'), :headers => {}) | ||
end | ||
|
||
def test_lookup_http_query | ||
Ipgeobase.lookup @ip | ||
|
||
assert_requested @stub | ||
end | ||
|
||
def test_lookup_response_object | ||
meta = Ipgeobase.lookup @ip | ||
|
||
assert_equal 54.321480, meta.lat | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'bundler/setup' | ||
Bundler.require | ||
|
||
MiniTest::Unit.autorun | ||
|
||
class TestCase < MiniTest::Unit::TestCase | ||
def load_fixture(filename) | ||
File.read(File.dirname(__FILE__) + "/fixtures/#{filename}") | ||
end | ||
end |