graticule 2.0.0 → 2.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.
data/README.textile ADDED
@@ -0,0 +1,43 @@
1
+ h1. Graticule
2
+
3
+ Graticule is a geocoding API for looking up address coordinates. It supports many popular APIs, including Yahoo, Google, Geocoder.ca and Geocoder.us.
4
+
5
+ h2. Usage
6
+
7
+ <pre><code>require 'rubygems'
8
+ require 'graticule'
9
+ geocoder = Graticule.service(:google).new "api_key"
10
+ location = geocoder.locate "61 East 9th Street, Holland, MI"</code></pre>
11
+
12
+ h2. Distance Calculation
13
+
14
+ Graticule includes 3 different distance formulas, Spherical (simplest but least accurate), Vincenty (most accurate and most complicated), and Haversine (somewhere inbetween).
15
+
16
+ <pre><code>geocoder.locate("Holland, MI").distance_to(geocoder.locate("Chicago, IL"))
17
+ #=> 101.997458788177</code></pre>
18
+
19
+ h2. Command Line
20
+
21
+ Graticule includes a command line interface (CLI).
22
+
23
+ <pre><code>$ geocode -s yahoo -a yahookey Washington, DC
24
+ Washington, DC US
25
+ latitude: 38.895222, longitude: -77.036758</code></pre>
26
+
27
+ h2. Mailing List
28
+
29
+ Join us on the "mailing list":http://groups.google.com/group/graticule.
30
+
31
+ h2. How to contribute
32
+
33
+ If you find what you might think is a bug:
34
+
35
+ # Check the "GitHub issue tracker":http://github.com/collectiveidea/graticule/issues/ to see if anyone else has had the same issue.
36
+ # If you don't see anything, create an issue with information on how to reproduce it.
37
+
38
+ If you want to contribute an enhancement or a fix:
39
+
40
+ # Fork "the project":http://github.com/collectiveidea/graticule/ on GitHub.
41
+ # Make your changes with tests.
42
+ # Commit the changes without making changes to the Rakefile, VERSION, or any other files that aren't related to your enhancement or fix
43
+ # Send a pull request.
data/lib/graticule.rb CHANGED
@@ -21,6 +21,7 @@ require 'graticule/geocoder/local_search_maps'
21
21
  require 'graticule/geocoder/freethepostcode'
22
22
  require 'graticule/geocoder/multimap'
23
23
  require 'graticule/geocoder/mapquest'
24
+ require 'graticule/geocoder/simple_geo'
24
25
  require 'graticule/distance'
25
26
  require 'graticule/distance/haversine'
26
27
  require 'graticule/distance/spherical'
data/lib/graticule/cli.rb CHANGED
@@ -45,7 +45,7 @@ module Graticule
45
45
  result = Graticule.service(options[:service]).new(*options[:api_key].split(',')).locate(options[:location])
46
46
  location = (result.is_a?(Array) ? result.first : result)
47
47
  if location
48
- out << location.to_s(:coordinates => true)
48
+ out << location.to_s(:coordinates => true) + "\n"
49
49
  exit 0
50
50
  else
51
51
  out << "Location not found"
@@ -0,0 +1,64 @@
1
+ require 'json'
2
+
3
+ module Graticule
4
+ module Geocoder
5
+
6
+ # First you need a SimpleGeo JSONP API key. You can register for one here:
7
+ # http://simplegeo.com/docs/clients-code-libraries/javascript-sdk
8
+ #
9
+ # gg = Graticule.service(:SimpleGeo).new(SIMPLEGEO_TOKEN)
10
+ # location = gg.locate '1600 Amphitheater Pkwy, Mountain View, CA'
11
+ # location.coordinates
12
+ # #=> [37.423111, -122.081783]
13
+ #
14
+ class SimpleGeo < Base
15
+
16
+ def initialize(token)
17
+ @token = token
18
+ @url = URI.parse 'http://api.simplegeo.com/1.0/context/address.json?'
19
+ end
20
+
21
+ def locate(query)
22
+ get :address => "#{query}"
23
+ end
24
+
25
+ # reimplement Base#get so we can return only the time zone for replacing geonames
26
+ def time_zone(query)
27
+ response = prepare_response(make_url(:address => "#{query}").open('User-Agent' => USER_AGENT).read)
28
+ check_error(response)
29
+ return parse_time_zone(response)
30
+ rescue OpenURI::HTTPError => e
31
+ check_error(prepare_response(e.io.read))
32
+ raise
33
+ end
34
+
35
+ private
36
+
37
+ def prepare_response(response)
38
+ JSON.parse(response)
39
+ end
40
+
41
+ def parse_response(response)
42
+ Location.new(
43
+ :latitude => response["query"]["latitude"],
44
+ :longitude => response["query"]["longitude"],
45
+ :precision => :unknown
46
+ )
47
+ end
48
+
49
+ def parse_time_zone(response)
50
+ response["features"].detect do |feature|
51
+ feature["classifiers"].first["category"] == "Time Zone"
52
+ end["name"]
53
+ end
54
+
55
+ def check_error(response)
56
+ raise Error, response["message"] unless response["message"].blank?
57
+ end
58
+
59
+ def make_url(params)
60
+ super params.merge(:token => @token)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,60 +1,56 @@
1
1
  module Graticule
2
-
2
+
3
3
  # A geographic location
4
4
  class Location
5
5
  attr_accessor :latitude, :longitude, :street, :locality, :region, :postal_code, :country, :precision, :warning
6
6
  alias_method :city, :locality
7
7
  alias_method :state, :region
8
8
  alias_method :zip, :postal_code
9
-
9
+
10
10
  def initialize(attrs = {})
11
11
  attrs.each do |key,value|
12
12
  self.send("#{key}=", value)
13
13
  end
14
14
  self.precision ||= :unknown
15
15
  end
16
-
16
+
17
17
  def precision=(precision)
18
18
  @precision = Precision.new(precision.to_s)
19
19
  end
20
-
20
+
21
21
  def attributes
22
22
  [:latitude, :longitude, :street, :locality, :region, :postal_code, :country, :precision].inject({}) do |result,attr|
23
23
  result[attr] = self.send(attr) unless self.send(attr).blank?
24
24
  result
25
25
  end
26
26
  end
27
-
27
+
28
28
  def blank?
29
29
  attributes.except(:precision).empty?
30
30
  end
31
-
31
+
32
32
  # Returns an Array with latitude and longitude.
33
33
  def coordinates
34
34
  [latitude, longitude]
35
35
  end
36
-
36
+
37
37
  def ==(other)
38
38
  other.respond_to?(:attributes) ? attributes == other.attributes : false
39
39
  end
40
-
40
+
41
41
  # Calculate the distance to another location. See the various Distance formulas
42
42
  # for more information
43
43
  def distance_to(destination, options = {})
44
44
  options = {:formula => :haversine, :units => :miles}.merge(options)
45
45
  "Graticule::Distance::#{options[:formula].to_s.titleize}".constantize.distance(self, destination, options[:units])
46
46
  end
47
-
47
+
48
48
  # Where would I be if I dug through the center of the earth?
49
49
  def antipode
50
50
  Location.new :latitude => -latitude, :longitude => longitude + (longitude >= 0 ? -180 : 180)
51
51
  end
52
52
  alias_method :antipodal_location, :antipode
53
-
54
- def time_zone
55
- Graticule::Geocoder::Geonames.new.time_zone self
56
- end
57
-
53
+
58
54
  def to_s(options = {})
59
55
  options = {:coordinates => false, :country => true}.merge(options)
60
56
  result = ""
@@ -64,6 +60,6 @@ module Graticule
64
60
  result << "\nlatitude: #{latitude}, longitude: #{longitude}" if options[:coordinates] && [latitude, longitude].any?
65
61
  result
66
62
  end
67
-
63
+
68
64
  end
69
65
  end
@@ -1,3 +1,3 @@
1
1
  module Graticule
2
- VERSION = '2.0.0' unless defined?(::Graticule::VERSION)
2
+ VERSION = '2.0.1' unless defined?(::Graticule::VERSION)
3
3
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graticule
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 13
4
5
  prerelease: false
5
6
  segments:
6
7
  - 2
7
8
  - 0
8
- - 0
9
- version: 2.0.0
9
+ - 1
10
+ version: 2.0.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Brandon Keepers
@@ -15,71 +16,95 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-10-01 00:00:00 -04:00
19
+ date: 2011-02-28 00:00:00 -05:00
19
20
  default_executable: geocode
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- type: :runtime
24
23
  version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
+ hash: 3
28
29
  segments:
29
30
  - 0
30
31
  version: "0"
31
32
  requirement: *id001
33
+ type: :runtime
32
34
  name: activesupport
33
- - !ruby/object:Gem::Dependency
34
35
  prerelease: false
35
- type: :runtime
36
+ - !ruby/object:Gem::Dependency
36
37
  version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
37
39
  requirements:
38
40
  - - ">="
39
41
  - !ruby/object:Gem::Version
42
+ hash: 3
40
43
  segments:
41
44
  - 0
42
45
  version: "0"
43
46
  requirement: *id002
47
+ type: :runtime
44
48
  name: i18n
45
- - !ruby/object:Gem::Dependency
46
49
  prerelease: false
47
- type: :runtime
50
+ - !ruby/object:Gem::Dependency
48
51
  version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
49
53
  requirements:
50
54
  - - ">="
51
55
  - !ruby/object:Gem::Version
56
+ hash: 19
52
57
  segments:
53
58
  - 0
54
59
  - 3
55
60
  - 0
56
61
  version: 0.3.0
57
62
  requirement: *id003
63
+ type: :runtime
58
64
  name: happymapper
59
- - !ruby/object:Gem::Dependency
60
65
  prerelease: false
61
- type: :development
66
+ - !ruby/object:Gem::Dependency
62
67
  version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
63
69
  requirements:
64
70
  - - ">="
65
71
  - !ruby/object:Gem::Version
72
+ hash: 3
66
73
  segments:
67
74
  - 0
68
75
  version: "0"
69
76
  requirement: *id004
70
- name: mocha
71
- - !ruby/object:Gem::Dependency
77
+ type: :runtime
78
+ name: json
72
79
  prerelease: false
73
- type: :development
80
+ - !ruby/object:Gem::Dependency
74
81
  version_requirements: &id005 !ruby/object:Gem::Requirement
82
+ none: false
75
83
  requirements:
76
84
  - - ">="
77
85
  - !ruby/object:Gem::Version
86
+ hash: 3
78
87
  segments:
79
88
  - 0
80
89
  version: "0"
81
90
  requirement: *id005
91
+ type: :development
92
+ name: mocha
93
+ prerelease: false
94
+ - !ruby/object:Gem::Dependency
95
+ version_requirements: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ requirement: *id006
105
+ type: :development
82
106
  name: rcov
107
+ prerelease: false
83
108
  description: Graticule is a geocoding API that provides a common interface to all the popular services, including Google, Yahoo, Geocoder.us, and MetaCarta.
84
109
  email: brandon@opensoul.org
85
110
  executables:
@@ -87,7 +112,7 @@ executables:
87
112
  extensions: []
88
113
 
89
114
  extra_rdoc_files:
90
- - README.txt
115
+ - README.textile
91
116
  files:
92
117
  - bin/geocode
93
118
  - lib/graticule/cli.rb
@@ -108,6 +133,7 @@ files:
108
133
  - lib/graticule/geocoder/mapquest.rb
109
134
  - lib/graticule/geocoder/multi.rb
110
135
  - lib/graticule/geocoder/multimap.rb
136
+ - lib/graticule/geocoder/simple_geo.rb
111
137
  - lib/graticule/geocoder/yahoo.rb
112
138
  - lib/graticule/geocoder.rb
113
139
  - lib/graticule/location.rb
@@ -116,7 +142,7 @@ files:
116
142
  - lib/graticule.rb
117
143
  - CHANGELOG.txt
118
144
  - LICENSE.txt
119
- - README.txt
145
+ - README.textile
120
146
  has_rdoc: true
121
147
  homepage: http://github.com/collectiveidea/graticule
122
148
  licenses: []
@@ -130,23 +156,27 @@ rdoc_options:
130
156
  require_paths:
131
157
  - lib
132
158
  required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
133
160
  requirements:
134
161
  - - ">="
135
162
  - !ruby/object:Gem::Version
163
+ hash: 3
136
164
  segments:
137
165
  - 0
138
166
  version: "0"
139
167
  required_rubygems_version: !ruby/object:Gem::Requirement
168
+ none: false
140
169
  requirements:
141
170
  - - ">="
142
171
  - !ruby/object:Gem::Version
172
+ hash: 3
143
173
  segments:
144
174
  - 0
145
175
  version: "0"
146
176
  requirements: []
147
177
 
148
178
  rubyforge_project: graticule
149
- rubygems_version: 1.3.6
179
+ rubygems_version: 1.3.7
150
180
  signing_key:
151
181
  specification_version: 3
152
182
  summary: API for using all the popular geocoding services.
data/README.txt DELETED
@@ -1,45 +0,0 @@
1
- = Graticule
2
-
3
- Graticule is a geocoding API for looking up address coordinates. It supports many popular APIs, including Yahoo, Google, Geocoder.ca and Geocoder.us.
4
-
5
- = Usage
6
-
7
- require 'rubygems'
8
- require 'graticule'
9
- geocoder = Graticule.service(:google).new "api_key"
10
- location = geocoder.locate "61 East 9th Street, Holland, MI"
11
-
12
- = Distance Calculation
13
-
14
- Graticule includes 3 different distance formulas, Spherical (simplest but least accurate), Vincenty (most accurate and most complicated), and Haversine (somewhere inbetween).
15
-
16
- geocoder.locate("Holland, MI").distance_to(geocoder.locate("Chicago, IL"))
17
- #=> 101.997458788177
18
-
19
- = Command Line
20
-
21
- Graticule includes a command line interface (CLI).
22
-
23
- $ geocode -s yahoo -a yahookey Washington, DC
24
- Washington, DC US
25
- latitude: 38.895222, longitude: -77.036758
26
-
27
- = Mailing List
28
-
29
- Join us on the mailing list at http://groups.google.com/group/graticule
30
-
31
- = How to contribute
32
-
33
- If you find what you might think is a bug:
34
-
35
- 1. Check the GitHub issue tracker to see if anyone else has had the same issue.
36
- http://github.com/collectiveidea/graticule/issues/
37
- 2. If you don't see anything, create an issue with information on how to reproduce it.
38
-
39
- If you want to contribute an enhancement or a fix:
40
-
41
- 1. Fork the project on github.
42
- http://github.com/collectiveidea/graticule/
43
- 2. Make your changes with tests.
44
- 3. Commit the changes without making changes to the Rakefile, VERSION, or any other files that aren't related to your enhancement or fix
45
- 4. Send a pull request.