twofishes 2.0.0 → 2.1.0.pre.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/twofishes.rb +1 -0
- data/lib/twofishes/client.rb +9 -6
- data/lib/twofishes/configuration.rb +2 -1
- data/lib/twofishes/geocode_request.rb +68 -0
- data/lib/twofishes/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60346193a88118337642826f79fb68b87373fda3
|
4
|
+
data.tar.gz: 1ca46ac922435ce41af3d5e46725689acf20ddc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74f76b892901bfb33ec5aa15cb913a74c28216a70d922647bc0793bd922d00864a8f07d6fe1d470ba6cc2a99316b14e1aed3af482929fdad79e541e09e62638e
|
7
|
+
data.tar.gz: 1ffe49e7909c92ee1bb6a7a2735973b86363444598d6075c61fae209d582179a8817825f130cdad180f9abe23a41540e77e6374cb506cbff2028359baf730e9e
|
data/lib/twofishes.rb
CHANGED
data/lib/twofishes/client.rb
CHANGED
@@ -11,9 +11,11 @@ module Twofishes
|
|
11
11
|
# @example
|
12
12
|
# Twofishes::Client.geocode('Zurich, Switzerland')
|
13
13
|
#
|
14
|
-
|
14
|
+
|
15
|
+
def self.geocode(location, options = {})
|
15
16
|
handle_response do
|
16
|
-
|
17
|
+
options[:query] = location
|
18
|
+
request = Twofishes::GeocodeRequest.new(options)
|
17
19
|
thrift_client.geocode(request)
|
18
20
|
end
|
19
21
|
end
|
@@ -25,10 +27,10 @@ module Twofishes
|
|
25
27
|
# @example
|
26
28
|
# Twofishes::Client.reverse_geocode([47.3787733, 8.5273363])
|
27
29
|
#
|
28
|
-
def self.reverse_geocode(coordinates,
|
30
|
+
def self.reverse_geocode(coordinates, options = {})
|
29
31
|
handle_response do
|
30
|
-
|
31
|
-
request = GeocodeRequest.new(
|
32
|
+
options[:ll] = coordinates
|
33
|
+
request = Twofishes::GeocodeRequest.new(options)
|
32
34
|
thrift_client.reverseGeocode(request)
|
33
35
|
end
|
34
36
|
end
|
@@ -38,7 +40,8 @@ module Twofishes
|
|
38
40
|
Geocoder::Client,
|
39
41
|
Twofishes.configuration.address,
|
40
42
|
retries: Twofishes.configuration.retries,
|
41
|
-
timeout: Twofishes.configuration.timeout
|
43
|
+
timeout: Twofishes.configuration.timeout,
|
44
|
+
connect_timeout: Twofishes.configuration.connect_timeout
|
42
45
|
)
|
43
46
|
end
|
44
47
|
|
@@ -2,13 +2,14 @@ module Twofishes
|
|
2
2
|
class Configuration
|
3
3
|
# @see https://github.com/thoughtbot/clearance/blob/master/lib/clearance/configuration.rb
|
4
4
|
|
5
|
-
attr_accessor :host, :port, :timeout, :retries
|
5
|
+
attr_accessor :host, :port, :timeout, :retries, :connect_timeout
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@host = '127.0.0.1'
|
9
9
|
@port = 8080
|
10
10
|
@timeout = 3
|
11
11
|
@retries = 2
|
12
|
+
@connect_timeout = 0.5
|
12
13
|
end
|
13
14
|
|
14
15
|
def address
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Twofishes
|
2
|
+
class GeocodeRequest < ::GeocodeRequest
|
3
|
+
def initialize(options = {})
|
4
|
+
options = substitute_aliases(options)
|
5
|
+
|
6
|
+
options[:ll] = prepare_ll(options[:ll])
|
7
|
+
options[:bounds] = prepare_bounds(options[:bounds])
|
8
|
+
|
9
|
+
super(options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def prepare_ll(ll)
|
13
|
+
case ll
|
14
|
+
when String
|
15
|
+
lat, lng = ll.split(/\s*,\s*/)
|
16
|
+
GeocodePoint.new(lat: lat.to_f, lng: lng.to_f)
|
17
|
+
when Array
|
18
|
+
GeocodePoint.new(lat: ll[0].to_f, lng: ll[1].to_f)
|
19
|
+
when Hash
|
20
|
+
GeocodePoint.new(lat: ll[:lat].to_f, lng: ll[:lng].to_f)
|
21
|
+
else
|
22
|
+
ll
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def prepare_bounds(bounds)
|
27
|
+
case bounds
|
28
|
+
when String
|
29
|
+
ne_lat, ne_lng, sw_lat, sw_lng = bounds.split(/\s*,\s*/)
|
30
|
+
ne = GeocodePoint.new(lat: ne_lat.to_f, lng: ne_lng.to_f)
|
31
|
+
sw = GeocodePoint.new(lat: sw_lat.to_f, lng: sw_lng.to_f)
|
32
|
+
GeocodeBoundingBox.new(ne: ne, sw: sw)
|
33
|
+
when Array
|
34
|
+
ne = GeocodePoint.new(lat: bounds[0].to_f, lng: bounds[1].to_f)
|
35
|
+
sw = GeocodePoint.new(lat: bounds[2].to_f, lng: bounds[3].to_f)
|
36
|
+
GeocodeBoundingBox.new(ne: ne, sw: sw)
|
37
|
+
when Hash
|
38
|
+
ne = GeocodePoint.new(lat: bounds[:ne_lat].to_f, lng: bounds[:ne_lng].to_f)
|
39
|
+
sw = GeocodePoint.new(lat: bounds[:sw_lat].to_f, lng: bounds[:sw_lng].to_f)
|
40
|
+
GeocodeBoundingBox.new(ne: ne, sw: sw)
|
41
|
+
else
|
42
|
+
bounds
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def substitute_aliases(options)
|
47
|
+
options = options.dup
|
48
|
+
|
49
|
+
options[:maxInterpretations] ||= options.delete(:max_interpretations) || options.delete(:max)
|
50
|
+
options[:allowedSources] ||= options.delete(:allowed_sources) || options.delete(:sources)
|
51
|
+
options[:responseIncludes] ||= options.delete(:response_includes) || options.delete(:includes)
|
52
|
+
options[:woeHint] ||= options.delete(:woe_hint)
|
53
|
+
options[:woeRestrict] ||= options.delete(:woe_restrict)
|
54
|
+
options[:autocompleteBias] ||= options.delete(:autocomplete_bias) || options.delete(:bias)
|
55
|
+
|
56
|
+
if options[:ll].kind_of? Hash
|
57
|
+
options[:ll][:lng] = options[:ll][:lon] if options[:ll][:lon]
|
58
|
+
end
|
59
|
+
|
60
|
+
if options[:bounds].kind_of? Hash
|
61
|
+
options[:bounds][:ne_lng] = options[:bounds][:ne_lon] if options[:bounds] and options[:bounds][:ne_lon]
|
62
|
+
options[:bounds][:sw_lng] = options[:bounds][:sw_lon] if options[:bounds] and options[:bounds][:sw_lon]
|
63
|
+
end
|
64
|
+
|
65
|
+
options
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/twofishes/version.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twofishes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.1.0.pre.rc.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Felder
|
8
8
|
- Miha Rekar
|
9
9
|
- Bartek Bułat
|
10
|
+
- Sebastian Delmont
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2015-
|
14
|
+
date: 2015-07-19 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: activesupport
|
@@ -151,6 +152,7 @@ files:
|
|
151
152
|
- lib/twofishes/client.rb
|
152
153
|
- lib/twofishes/configuration.rb
|
153
154
|
- lib/twofishes/errors.rb
|
155
|
+
- lib/twofishes/geocode_request.rb
|
154
156
|
- lib/twofishes/result.rb
|
155
157
|
- lib/twofishes/underscored.rb
|
156
158
|
- lib/twofishes/version.rb
|
@@ -169,9 +171,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
169
171
|
version: '2.0'
|
170
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
173
|
requirements:
|
172
|
-
- - '
|
174
|
+
- - '>'
|
173
175
|
- !ruby/object:Gem::Version
|
174
|
-
version:
|
176
|
+
version: 1.3.1
|
175
177
|
requirements: []
|
176
178
|
rubyforge_project:
|
177
179
|
rubygems_version: 2.4.5
|