opencage-geocoder 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/opencage/geocoder.rb +31 -0
- metadata +46 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'geocoder/location'
|
2
|
+
|
3
|
+
module OpenCage
|
4
|
+
class Geocoder
|
5
|
+
GeocodingError = Class.new(StandardError)
|
6
|
+
|
7
|
+
BASE_URL = "http://api.opencagedata.com/geocode/v1/json"
|
8
|
+
|
9
|
+
attr_reader :api_key
|
10
|
+
|
11
|
+
def initialize(options={})
|
12
|
+
@api_key = options.fetch(:api_key) { raise GeocodingError.new('missing API key') }
|
13
|
+
end
|
14
|
+
|
15
|
+
def geocode(location)
|
16
|
+
Location.new(self, name: location).coordinates
|
17
|
+
end
|
18
|
+
|
19
|
+
def reverse_geocode(*coordinates)
|
20
|
+
# Accept input as numbers, strings or an array. Raise an error
|
21
|
+
# for anything that cannot be interpreted as a pair of floats.
|
22
|
+
lat, lng = coordinates.flatten.compact.map { |coord| Float(coord) }
|
23
|
+
|
24
|
+
Location.new(self, lat: lat, lng: lng).name
|
25
|
+
end
|
26
|
+
|
27
|
+
def url
|
28
|
+
"#{BASE_URL}?key=#{api_key}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opencage-geocoder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Samuel Scully
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A client for the OpenCage Data geocoder API
|
15
|
+
email: dev@lokku.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/opencage/geocoder.rb
|
21
|
+
homepage: https://github.com/lokku/ruby-opencage-geocoder
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.23
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: A client for the OpenCage Data geocoder API
|
46
|
+
test_files: []
|