bag42_geocoder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bag42_geocoder.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Joost Hietbrink
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,36 @@
1
+ # Bag42Geocoder
2
+
3
+ Extension of Geocoder gem with Bag42.
4
+ For more information see: http://calendar42.com/bag42/
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'bag42_geocoder'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install bag42_geocoder
19
+
20
+ ## Usage
21
+
22
+ To enable use:
23
+
24
+ Geocoder.configure { |config|
25
+ config.lookup = :bag42
26
+ }
27
+
28
+ For example add this to config/initializers/geocoder.rb.
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/bag42_geocoder/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Joost Hietbrink"]
6
+ gem.email = ["joost@joopp.com"]
7
+ gem.description = %q{Extension of Geocoder gem with Bag42.}
8
+ gem.summary = %q{Extension of Geocoder gem with Bag42.re}
9
+ gem.homepage = ""
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 = "bag42_geocoder"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Bag42Geocoder::VERSION
17
+
18
+ gem.add_dependency('geocoder', '1.1.4')
19
+ end
@@ -0,0 +1,27 @@
1
+ require "bag42_geocoder/version"
2
+
3
+ require "bag42_geocoder/lookups/bag42"
4
+ require "bag42_geocoder/results/bag42"
5
+
6
+ module Geocoder
7
+ module Lookup
8
+ def street_services
9
+ [
10
+ :bag42,
11
+ :google,
12
+ :google_premier,
13
+ :yahoo,
14
+ :bing,
15
+ :geocoder_ca,
16
+ :yandex,
17
+ :nominatim,
18
+ :mapquest,
19
+ :test
20
+ ]
21
+ end
22
+ end
23
+ end
24
+
25
+ # Geocoder.configure { |config|
26
+ # config.lookup = :bag42
27
+ # }
@@ -0,0 +1,39 @@
1
+ require 'geocoder/lookups/base'
2
+ require "geocoder/results/google"
3
+
4
+ module Geocoder::Lookup
5
+ class Bag42 < Base
6
+
7
+ def map_link_url(coordinates)
8
+ "http://maps.google.com/maps?q=#{coordinates.join(',')}"
9
+ end
10
+
11
+ private # ---------------------------------------------------------------
12
+
13
+ def results(query)
14
+ return [] unless doc = fetch_data(query)
15
+ case doc['status']; when "OK" # OK status implies >0 results
16
+ return doc['results']
17
+ when "OVER_QUERY_LIMIT"
18
+ raise_error(Geocoder::OverQueryLimitError) ||
19
+ warn("Bag42 Geocoding API error: over query limit.")
20
+ when "REQUEST_DENIED"
21
+ warn "Bag42 Geocoding API error: request denied."
22
+ when "INVALID_REQUEST"
23
+ warn "Bag42 Geocoding API error: invalid request."
24
+ end
25
+ return []
26
+ end
27
+
28
+ def query_url(query, reverse = false)
29
+ params = {
30
+ (reverse ? :latlng : :address) => query,
31
+ :sensor => "false",
32
+ :language => Geocoder::Configuration.language #,
33
+ # :key => Geocoder::Configuration.api_key
34
+ }
35
+ "#{protocol}://bag42.nl/api/v0/geocode/json?" + hash_to_query(params)
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,116 @@
1
+ require 'geocoder/results/base'
2
+
3
+ # See: http://calendar42.com/bag42/ and http://bag42.nl/
4
+ # Load using:
5
+ # module Geocoder
6
+ # def self.street_lookups
7
+ # [:bag42, :google_premier, :yahoo, :bing, :geocoder_ca, :yandex, :nominatim]
8
+ # end
9
+ # end
10
+ # Geocoder.configure { |config| config.lookup = :bag42 }
11
+ # result = Geocoder.search("Hoogstraat 31, Rotterdam")
12
+
13
+ module Geocoder::Result
14
+ class Bag42 < Geocoder::Result::Google
15
+ # Nothing to do here..
16
+
17
+ def coordinates
18
+ ['lat', 'lng'].map{ |i| geometry['location'][i] }
19
+ end
20
+
21
+ def address(format = :full)
22
+ formatted_address
23
+ end
24
+
25
+ def city
26
+ fields = [:locality, :sublocality,
27
+ :administrative_area_level_3,
28
+ :administrative_area_level_2]
29
+ fields.each do |f|
30
+ if entity = address_components_of_type(f).first
31
+ return entity['long_name']
32
+ end
33
+ end
34
+ return nil # no appropriate components found
35
+ end
36
+
37
+ def state
38
+ if state = address_components_of_type(:administrative_area_level_1).first
39
+ state['long_name']
40
+ end
41
+ end
42
+
43
+ def state_code
44
+ if state = address_components_of_type(:administrative_area_level_1).first
45
+ state['short_name']
46
+ end
47
+ end
48
+
49
+ def country
50
+ if country = address_components_of_type(:country).first
51
+ country['long_name']
52
+ end
53
+ end
54
+
55
+ def country_code
56
+ if country = address_components_of_type(:country).first
57
+ country['short_name']
58
+ end
59
+ end
60
+
61
+ def postal_code
62
+ if postal = address_components_of_type(:postcode_code).first
63
+ postal['long_name']
64
+ end
65
+ end
66
+
67
+ def registered_name
68
+ if registered_name = company_components_of_type(:registered_name).first
69
+ registered_name['long_name']
70
+ end
71
+ end
72
+
73
+ def types
74
+ @data['types']
75
+ end
76
+
77
+ def formatted_address
78
+ @data['formatted_address']
79
+ end
80
+
81
+ def address_components
82
+ @data['address_components']
83
+ end
84
+
85
+ def company_components
86
+ @data['companny_components'] || @data['company_components'] # NOTE: The typo is on purpose! We fallback on non-type to be compatible when they fix this!
87
+ end
88
+
89
+ ##
90
+ # Get address components of a given type. Valid types are defined in
91
+ # Google's Geocoding API documentation and include (among others):
92
+ #
93
+ # :street_number
94
+ # :locality
95
+ # :neighborhood
96
+ # :route
97
+ # :postal_code
98
+ #
99
+ def address_components_of_type(type)
100
+ address_components.select{ |c| c['types'].include?(type.to_s) }
101
+ end
102
+
103
+ def company_components_of_type(type)
104
+ return [] if company_components.nil?
105
+ company_components.select{ |c| c['types'].include?(type.to_s) }
106
+ end
107
+
108
+ def geometry
109
+ @data['geometry']
110
+ end
111
+
112
+ def precision
113
+ geometry['location_type'] if geometry
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,3 @@
1
+ module Bag42Geocoder
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bag42_geocoder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joost Hietbrink
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: geocoder
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.4
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: 1.1.4
30
+ description: Extension of Geocoder gem with Bag42.
31
+ email:
32
+ - joost@joopp.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - bag42_geocoder.gemspec
43
+ - lib/bag42_geocoder.rb
44
+ - lib/bag42_geocoder/lookups/bag42.rb
45
+ - lib/bag42_geocoder/results/bag42.rb
46
+ - lib/bag42_geocoder/version.rb
47
+ homepage: ''
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.24
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Extension of Geocoder gem with Bag42.re
71
+ test_files: []
72
+ has_rdoc: