freegeoip 0.1.0

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,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
+ .DS_STORE
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
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@freegeoip"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.11.5 (master)" # 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
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'guard-rspec'
7
+ gem 'growl', :require => false
8
+ end
9
+
10
+ group :test do
11
+ gem 'rake'
12
+ end
@@ -0,0 +1,5 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
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.
@@ -0,0 +1,32 @@
1
+ # FreeGeoIP
2
+
3
+ Despite what the incredibly witty title might lead you to believe, this is a Ruby API client for [FreeGeoIP's IP geolocation API](http://freegeoip.net/static/index.html).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'freegeoip'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install freegeoip
18
+
19
+ ## Usage
20
+
21
+ require 'freegeoip'
22
+
23
+ FreeGeoIP.locate("zeke.templ.in")
24
+ # => I'll fill this in later.
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task :default => :spec
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/freegeoip/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 Client for FreeGeoIP's geolocation API}
8
+ gem.summary = %q{Ruby Client for FreeGeoIP's geolocation API}
9
+ gem.homepage = "http://github.com/ezkl/"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "freegeoip"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = FreeGeoIP::VERSION
17
+
18
+ gem.add_runtime_dependency("faraday", "0.8.0.rc2")
19
+ gem.add_runtime_dependency("multi_json", "1.2.0")
20
+ gem.add_development_dependency("rspec", "~> 2.9.0")
21
+ gem.add_development_dependency("vcr", "~> 2.0.0")
22
+ end
@@ -0,0 +1,19 @@
1
+ require "faraday"
2
+ require "multi_json"
3
+
4
+ module FreeGeoIP
5
+ CONNECTION = Faraday.new(:url => "http://freegeoip.net/json/") do |builder|
6
+ builder.adapter Faraday.default_adapter
7
+ end
8
+
9
+ def self.locate(address)
10
+ if (response = CONNECTION.get(address)).success?
11
+ MultiJson.decode(response.body)
12
+ else
13
+ false
14
+ end
15
+ end
16
+ end
17
+
18
+ require "freegeoip/version"
19
+ require "freegeoip/response"
@@ -0,0 +1,18 @@
1
+ module FreeGeoIP
2
+ class Response
3
+ attr_reader :city, :region, :region_code, :longitude, :latitude, :country, :country_code, :ip, :zip_code, :metro_code
4
+
5
+ def initialize(response_body)
6
+ @city = response_body['city']
7
+ @region = response_body['region_name']
8
+ @region_code = response_body['region_code']
9
+ @longitude = response_body['longitude']
10
+ @latitude = response_body['latitude']
11
+ @country = response_body['country_name']
12
+ @country_code = response_body['country_code']
13
+ @ip = response_body['ip']
14
+ @zip_code = response_body['zipcode']
15
+ @metro_code = response_body['metrocode']
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module FreeGeoIP
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,71 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://freegeoip.net/json/google-public-dns-a.google.com
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message:
14
+ headers:
15
+ server:
16
+ - nginx/0.7.67
17
+ date:
18
+ - Mon, 02 Apr 2012 02:47:46 GMT
19
+ content-type:
20
+ - application/json
21
+ connection:
22
+ - close
23
+ access-control-allow-origin:
24
+ - ! '*'
25
+ etag:
26
+ - ! '"037319b5e2a1a8d7c5b59d6f8786d875c9ae7e41"'
27
+ content-length:
28
+ - '235'
29
+ body:
30
+ encoding: US-ASCII
31
+ string: ! '{"city": "Mountain View", "region_code": "CA", "longitude": "-122.057",
32
+ "region_name": "California", "country_code": "US", "latitude": "37.4192",
33
+ "country_name": "United States", "ip": "8.8.8.8", "zipcode": "94043", "metrocode":
34
+ "807"}'
35
+ http_version:
36
+ recorded_at: Mon, 02 Apr 2012 02:46:43 GMT
37
+ - request:
38
+ method: get
39
+ uri: http://freegeoip.net/json/8.8.8.8
40
+ body:
41
+ encoding: US-ASCII
42
+ string: ''
43
+ headers: {}
44
+ response:
45
+ status:
46
+ code: 200
47
+ message:
48
+ headers:
49
+ server:
50
+ - nginx/0.7.67
51
+ date:
52
+ - Mon, 02 Apr 2012 02:47:47 GMT
53
+ content-type:
54
+ - application/json
55
+ connection:
56
+ - close
57
+ access-control-allow-origin:
58
+ - ! '*'
59
+ etag:
60
+ - ! '"037319b5e2a1a8d7c5b59d6f8786d875c9ae7e41"'
61
+ content-length:
62
+ - '235'
63
+ body:
64
+ encoding: US-ASCII
65
+ string: ! '{"city": "Mountain View", "region_code": "CA", "longitude": "-122.057",
66
+ "region_name": "California", "country_code": "US", "latitude": "37.4192",
67
+ "country_name": "United States", "ip": "8.8.8.8", "zipcode": "94043", "metrocode":
68
+ "807"}'
69
+ http_version:
70
+ recorded_at: Mon, 02 Apr 2012 02:46:43 GMT
71
+ recorded_with: VCR 2.0.1
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "FreeGeoIP::Response", :vcr do
4
+ before(:all) do
5
+ VCR.use_cassette("locate") do
6
+ @host = FreeGeoIP.locate("google-public-dns-a.google.com")
7
+ end
8
+ @google_dns = FreeGeoIP::Response.new(@host)
9
+ end
10
+ context "success" do
11
+ subject { @google_dns }
12
+ it "should have the proper values" do
13
+ subject.city.should eq "Mountain View"
14
+ subject.region.should eq "California"
15
+ subject.region_code.should eq "CA"
16
+ subject.longitude.should eq "-122.057"
17
+ subject.latitude.should eq "37.4192"
18
+ subject.country.should eq "United States"
19
+ subject.country_code.should eq "US"
20
+ subject.ip.should eq "8.8.8.8"
21
+ subject.zip_code.should eq "94043"
22
+ subject.metro_code.should eq "807"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe FreeGeoIP do
4
+ describe "#locate" do
5
+ before(:all) do
6
+ VCR.use_cassette("locate") do
7
+ @host = subject.locate("google-public-dns-a.google.com")
8
+ @ip = subject.locate("8.8.8.8")
9
+ end
10
+ end
11
+
12
+ it "should not break" do
13
+ @host.should eq @ip
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ require "vcr"
2
+
3
+ VCR.configure do |c|
4
+ c.cassette_library_dir = 'spec/cassettes'
5
+ c.hook_into :faraday
6
+ c.configure_rspec_metadata!
7
+ end
8
+
9
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/freegeoip')
10
+
11
+ RSpec.configure do |config|
12
+ config.run_all_when_everything_filtered = true
13
+ config.mock_framework = :rspec
14
+ config.treat_symbols_as_metadata_keys_with_true_values = true
15
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: freegeoip
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-04-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.0.rc2
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.8.0.rc2
30
+ - !ruby/object:Gem::Dependency
31
+ name: multi_json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.2.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.9.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.9.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: vcr
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.0.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.0.0
78
+ description: Ruby Client for FreeGeoIP's geolocation API
79
+ email:
80
+ - zeke@templ.in
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rspec
87
+ - .rvmrc
88
+ - .travis.yml
89
+ - Gemfile
90
+ - Guardfile
91
+ - LICENSE
92
+ - README.md
93
+ - Rakefile
94
+ - freegeoip.gemspec
95
+ - lib/freegeoip.rb
96
+ - lib/freegeoip/response.rb
97
+ - lib/freegeoip/version.rb
98
+ - spec/cassettes/locate.yml
99
+ - spec/freegeoip/response_spec.rb
100
+ - spec/freeogeoip_spec.rb
101
+ - spec/spec_helper.rb
102
+ homepage: http://github.com/ezkl/
103
+ licenses: []
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ segments:
115
+ - 0
116
+ hash: -3507139357993624515
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ segments:
124
+ - 0
125
+ hash: -3507139357993624515
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 1.8.21
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Ruby Client for FreeGeoIP's geolocation API
132
+ test_files:
133
+ - spec/cassettes/locate.yml
134
+ - spec/freegeoip/response_spec.rb
135
+ - spec/freeogeoip_spec.rb
136
+ - spec/spec_helper.rb