naver_map 0.2.2 → 0.2.3
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/.gitignore +6 -0
- data/CHANGELOG.md +13 -10
- data/Gemfile.lock +1 -1
- data/lib/invalid_keys_error.rb +11 -0
- data/lib/naver_map/version.rb +1 -1
- data/lib/naver_map.rb +25 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afdfc7a5a1c1dbd88bda59862f7afb7c25724087
|
4
|
+
data.tar.gz: 7503892882aecec83cc212212473b755393bea83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caee5dc6fd52514ee2e8d00429440c8f3585756376e304c4997901099d5324d32dfe8ef7540a252302db3b021cc93f83a6a93b3d8dde34f48f766cdf5a17f12a
|
7
|
+
data.tar.gz: 0273f0d9089a467644fc4b7508fdff5cde17d704df18039e508bb42184b23ebbf882f1b8ff8413a4203d076145c4c9d5549e17bdc297fec594563aadd96a6d64
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,17 @@
|
|
1
|
-
* 0.
|
2
|
-
*
|
3
|
-
|
4
|
-
*
|
5
|
-
* gemspec
|
1
|
+
* 0.2.3
|
2
|
+
* invalid key에 대한 에러 메시지 추가
|
3
|
+
* 0.2.2
|
4
|
+
* 결과값이 1개일시 array로 반환 안함
|
5
|
+
* gemspec dependency warning 해결
|
6
|
+
* 0.2.1
|
7
|
+
* dependency 정리
|
8
|
+
* travis 코드 정리
|
6
9
|
* 0.2.0
|
7
10
|
* travis 연동 및 minitest로 TDD 구현
|
8
11
|
* 좌표를 주소로 변환 시켜주는 기능 추가
|
9
12
|
* 소스 리펙토링
|
10
|
-
* 0.
|
11
|
-
*
|
12
|
-
|
13
|
-
*
|
14
|
-
*
|
13
|
+
* 0.1.1
|
14
|
+
* gemspec에 누락된 홈페이지 정보 추가
|
15
|
+
* 0.1.0
|
16
|
+
* 첫 버전
|
17
|
+
* 주소를 좌표로 변환 시켜주는 기능 추가
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
class InvalidKeysError < StandardError
|
2
|
+
def initialize(client_id, client_secret)
|
3
|
+
message = """
|
4
|
+
Wrong API keys
|
5
|
+
Given Client ID: #{client_id} (Must be 20 characters of String)
|
6
|
+
Given Client Secret: #{client_secret} (Must be 10 characters of String)
|
7
|
+
"""
|
8
|
+
|
9
|
+
puts message
|
10
|
+
end
|
11
|
+
end
|
data/lib/naver_map/version.rb
CHANGED
data/lib/naver_map.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
require 'naver_map/version'
|
2
1
|
require 'rest-client'
|
3
2
|
require 'json'
|
3
|
+
require_relative './naver_map/version'
|
4
|
+
require_relative './invalid_keys_error'
|
4
5
|
|
5
6
|
class NaverMap
|
6
7
|
attr_reader :client_id, :client_secret
|
@@ -11,6 +12,8 @@ class NaverMap
|
|
11
12
|
def initialize(client_id, client_secret)
|
12
13
|
@client_id = client_id
|
13
14
|
@client_secret = client_secret
|
15
|
+
|
16
|
+
validate!
|
14
17
|
end
|
15
18
|
|
16
19
|
def address_to_coordinates(address)
|
@@ -29,6 +32,15 @@ class NaverMap
|
|
29
32
|
|
30
33
|
private
|
31
34
|
|
35
|
+
def validate!
|
36
|
+
raise InvalidKeysError.new(client_id, client_secret) unless valid_keys?
|
37
|
+
end
|
38
|
+
|
39
|
+
def valid_keys?
|
40
|
+
client_id.is_a?(String) && client_id.length == 20 &&
|
41
|
+
client_secret.is_a?(String) && client_secret.length == 10
|
42
|
+
end
|
43
|
+
|
32
44
|
def request_to_naver(url, *params)
|
33
45
|
RestClient.get(url, params: { query: params.join(',') },
|
34
46
|
'X-Naver-Client-Id': client_id,
|
@@ -38,17 +50,23 @@ class NaverMap
|
|
38
50
|
def query(url, *params)
|
39
51
|
request_to_naver(url, params)
|
40
52
|
rescue RestClient::ExceptionWithResponse => err
|
41
|
-
err.response
|
53
|
+
err.response
|
42
54
|
end
|
43
55
|
|
44
|
-
def
|
45
|
-
JSON.parse(body, symbolize_names: true)
|
56
|
+
def render_json(body)
|
57
|
+
JSON.parse(body, symbolize_names: true)
|
46
58
|
end
|
47
59
|
|
48
60
|
def extract_result(content, result_type)
|
49
|
-
|
61
|
+
result_json = render_json(content)
|
62
|
+
|
63
|
+
if result_json[:result]
|
64
|
+
result_items = result_json[:result][:items]
|
50
65
|
|
51
|
-
|
52
|
-
|
66
|
+
return result_items.first[result_type] unless result_items.size > 1
|
67
|
+
result_items.map { |item| item[result_type] }
|
68
|
+
else
|
69
|
+
result_json
|
70
|
+
end
|
53
71
|
end
|
54
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: naver_map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Penguin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- Rakefile
|
107
107
|
- bin/console
|
108
108
|
- bin/setup
|
109
|
+
- lib/invalid_keys_error.rb
|
109
110
|
- lib/naver_map.rb
|
110
111
|
- lib/naver_map/version.rb
|
111
112
|
- naver_map.gemspec
|