kieranj-google-local-search 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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kieran Johnson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = google-local-search
2
+
3
+ Geocodes a UK postcode more accurately using the GoogleLocalSearch web service rather than the Google Maps API.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Kieran Johnson. See LICENSE for details.
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 0
3
+ :major: 0
4
+ :minor: 1
@@ -0,0 +1,27 @@
1
+ %w(uri net/http json cgi).each { |lib| require lib }
2
+
3
+ module GoogleLocalSearch
4
+
5
+ class GeoCode
6
+
7
+ GOOGLE_URL = "http://www.google.com/uds/GlocalSearch?"
8
+
9
+ class << self
10
+ def locate(address)
11
+ options = { "rsz" => "small", "v" => "1.0" }
12
+ options.merge!("q" => CGI.escape(address))
13
+
14
+ response = Net::HTTP.get_response(URI.parse(GOOGLE_URL + options.map { |k,v| "#{k}=#{v}" }.join("&")))
15
+ if response.is_a?(Net::HTTPSuccess)
16
+ result = JSON.parse(response.body)
17
+ return result['responseData']['results'][0]['lat'], result['responseData']['results'][0]['lng']
18
+ else
19
+ response.error!
20
+ end
21
+
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,27 @@
1
+ require File.join(File.dirname(__FILE__), "..", "lib", "google_local_search")
2
+
3
+ describe "GoogleLocalSearch" do
4
+
5
+ describe "Geocode" do
6
+
7
+ before do
8
+ @response = Net::HTTPSuccess.new('1.1', '200', 'OK')
9
+ Net::HTTP.stub!(:get_response).and_return(@response)
10
+ @response.stub!(:body).and_return('{"responseData": {"results":[{"GsearchResultClass":"GlocalSearch","listingType":"local","addressLookupResult":"/maps","lat":"51.533313","lng":"-0.146907","accuracy":"5","title":"London NW1","titleNoFormatting":"London NW1","ddUrl":"http://www.google.com/maps?source\u003duds\u0026daddr\u003dLondon+NW1%2C+London+%28London+NW1%29+%4051.533313%2C-0.146907\u0026saddr","ddUrlToHere":"http://www.google.com/maps?source\u003duds\u0026daddr\u003dLondon+NW1%2C+London+%28London+NW1%29+%4051.533313%2C-0.146907\u0026iwstate1\u003ddir%3Ato","ddUrlFromHere":"http://www.google.com/maps?source\u003duds\u0026saddr\u003dLondon+NW1%2C+London+%28London+NW1%29+%4051.533313%2C-0.146907\u0026iwstate1\u003ddir%3Afrom","streetAddress":"London NW1","city":"London","region":"","country":"GB","staticMapUrl":"http://mt.google.com/mapdata?cc\u003dus\u0026tstyp\u003d5\u0026Point\u003db\u0026Point.latitude_e6\u003d51533313\u0026Point.longitude_e6\u003d-146907\u0026Point.iconid\u003d15\u0026Point\u003de\u0026w\u003d150\u0026h\u003d100\u0026zl\u003d4","url":"http://www.google.com/maps?source\u003duds\u0026q\u003dNW1","postalCode":"NW1","maxAge":604800,"addressLines":["London NW1","UK"]}],"cursor":{"moreResultsUrl":"http://www.google.com/local?oe\u003dutf8\u0026ie\u003dutf8\u0026num\u003d4\u0026mrt\u003dyp%2Cloc\u0026sll\u003d37.779160%2C-122.420090\u0026start\u003d0\u0026hl\u003den\u0026q\u003dNW1"},"viewport":{"center":{"lat":"51.533313","lng":"-0.146907"},"span":{"lat":"0.036858","lng":"0.049982"},"sw":{"lat":"51.514885","lng":"-0.171898"},"ne":{"lat":"51.551743","lng":"-0.121916"}}}, "responseDetails": null, "responseStatus": 200}')
11
+ end
12
+
13
+ it "should raise ArgumentError if no address supplied" do
14
+ lambda { GoogleLocalSearch::GeoCode.locate.should raise_error(ArgumentError) }
15
+ end
16
+
17
+ it "should return lat/lng array" do
18
+ GoogleLocalSearch::GeoCode.locate("NW1").should be_instance_of(Array)
19
+ end
20
+
21
+ it "should have 2 items in the array" do
22
+ GoogleLocalSearch::GeoCode.locate("NW1").length.should == 2
23
+ end
24
+
25
+ end
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kieranj-google-local-search
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kieran Johnson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-02 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: kieran@invisiblelines.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE
25
+ files:
26
+ - README.rdoc
27
+ - VERSION.yml
28
+ - lib/google_local_search.rb
29
+ - spec/google_local_search_spec.rb
30
+ - LICENSE
31
+ has_rdoc: true
32
+ homepage: http://github.com/kieranj/google-local-search
33
+ post_install_message:
34
+ rdoc_options:
35
+ - --inline-source
36
+ - --charset=UTF-8
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ requirements: []
52
+
53
+ rubyforge_project:
54
+ rubygems_version: 1.2.0
55
+ signing_key:
56
+ specification_version: 2
57
+ summary: TODO
58
+ test_files: []
59
+