geocoder-olleh 0.1.5 → 0.1.6
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.
- checksums.yaml +4 -4
- data/lib/geocoder/olleh/lookups/olleh.rb +67 -42
- data/lib/geocoder/olleh/results/olleh.rb +81 -10
- data/lib/geocoder/olleh/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bff207aab53ada46cdd496289ced480643fe8cc
|
4
|
+
data.tar.gz: 77cc01c199ef17debc4f4eb0b40e2f09a92eded0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d07fb1b4ccee97e4d86ec72ad09793718bf1526542192abe0c913cf24679986a2938b8f6bd0c8a9ac21225a14236f8a344cf43116576062b7603e1d15f5a947c
|
7
|
+
data.tar.gz: f3623860e2fa5ead550fb48d281c96e52891d79b28c20b464ccf2e8060b55aaad4848f3eaac52cd558b4a9bb0af8b1fc8dec0764674adbe941aa3f22b6d52a80
|
@@ -107,6 +107,22 @@ module Geocoder::Lookup
|
|
107
107
|
token
|
108
108
|
end
|
109
109
|
|
110
|
+
def self.check_query_type(query)
|
111
|
+
if !query.options.empty? && query.options.include?(:priority)
|
112
|
+
query.options[:query_type] || query.options[:query_type] = "route_search"
|
113
|
+
elsif query.reverse_geocode? && query.options.include?(:include_jibun)
|
114
|
+
query.options[:query_type] || query.options[:query_type] = "reverse_geocoding"
|
115
|
+
elsif !query.options.empty? && query.options.include?(:coord_in)
|
116
|
+
query.options[:query_type] || query.options[:query_type] = "convert_coord"
|
117
|
+
elsif !query.options.empty? && query.options.include?(:l_code)
|
118
|
+
query.options[:query_type] || query.options[:query_type] = "addr_step_search"
|
119
|
+
elsif !query.options.empty? && query.options.include?(:radius)
|
120
|
+
query.options[:query_type] || query.options[:query_type] = "addr_nearest_position_search"
|
121
|
+
else
|
122
|
+
query.options[:query_type] || query.options[:query_type] = "geocoding"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
110
126
|
|
111
127
|
private # ----------------------------------------------
|
112
128
|
|
@@ -115,22 +131,24 @@ module Geocoder::Lookup
|
|
115
131
|
data = fetch_data(query)
|
116
132
|
return [] unless data
|
117
133
|
doc = JSON.parse(URI.decode(data["payload"]))
|
118
|
-
if doc['ERRCD'] != 0
|
119
|
-
Geocoder.log(:warn, "Olleh API error: #{doc['ERRCD']} (#{doc['ERRMS']
|
134
|
+
if doc['ERRCD'] != nil && doc['ERRCD'] != 0
|
135
|
+
Geocoder.log(:warn, "Olleh API error: #{doc['ERRCD']} (#{doc['ERRMS'] if doc['ERRMS']}).")
|
120
136
|
return []
|
121
137
|
end
|
122
|
-
|
123
|
-
|
138
|
+
|
139
|
+
case Olleh.check_query_type(query)
|
140
|
+
when "geocoding" || "reverse_geocoding"
|
124
141
|
return [] if doc['RESDATA']['COUNT'] == 0
|
125
142
|
return doc['RESDATA']["ADDRS"]
|
126
|
-
|
127
|
-
|
128
|
-
return
|
129
|
-
|
130
|
-
# CONVERT COORDINATES
|
131
|
-
elsif doc['RESDATA']['COORD'] && doc['RESDATA']['COORD']['COORDTYPE']
|
132
|
-
return [] if doc['RESDATA']['COORD']['X'] == ''
|
143
|
+
when "route_search"
|
144
|
+
return [] if doc["RESDATA"]["SROUTE"]["isRoute"] == "false"
|
145
|
+
return doc["RESDATA"]
|
146
|
+
when "convert_coord"
|
133
147
|
return doc['RESDATA']
|
148
|
+
when "addr_step_search"
|
149
|
+
return doc['RESULTDATA']
|
150
|
+
when "addr_nearest_position_search"
|
151
|
+
return doc['RESULTDATA']
|
134
152
|
else
|
135
153
|
[]
|
136
154
|
end
|
@@ -140,34 +158,25 @@ module Geocoder::Lookup
|
|
140
158
|
timeout(configuration.timeout) do
|
141
159
|
uri = URI.parse(query_url(query))
|
142
160
|
Geocoder.log(:debug, "Geocoder: HTTP request being made for #{uri.to_s}")
|
143
|
-
http_client.start(uri.host, uri.port, use_ssl
|
161
|
+
http_client.start(uri.host, uri.port, :use_ssl => true) do |client|
|
144
162
|
req = Net::HTTP::Get.new(uri.request_uri, configuration.http_headers)
|
145
|
-
|
146
163
|
client.request(req)
|
147
164
|
end
|
148
165
|
end
|
149
166
|
end
|
150
167
|
|
151
|
-
def token
|
152
|
-
if a = configuration.api_key
|
153
|
-
if a.is_a?(Array)
|
154
|
-
return Base64.encode64("#{a.first}:#{a.last}").strip
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
def now
|
160
|
-
Time.now.strftime("%Y%m%d%H%M%S%L")
|
161
|
-
end
|
162
|
-
|
163
168
|
def base_url(query)
|
164
|
-
case check_query_type(query)
|
169
|
+
case Olleh.check_query_type(query)
|
165
170
|
when "route_search"
|
166
171
|
"https://openapi.kt.com/maps/etc/RouteSearch?params="
|
167
172
|
when "reverse_geocoding"
|
168
173
|
"https://openapi.kt.com/maps/geocode/GetAddrByGeocode?params="
|
169
174
|
when "convert_coord"
|
170
175
|
"https://openapi.kt.com/maps/etc/ConvertCoord?params="
|
176
|
+
when "addr_step_search"
|
177
|
+
"https://openapi.kt.com/maps/search/AddrStepSearch?params="
|
178
|
+
when "addr_nearest_position_search"
|
179
|
+
"https://openapi.kt.com/maps/search/AddrNearestPosSearch?params="
|
171
180
|
else
|
172
181
|
"https://openapi.kt.com/maps/geocode/GetGeocodeByAddr?params="
|
173
182
|
end
|
@@ -175,7 +184,7 @@ module Geocoder::Lookup
|
|
175
184
|
|
176
185
|
|
177
186
|
def query_url_params(query)
|
178
|
-
case check_query_type(query)
|
187
|
+
case Olleh.check_query_type(query)
|
179
188
|
when "route_search"
|
180
189
|
JSON.generate({
|
181
190
|
SX: query.options[:start_x],
|
@@ -197,8 +206,8 @@ module Geocoder::Lookup
|
|
197
206
|
JSON.generate({
|
198
207
|
x: query.text.first,
|
199
208
|
y: query.text.last,
|
200
|
-
inCoordType:
|
201
|
-
outCoordType:
|
209
|
+
inCoordType: Olleh.coord_types[query.options[:coord_in]],
|
210
|
+
outCoordType: Olleh.coord_types[query.options[:coord_out]],
|
202
211
|
timestamp: now
|
203
212
|
})
|
204
213
|
when "reverse_geocoding"
|
@@ -210,6 +219,18 @@ module Geocoder::Lookup
|
|
210
219
|
isJibun: Olleh.include_jibun[query.options[:include_jibun]] || 0,
|
211
220
|
timestamp: now
|
212
221
|
})
|
222
|
+
when "addr_step_search"
|
223
|
+
JSON.generate({
|
224
|
+
l_Code: query.options[:l_code],
|
225
|
+
timestamp: now
|
226
|
+
})
|
227
|
+
when "addr_nearest_position_search"
|
228
|
+
JSON.generate({
|
229
|
+
px: query.options[:px],
|
230
|
+
py: query.options[:py],
|
231
|
+
radius: query.options[:radius],
|
232
|
+
timestamp: now
|
233
|
+
})
|
213
234
|
else # geocoding
|
214
235
|
JSON.generate({
|
215
236
|
addr: URI.encode(query.sanitized_text),
|
@@ -219,25 +240,29 @@ module Geocoder::Lookup
|
|
219
240
|
end
|
220
241
|
end
|
221
242
|
|
243
|
+
def token
|
244
|
+
if a = configuration.api_key
|
245
|
+
if a.is_a?(Array)
|
246
|
+
return Base64.encode64("#{a.first}:#{a.last}").strip
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def now
|
252
|
+
Time.now.strftime("%Y%m%d%H%M%S%L")
|
253
|
+
end
|
254
|
+
|
222
255
|
def url_query_string(query)
|
223
256
|
URI.encode(
|
224
257
|
query_url_params(query)
|
225
258
|
).gsub(':','%3A').gsub(',','%2C').gsub('https%3A', 'https:')
|
226
259
|
end
|
227
260
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
elsif !query.options.empty? && query.options.include?(:coord_in)
|
234
|
-
"convert_coord"
|
235
|
-
else
|
236
|
-
"geocoding"
|
237
|
-
end
|
261
|
+
##
|
262
|
+
# Need to delete timestamp from cache_key to hit cache
|
263
|
+
#
|
264
|
+
def cache_key(query)
|
265
|
+
Geocoder.config[:cache_prefix] + query_url(query).split('timestamp')[0]
|
238
266
|
end
|
239
|
-
|
240
|
-
|
241
|
-
|
242
267
|
end
|
243
268
|
end
|
@@ -1,11 +1,8 @@
|
|
1
|
-
require 'geocoder'
|
2
|
-
require_relative "../../olleh"
|
1
|
+
require 'geocoder/results/base'
|
3
2
|
|
4
3
|
module Geocoder::Result
|
5
4
|
class Olleh < Base
|
6
5
|
|
7
|
-
# NEED TO CHECK COORD SYSTEM
|
8
|
-
#
|
9
6
|
def latitude
|
10
7
|
coordinates[0].to_f
|
11
8
|
end
|
@@ -56,6 +53,22 @@ module Geocoder::Result
|
|
56
53
|
[@data['X'], @data['Y']]
|
57
54
|
end
|
58
55
|
|
56
|
+
#########
|
57
|
+
# methods for returning wgs coordiates from
|
58
|
+
#
|
59
|
+
def wgs_coordinates
|
60
|
+
return @data["WGS_COORDINATES"] if @data["WGS_COORDINATES"]
|
61
|
+
query = Geocoder::Query.new(
|
62
|
+
coordinates, {
|
63
|
+
coord_in: 'utmk',
|
64
|
+
coord_out: 'wgs84'
|
65
|
+
})
|
66
|
+
lookup = Geocoder::Lookup::Olleh.new
|
67
|
+
wgs = lookup.search(query).first.converted_coord
|
68
|
+
@data["WGS_COORDINATES"] = wgs
|
69
|
+
wgs
|
70
|
+
end
|
71
|
+
|
59
72
|
def address_data
|
60
73
|
@data['ADDRESS']
|
61
74
|
end
|
@@ -64,18 +77,22 @@ module Geocoder::Result
|
|
64
77
|
%w[bbox name confidence entityType]
|
65
78
|
end
|
66
79
|
|
67
|
-
|
68
|
-
#
|
69
|
-
|
80
|
+
##
|
81
|
+
# methods for converting coord system
|
82
|
+
#
|
83
|
+
def coord_type
|
70
84
|
@data[1]['COORDTYPE']
|
71
85
|
end
|
72
86
|
|
73
|
-
def
|
74
|
-
[@data[1][
|
87
|
+
def converted_coord
|
88
|
+
[@data[1]["X"], @data[1]["Y"]]
|
75
89
|
end
|
76
90
|
|
77
|
-
|
91
|
+
##
|
78
92
|
# methods for route search results
|
93
|
+
# total_time : minutes
|
94
|
+
# total_dist : meter
|
95
|
+
#
|
79
96
|
def total_time
|
80
97
|
@data[1]['ROUTE']['total_time']
|
81
98
|
end
|
@@ -92,6 +109,60 @@ module Geocoder::Result
|
|
92
109
|
@data[1]['ROUTE']['rg']
|
93
110
|
end
|
94
111
|
|
112
|
+
##
|
113
|
+
# methods for converting coord system
|
114
|
+
#
|
115
|
+
def coord_type
|
116
|
+
@data[1]['COORDTYPE']
|
117
|
+
end
|
118
|
+
|
119
|
+
def converted_coord
|
120
|
+
[@data[1]["X"], @data[1]["Y"]]
|
121
|
+
end
|
122
|
+
|
123
|
+
##
|
124
|
+
# methods for parsing adress step search
|
125
|
+
#
|
126
|
+
# 법정동 - 시도
|
127
|
+
def addr_step_sido
|
128
|
+
@data["SIDO"]
|
129
|
+
end
|
130
|
+
|
131
|
+
##
|
132
|
+
# 법정동 - 시군구
|
133
|
+
def addr_step_sigungu
|
134
|
+
@data["SIGUNGU"].gsub("+"," ")
|
135
|
+
end
|
136
|
+
|
137
|
+
def addr_step_dong
|
138
|
+
@data["DONG"]
|
139
|
+
end
|
140
|
+
|
141
|
+
def addr_step_li
|
142
|
+
@data["LI"]
|
143
|
+
end
|
144
|
+
##
|
145
|
+
# 법정동코드
|
146
|
+
def addr_step_l_code
|
147
|
+
@data["L_CODE"]
|
148
|
+
end
|
149
|
+
##
|
150
|
+
# 행정동코드
|
151
|
+
def addr_step_h_code
|
152
|
+
@data["H_CODE"]
|
153
|
+
end
|
154
|
+
##
|
155
|
+
# 파란코드
|
156
|
+
def addr_step_p_code
|
157
|
+
@data["P_CODE"]
|
158
|
+
end
|
159
|
+
|
160
|
+
##
|
161
|
+
# methods for parsing nearest position search
|
162
|
+
#
|
163
|
+
def position_address
|
164
|
+
"#{@data['SIDO']} #{@data['L_SIGUN_GU']} #{@data['L_DONG']} #{@data['GIBUN']}"
|
165
|
+
end
|
95
166
|
|
96
167
|
response_attributes.each do |a|
|
97
168
|
define_method a do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geocoder-olleh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jaigouk Kim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|