drifter 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.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/README +102 -0
- data/README.rdoc +102 -0
- data/Rakefile +8 -0
- data/drifter.gemspec +21 -0
- data/lib/drifter.rb +92 -0
- data/lib/drifter/distance/haversine.rb +69 -0
- data/lib/drifter/geocoders.rb +3 -0
- data/lib/drifter/geocoders/base.rb +57 -0
- data/lib/drifter/geocoders/google.rb +91 -0
- data/lib/drifter/geocoders/hostip.rb +92 -0
- data/lib/drifter/geocoders/yahoo.rb +160 -0
- data/lib/drifter/location.rb +43 -0
- data/lib/drifter/location/locatable.rb +35 -0
- data/lib/drifter/version.rb +3 -0
- data/test/google_geocoder_test.rb +85 -0
- data/test/locatable_test.rb +101 -0
- data/test/location_test.rb +27 -0
- data/test/responses/google_error +4 -0
- data/test/responses/google_many_results +478 -0
- data/test/responses/google_no_results +4 -0
- data/test/responses/google_one_result +55 -0
- data/test/responses/yahoo_error +1 -0
- data/test/responses/yahoo_many_results +1 -0
- data/test/responses/yahoo_no_results +1 -0
- data/test/responses/yahoo_one_result +1 -0
- data/test/test_helper.rb +22 -0
- data/test/yahoo_geocoder_test.rb +76 -0
- metadata +110 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
{
|
2
|
+
"status": "OK",
|
3
|
+
"results": [ {
|
4
|
+
"types": [ "locality", "political" ],
|
5
|
+
"formatted_address": "Westminster, London, UK",
|
6
|
+
"address_components": [ {
|
7
|
+
"long_name": "London",
|
8
|
+
"short_name": "London",
|
9
|
+
"types": [ "locality", "political" ]
|
10
|
+
}, {
|
11
|
+
"long_name": "Westminster",
|
12
|
+
"short_name": "Westminster",
|
13
|
+
"types": [ "administrative_area_level_3", "political" ]
|
14
|
+
}, {
|
15
|
+
"long_name": "Greater London",
|
16
|
+
"short_name": "Greater London",
|
17
|
+
"types": [ "administrative_area_level_2", "political" ]
|
18
|
+
}, {
|
19
|
+
"long_name": "England",
|
20
|
+
"short_name": "England",
|
21
|
+
"types": [ "administrative_area_level_1", "political" ]
|
22
|
+
}, {
|
23
|
+
"long_name": "United Kingdom",
|
24
|
+
"short_name": "GB",
|
25
|
+
"types": [ "country", "political" ]
|
26
|
+
} ],
|
27
|
+
"geometry": {
|
28
|
+
"location": {
|
29
|
+
"lat": 51.5001524,
|
30
|
+
"lng": -0.1262362
|
31
|
+
},
|
32
|
+
"location_type": "APPROXIMATE",
|
33
|
+
"viewport": {
|
34
|
+
"southwest": {
|
35
|
+
"lat": 51.3493528,
|
36
|
+
"lng": -0.3783580
|
37
|
+
},
|
38
|
+
"northeast": {
|
39
|
+
"lat": 51.7040647,
|
40
|
+
"lng": 0.1502295
|
41
|
+
}
|
42
|
+
},
|
43
|
+
"bounds": {
|
44
|
+
"southwest": {
|
45
|
+
"lat": 51.3493528,
|
46
|
+
"lng": -0.3783580
|
47
|
+
},
|
48
|
+
"northeast": {
|
49
|
+
"lat": 51.7040647,
|
50
|
+
"lng": 0.1502295
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
} ]
|
55
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"ResultSet":{"version":"1.0","Error":100,"ErrorMessage":"No location parameters","Locale":"us_US","Quality":0,"Found":0}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"ResultSet":{"version":"1.0","Error":0,"ErrorMessage":"No error","Locale":"us_US","Quality":40,"Found":10,"Results":[{"quality":40,"latitude":"35.267435","longitude":"-92.557244","offsetlat":"35.267435","offsetlon":"-92.557244","radius":1300,"name":"","line1":"","line2":"Springfield, AR","line3":"","line4":"United States","house":"","street":"","xstreet":"","unittype":"","unit":"","postal":"","neighborhood":"","city":"Springfield","county":"Conway County","state":"Arkansas","country":"United States","countrycode":"US","statecode":"AR","countycode":"","uzip":"72157","hash":"","woeid":2498258,"woetype":7},{"quality":40,"latitude":"37.413710","longitude":"-102.616579","offsetlat":"37.413710","offsetlon":"-102.616579","radius":1700,"name":"","line1":"","line2":"Springfield, CO","line3":"","line4":"United States","house":"","street":"","xstreet":"","unittype":"","unit":"","postal":"","neighborhood":"","city":"Springfield","county":"Baca County","state":"Colorado","country":"United States","countrycode":"US","statecode":"CO","countycode":"","uzip":"81073","hash":"","woeid":2498261,"woetype":7},{"quality":40,"latitude":"30.155135","longitude":"-85.616494","offsetlat":"30.155135","offsetlon":"-85.616494","radius":4200,"name":"","line1":"","line2":"Springfield, FL","line3":"","line4":"United States","house":"","street":"","xstreet":"","unittype":"","unit":"","postal":"","neighborhood":"","city":"Springfield","county":"Bay County","state":"Florida","country":"United States","countrycode":"US","statecode":"FL","countycode":"","uzip":"32401","hash":"","woeid":2498262,"woetype":7},{"quality":40,"latitude":"32.370925","longitude":"-81.313430","offsetlat":"32.370925","offsetlon":"-81.313430","radius":2100,"name":"","line1":"","line2":"Springfield, GA","line3":"","line4":"United States","house":"","street":"","xstreet":"","unittype":"","unit":"","postal":"","neighborhood":"","city":"Springfield","county":"Effingham County","state":"Georgia","country":"United States","countrycode":"US","statecode":"GA","countycode":"","uzip":"31329","hash":"","woeid":2498309,"woetype":7},{"quality":40,"latitude":"43.081285","longitude":"-112.682309","offsetlat":"43.081285","offsetlon":"-112.682309","radius":1400,"name":"","line1":"","line2":"Springfield, ID","line3":"","line4":"United States","house":"","street":"","xstreet":"","unittype":"","unit":"","postal":"","neighborhood":"","city":"Springfield","county":"Bingham County","state":"Idaho","country":"United States","countrycode":"US","statecode":"ID","countycode":"","uzip":"83277","hash":"","woeid":2498318,"woetype":7},{"quality":40,"latitude":"39.801055","longitude":"-89.643604","offsetlat":"39.801055","offsetlon":"-89.643604","radius":16000,"name":"","line1":"","line2":"Springfield, IL","line3":"","line4":"United States","house":"","street":"","xstreet":"","unittype":"","unit":"","postal":"","neighborhood":"","city":"Springfield","county":"Sangamon County","state":"Illinois","country":"United States","countrycode":"US","statecode":"IL","countycode":"","uzip":"62701","hash":"","woeid":2498306,"woetype":7},{"quality":40,"latitude":"37.685450","longitude":"-85.222674","offsetlat":"37.685450","offsetlon":"-85.222674","radius":2600,"name":"","line1":"","line2":"Springfield, KY","line3":"","line4":"United States","house":"","street":"","xstreet":"","unittype":"","unit":"","postal":"","neighborhood":"","city":"Springfield","county":"Washington County","state":"Kentucky","country":"United States","countrycode":"US","statecode":"KY","countycode":"WA","uzip":"40069","hash":"","woeid":2498275,"woetype":7},{"quality":40,"latitude":"30.428810","longitude":"-90.549239","offsetlat":"30.428810","offsetlon":"-90.549239","radius":2200,"name":"","line1":"","line2":"Springfield, LA","line3":"","line4":"United States","house":"","street":"","xstreet":"","unittype":"","unit":"","postal":"","neighborhood":"","city":"Springfield","county":"Livingston Parish","state":"Louisiana","country":"United States","countrycode":"US","statecode":"LA","countycode":"","uzip":"70462","hash":"","woeid":2498276,"woetype":7},{"quality":40,"latitude":"45.395384","longitude":"-68.137404","offsetlat":"45.395384","offsetlon":"-68.137404","radius":8600,"name":"","line1":"","line2":"Springfield, ME","line3":"","line4":"United States","house":"","street":"","xstreet":"","unittype":"","unit":"","postal":"","neighborhood":"","city":"Springfield","county":"Penobscot County","state":"Maine","country":"United States","countrycode":"US","statecode":"ME","countycode":"","uzip":"04487","hash":"","woeid":2498314,"woetype":7},{"quality":40,"latitude":"42.101250","longitude":"-72.589294","offsetlat":"42.101250","offsetlon":"-72.589294","radius":11800,"name":"","line1":"","line2":"Springfield, MA","line3":"","line4":"United States","house":"","street":"","xstreet":"","unittype":"","unit":"","postal":"","neighborhood":"","city":"Springfield","county":"Hampden County","state":"Massachusetts","country":"United States","countrycode":"US","statecode":"MA","countycode":"","uzip":"01103","hash":"","woeid":2498304,"woetype":7}]}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"ResultSet":{"version":"1.0","Error":0,"ErrorMessage":"No error","Locale":"us_US","Quality":10,"Found":0}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"ResultSet":{"version":"1.0","Error":0,"ErrorMessage":"No error","Locale":"us_US","Quality":40,"Found":1,"Results":[{"quality":40,"latitude":"53.578450","longitude":"-2.426664","offsetlat":"53.578450","offsetlon":"-2.426664","radius":71500,"name":"","line1":"","line2":"Bolton","line3":"","line4":"United Kingdom","house":"","street":"","xstreet":"","unittype":"","unit":"","postal":"","neighborhood":"","city":"Bolton","county":"Lancashire","state":"England","country":"United Kingdom","countrycode":"GB","statecode":"ENG","countycode":"LAN","uzip":"BL1 1","hash":"","woeid":12602160,"woetype":9}]}}
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'ruby-debug'
|
3
|
+
require 'fakeweb'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
$: << File.expand_path('../../lib', __FILE__)
|
7
|
+
require 'drifter'
|
8
|
+
|
9
|
+
|
10
|
+
# nodoc
|
11
|
+
def open_web_response(filename)
|
12
|
+
path_to_file = [File.dirname(__FILE__), 'responses', filename].join('/')
|
13
|
+
File.open(path_to_file, 'r') { |f| f.read }
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
# nodoc
|
18
|
+
def save_web_response(uri, filename)
|
19
|
+
path_to_file = [File.dirname(__FILE__), 'responses', filename].join('/')
|
20
|
+
response = Net::HTTP.get(uri.host, uri.request_uri)
|
21
|
+
File.open(path_to_file, 'w') { |f| f.write response }
|
22
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class YahooGeocoderTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Drifter::Geocoders::Yahoo.api_key = "foo"
|
7
|
+
end
|
8
|
+
|
9
|
+
# checks that the given Location object has the the expected values when Geocoded using Yahoo
|
10
|
+
def assert_yahoo_location(data, loc)
|
11
|
+
assert_equal :yahoo, loc.geocoder
|
12
|
+
assert_equal :hash, loc.raw_data_format
|
13
|
+
assert_equal data["city"], loc.city
|
14
|
+
assert_equal data["state"], loc.state
|
15
|
+
assert_equal data["postal"], loc.post_code
|
16
|
+
assert_equal data["countrycode"], loc.country_code
|
17
|
+
assert_equal data["latitude"], loc.lat
|
18
|
+
assert_equal data["longitude"], loc.lng
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
# nodoc
|
23
|
+
def stub_response(response_file)
|
24
|
+
response = open_web_response(response_file)
|
25
|
+
rx = Regexp.new(Drifter::Geocoders::Yahoo.base_uri)
|
26
|
+
FakeWeb.register_uri(:get, rx, :body => response)
|
27
|
+
|
28
|
+
results = Drifter::Geocoders::Yahoo.geocode("springfield")
|
29
|
+
data = JSON.parse(response)
|
30
|
+
error = Drifter::Geocoders::Yahoo.last_error
|
31
|
+
|
32
|
+
return results, data, error
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
# nodoc
|
37
|
+
def test_error
|
38
|
+
results, data, error = stub_response('yahoo_error')
|
39
|
+
assert_nil results
|
40
|
+
assert_equal data["ResultSet"]["ErrorMessage"], error[:message]
|
41
|
+
assert_equal data["ResultSet"]["Error"], error[:code]
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
# nodoc
|
46
|
+
def test_success_with_no_results
|
47
|
+
results, data, error = stub_response('yahoo_no_results')
|
48
|
+
assert_nil error
|
49
|
+
assert results.is_a?(Array)
|
50
|
+
assert results.empty?
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# nodoc
|
55
|
+
def test_success_with_one_result
|
56
|
+
results, data, error = stub_response('yahoo_one_result')
|
57
|
+
assert_nil error
|
58
|
+
assert results.is_a?(Array)
|
59
|
+
assert_equal 1, results.size
|
60
|
+
assert_yahoo_location data["ResultSet"]["Results"].first, results.first
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
# ndoc
|
65
|
+
def test_success_with_many_results
|
66
|
+
results, data, error = stub_response('yahoo_many_results')
|
67
|
+
assert_nil error
|
68
|
+
assert results.is_a?(Array)
|
69
|
+
assert_equal data["ResultSet"]["Found"], results.size
|
70
|
+
results.each_with_index do |loc, i|
|
71
|
+
loc_data = data["ResultSet"]["Results"][i]
|
72
|
+
assert_yahoo_location loc_data, loc
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: drifter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ahmed Adam
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-22 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: json
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 11
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 4
|
33
|
+
- 6
|
34
|
+
version: 1.4.6
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description:
|
38
|
+
email:
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- .gitignore
|
47
|
+
- Gemfile
|
48
|
+
- README
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- drifter.gemspec
|
52
|
+
- lib/drifter.rb
|
53
|
+
- lib/drifter/distance/haversine.rb
|
54
|
+
- lib/drifter/geocoders.rb
|
55
|
+
- lib/drifter/geocoders/base.rb
|
56
|
+
- lib/drifter/geocoders/google.rb
|
57
|
+
- lib/drifter/geocoders/hostip.rb
|
58
|
+
- lib/drifter/geocoders/yahoo.rb
|
59
|
+
- lib/drifter/location.rb
|
60
|
+
- lib/drifter/location/locatable.rb
|
61
|
+
- lib/drifter/version.rb
|
62
|
+
- test/google_geocoder_test.rb
|
63
|
+
- test/locatable_test.rb
|
64
|
+
- test/location_test.rb
|
65
|
+
- test/responses/google_error
|
66
|
+
- test/responses/google_many_results
|
67
|
+
- test/responses/google_no_results
|
68
|
+
- test/responses/google_one_result
|
69
|
+
- test/responses/yahoo_error
|
70
|
+
- test/responses/yahoo_many_results
|
71
|
+
- test/responses/yahoo_no_results
|
72
|
+
- test/responses/yahoo_one_result
|
73
|
+
- test/test_helper.rb
|
74
|
+
- test/yahoo_geocoder_test.rb
|
75
|
+
has_rdoc: true
|
76
|
+
homepage: http://github.com/ahmedrb/drifter
|
77
|
+
licenses: []
|
78
|
+
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
requirements: []
|
103
|
+
|
104
|
+
rubyforge_project: drifter
|
105
|
+
rubygems_version: 1.3.7
|
106
|
+
signing_key:
|
107
|
+
specification_version: 3
|
108
|
+
summary: Simple geocoding library for ruby
|
109
|
+
test_files: []
|
110
|
+
|