naver-sdk 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -2
- data/README.md +5 -6
- data/Rakefile +1 -1
- data/lib/naver/client.rb +2 -2
- data/lib/naver/configration.rb +30 -0
- data/lib/naver/connection.rb +6 -11
- data/lib/naver/core_ext/hash/keys.rb +116 -0
- data/lib/naver/map.rb +9 -2
- data/lib/naver/oauth.rb +6 -11
- data/lib/naver/papago.rb +2 -2
- data/lib/naver/sdk.rb +3 -6
- data/lib/naver/sdk/version.rb +1 -1
- data/lib/naver/search.rb +1 -1
- data/lib/naver/vision.rb +2 -2
- data/naver-sdk.gemspec +3 -1
- metadata +5 -5
- data/lib/naver/config.rb +0 -24
- data/lib/naver/ext/hash/to_underscore_keys.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d16fe3d0b77daf05e8f77f8e5caa2d42aac547e5
|
4
|
+
data.tar.gz: ccb0b9772ebf335765d967f0f5caf81e0dd52a4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3380b8d54040b9838c56551fe04a1fc38237a1e6d16903fecec117ba3264c03a98d44b930c89401a2d9b2dfd4dcb28456ac32ecb324e9951e61259eaa7620ea4
|
7
|
+
data.tar.gz: 398dfd1d1342c8072fc2d39d223095cb5cd6d3496fbc0ce37e38549ddd17010660d44d1db0c1e65445d7580b2455ba0ecd5ef6ff16461d03fe94b58f158e2251
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,10 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
4
|
## [unreleased]
|
5
|
-
|
5
|
+
|
6
|
+
## [0.5.0] - 2017-07-09
|
7
|
+
- improve configration
|
8
|
+
- core_ext/hash/keys
|
6
9
|
|
7
10
|
## [0.4.0] - 2017-06-26
|
8
11
|
- [breaking] JSON 출력 결과를 CamelCase 에서 underscore 변경
|
@@ -28,4 +31,5 @@ All notable changes to this project will be documented in this file.
|
|
28
31
|
[0.2.0]: https://github.com/kimsuelim/naver-sdk-ruby/compare/v0.1.0...v0.2.0
|
29
32
|
[0.3.0]: https://github.com/kimsuelim/naver-sdk-ruby/compare/v0.2.0...v0.3.0
|
30
33
|
[0.4.0]: https://github.com/kimsuelim/naver-sdk-ruby/compare/v0.3.0...v0.4.0
|
31
|
-
[
|
34
|
+
[0.5.0]: https://github.com/kimsuelim/naver-sdk-ruby/compare/v0.4.0...v0.5.0
|
35
|
+
[unreleased]: https://github.com/kimsuelim/naver-sdk-ruby/compare/v0.5.0...HEAD
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# NAVER SDK for Ruby
|
1
|
+
# 네이버 루비 SDK (NAVER SDK for Ruby)
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/kimsuelim/naver-sdk-ruby.svg?branch=master)](https://travis-ci.org/kimsuelim/naver-sdk-ruby)
|
4
4
|
[![Coverage Status](https://coveralls.io/repos/github/kimsuelim/naver-sdk-ruby/badge.svg?branch=master)](https://coveralls.io/github/kimsuelim/naver-sdk-ruby?branch=master)
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/naver-sdk.svg)](https://badge.fury.io/rb/naver-sdk)
|
6
6
|
|
7
|
-
A ruby client for the NAVER API
|
7
|
+
네이버 오픈API 루비 클라이언트 (A ruby client for the NAVER API)
|
8
8
|
|
9
9
|
## Links of Interest
|
10
10
|
|
@@ -145,15 +145,15 @@ puts response.items[0].name
|
|
145
145
|
response = Naver::Papago.translate(
|
146
146
|
source: "ko",
|
147
147
|
target: "en",
|
148
|
-
text: "
|
148
|
+
text: "기술은 사람을 대체하는 것이 아니라 기술의 도움으로 사람을 더 창조적으로 만들 것이라 믿는다."
|
149
149
|
)
|
150
150
|
# => #<Naver::ObjectifiedHash:70362563050680 {hash: {
|
151
|
-
"translated_text"=>"
|
151
|
+
"translated_text"=>"It is to replace the technology is more creative with the help of technology, not believe that it would make."
|
152
152
|
}
|
153
153
|
}
|
154
154
|
|
155
155
|
puts response.translated_text
|
156
|
-
# => "
|
156
|
+
# => "It is to replace the technology is more creative with the help of technology, not believe that it would make."
|
157
157
|
```
|
158
158
|
|
159
159
|
## 지도
|
@@ -162,7 +162,6 @@ puts response.translated_text
|
|
162
162
|
|
163
163
|
```ruby
|
164
164
|
response = Naver::Map.geocode(query: "불정로 6")
|
165
|
-
# => <Naver::ObjectifiedHash:70145842773600 {hash: {:total=>1, :userquery=>"불정로 6", :items=>[{:address=>"경기도 성남시 분당구 불정로 6 NAVER그린팩토리", :addrdetail=>{:country=>"대한민국", :sido=>"경기도", :sigugun=>"성남시 분당구", :dongmyun=>"불정로", :rest=>" 6 NAVER그린팩토리"}, :is_road_address=>true, :point=>{:x=>127.1052133, :y=>37.3595316}}]}}
|
166
165
|
# => [#<Naver::ObjectifiedHash:70284981985920 {hash: {
|
167
166
|
"address"=>"경기도 성남시 분당구 불정로 6 NAVER그린팩토리",
|
168
167
|
"addrdetail"=>{"country"=>"대한민국", "sido"=>"경기도", "sigugun"=>"성남시 분당구", "dongmyun"=>"불정로", "rest"=>" 6 NAVER그린팩토리"},
|
data/Rakefile
CHANGED
data/lib/naver/client.rb
CHANGED
@@ -10,10 +10,10 @@ module Naver # :nodoc:
|
|
10
10
|
# Converts the response body to an ObjectifiedHash.
|
11
11
|
def self.parse(body)
|
12
12
|
if body.is_a?(Hash)
|
13
|
-
body = body.
|
13
|
+
body = body.deep_underscore_keys
|
14
14
|
ObjectifiedHash.new(body)
|
15
15
|
elsif body.is_a?(Array)
|
16
|
-
body = body.
|
16
|
+
body = body.deep_underscore_keys
|
17
17
|
body.collect! { |e| ObjectifiedHash.new(e) }
|
18
18
|
elsif body
|
19
19
|
true
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Naver
|
2
|
+
# Defines constants and methods related to configuration.
|
3
|
+
module Configration
|
4
|
+
# An array of valid keys in the options hash when configuring a Naver::Client.
|
5
|
+
OPTION_KEYS = [:client_id, :client_secret, :redirect_uri, :timeout, :debug].freeze
|
6
|
+
|
7
|
+
# The user agent that will be sent to the API endpoint if none is set.
|
8
|
+
DEFAULT_USER_AGENT = "NAVER Ruby SDK Gem #{Naver::Sdk::VERSION}".freeze
|
9
|
+
|
10
|
+
# Base URI for the NAVER API.
|
11
|
+
DEFAULT_API_BASE_URI = "https://openapi.naver.com".freeze
|
12
|
+
|
13
|
+
# Base URI for NAVER OAuth.
|
14
|
+
DEFAULT_OAUTH_BASE_URI = "https://nid.naver.com".freeze
|
15
|
+
|
16
|
+
attr_accessor *OPTION_KEYS
|
17
|
+
|
18
|
+
# Convenience method to allow configuration options to be set in a block.
|
19
|
+
def configure
|
20
|
+
yield(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Creates a hash of options and their values.
|
24
|
+
def options
|
25
|
+
options = {}
|
26
|
+
OPTION_KEYS.each { |key| options[key] = send(key) }
|
27
|
+
options
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/naver/connection.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
module Naver
|
2
2
|
class Connection
|
3
|
-
# Base URI for the NAVER API..
|
4
|
-
DEFAULT_API_BASE_URI = "https://openapi.naver.com"
|
5
|
-
|
6
3
|
# Create a Connection object.
|
7
|
-
|
8
|
-
def initialize(api_base_uri: DEFAULT_API_BASE_URI)
|
4
|
+
def initialize
|
9
5
|
@client_id = Naver.client_id
|
10
6
|
@client_secret = Naver.client_secret
|
11
|
-
@api_base_uri =
|
12
|
-
|
13
|
-
|
14
|
-
@connection = Faraday.new(url: @api_base_uri, headers: headers) do |faraday|
|
7
|
+
@api_base_uri = Configration::DEFAULT_API_BASE_URI
|
8
|
+
@headers = { user_agent: Configration::DEFAULT_USER_AGENT }
|
9
|
+
@connection = Faraday.new(url: @api_base_uri, headers: @headers) do |faraday|
|
15
10
|
faraday.request :multipart
|
16
11
|
faraday.request :url_encoded
|
17
12
|
faraday.response :logger if Naver.debug
|
@@ -50,14 +45,14 @@ module Naver
|
|
50
45
|
private
|
51
46
|
|
52
47
|
def request(verb, path, params = {})
|
53
|
-
raise ArgumentError.new "Invalid http verb #{verb}"
|
48
|
+
raise ArgumentError.new "Invalid http verb #{verb}" unless [:get, :post, :put, :delete].include?(verb)
|
54
49
|
|
55
50
|
response = @connection.run_request(verb, path, params, public_auth_header) do |request|
|
56
51
|
request.params.update(params) if verb == :get && params
|
57
52
|
yield(request) if block_given?
|
58
53
|
end
|
59
54
|
|
60
|
-
|
55
|
+
unless (200..299).include?(response.status)
|
61
56
|
body = JSON.parse(response.body)
|
62
57
|
raise Naver::Error.new(body)
|
63
58
|
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
class Hash
|
2
|
+
# Returns a new hash with all keys converted to underscore strings.
|
3
|
+
#
|
4
|
+
# hash = { firstName: "Rob", lastName: "Bob" }
|
5
|
+
#
|
6
|
+
# hash.underscore_keys
|
7
|
+
# # => {:first_name=>"Rob", :last_name=>"Bob"}
|
8
|
+
def underscore_keys
|
9
|
+
transform_keys { |key| underscore_key(key) }
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns a new hash with all keys converted to camelcase strings.
|
13
|
+
#
|
14
|
+
# hash = { first_name: "Rob", last_name: "Bob" }
|
15
|
+
#
|
16
|
+
# hash.camelize_keys
|
17
|
+
# # => {:firstName=>"Rob", :lastName=>"Bob"}
|
18
|
+
def camelize_keys
|
19
|
+
transform_keys { |key| camelize_key(key) }
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns a new hash with all keys converted to underscore strings.
|
23
|
+
# This includes the keys from the root hash and from all
|
24
|
+
# nested hashes and arrays.
|
25
|
+
#
|
26
|
+
# hash = { person: { firstName: "Rob", lastName: "Bob" } }
|
27
|
+
#
|
28
|
+
# hash.deep_underscore_keys
|
29
|
+
# # => {:person=>{:first_name=>"Rob", :last_name=>"Bob"}}
|
30
|
+
def deep_underscore_keys
|
31
|
+
deep_transform_keys_in_object(self) { |key| underscore_key(key) }
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns a new hash with all keys converted to camelcase strings.
|
35
|
+
# This includes the keys from the root hash and from all
|
36
|
+
# nested hashes and arrays.
|
37
|
+
#
|
38
|
+
# hash = { person: { first_name: "Rob", last_name: "Bob" } }
|
39
|
+
#
|
40
|
+
# hash.deep_camelize_keys
|
41
|
+
# # => {:person=>{:firstName=>"Rob", :lastName=>"Bob"}}
|
42
|
+
def deep_camelize_keys
|
43
|
+
deep_transform_keys_in_object(self) { |key| camelize_key(key) }
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Returns a new hash with all keys converted using the +block+ operation.
|
49
|
+
def transform_keys
|
50
|
+
return enum_for(:transform_keys) { size } unless block_given?
|
51
|
+
result = {}
|
52
|
+
each_key do |key|
|
53
|
+
result[yield(key)] = self[key]
|
54
|
+
end
|
55
|
+
result
|
56
|
+
end
|
57
|
+
|
58
|
+
# support methods for deep transforming nested hashes and arrays
|
59
|
+
def deep_transform_keys_in_object(object, &block)
|
60
|
+
case object
|
61
|
+
when Array
|
62
|
+
object.map { |e| deep_transform_keys_in_object(e, &block) }
|
63
|
+
when Hash
|
64
|
+
object.each_with_object({}) do |(key, value), result|
|
65
|
+
result[yield(key)] = deep_transform_keys_in_object(value, &block)
|
66
|
+
end
|
67
|
+
# Hash[object.map { |key, value| [yield(key), deep_transform_keys_in_object(value, &block)] }]
|
68
|
+
else
|
69
|
+
object
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def underscore_key(key)
|
74
|
+
if key.is_a?(Symbol)
|
75
|
+
underscore(key.to_s).to_sym
|
76
|
+
elsif key.is_a?(String)
|
77
|
+
underscore(key)
|
78
|
+
else
|
79
|
+
key
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def underscore(camel_cased_word)
|
84
|
+
return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/
|
85
|
+
word = camel_cased_word.to_s.gsub("::".freeze, "/".freeze)
|
86
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
|
87
|
+
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
|
88
|
+
word.tr!("-".freeze, "_".freeze)
|
89
|
+
word.downcase!
|
90
|
+
word
|
91
|
+
end
|
92
|
+
|
93
|
+
def camelize_key(key)
|
94
|
+
if key.is_a?(Symbol)
|
95
|
+
camelize(key.to_s, :lower).to_sym
|
96
|
+
elsif key.is_a?(String)
|
97
|
+
camelize(key, :lower)
|
98
|
+
else
|
99
|
+
key
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def camelize(underscore_word, first_letter = :upper)
|
104
|
+
word = underscore_word.to_s
|
105
|
+
case first_letter
|
106
|
+
when :upper
|
107
|
+
word = word.sub(/^[a-z\d]*/) { $&.capitalize }
|
108
|
+
when :lower
|
109
|
+
word = word.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
|
110
|
+
end
|
111
|
+
|
112
|
+
word.gsub!(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }
|
113
|
+
word.gsub!(/\//, "::".freeze)
|
114
|
+
word
|
115
|
+
end
|
116
|
+
end
|
data/lib/naver/map.rb
CHANGED
@@ -2,18 +2,25 @@ module Naver # :nodoc:
|
|
2
2
|
# Naver Map API
|
3
3
|
class Map < Client
|
4
4
|
class << self
|
5
|
-
#
|
5
|
+
# 주소를 좌표로 변환
|
6
6
|
# @param params [Hash] Params for the search
|
7
7
|
def geocode(params = {})
|
8
8
|
parse(JSON.parse(connection.get("/v1/map/geocode", params).body)["result"])
|
9
9
|
end
|
10
10
|
|
11
|
-
#
|
11
|
+
# 좌표를 주소로 변환
|
12
12
|
# @param params [Hash] Params for the search
|
13
13
|
def reverse_geocode(params = {})
|
14
14
|
params = { query: "#{params[:lat]}, #{params[:lng]}" }
|
15
15
|
parse(JSON.parse(connection.get("/v1/map/reversegeocode", params).body)["result"])
|
16
16
|
end
|
17
|
+
|
18
|
+
# StaticMap
|
19
|
+
# 지정된 좌표의 네이버 지도 이미지를 출력
|
20
|
+
# @param params [Hash] Params for the search
|
21
|
+
def static_map(params = {})
|
22
|
+
connection.get("/v1/map/staticmap.bin", params).body
|
23
|
+
end
|
17
24
|
end
|
18
25
|
end
|
19
26
|
end
|
data/lib/naver/oauth.rb
CHANGED
@@ -1,18 +1,14 @@
|
|
1
1
|
module Naver
|
2
2
|
class Oauth
|
3
|
-
#
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
# Create a Oauth object.
|
8
|
-
# @param oauth_base_uri [String] Base URI at which to make API calls.
|
9
|
-
def initialize(oauth_base_uri: DEFAULT_OAUTH_BASE_URI, redirect_uri: Naver.redirect_uri)
|
3
|
+
# Create a OAuth object.
|
4
|
+
# @param redirect_uri [String] OAuth redirect_uri
|
5
|
+
def initialize(redirect_uri: Naver.redirect_uri)
|
10
6
|
@client_id = Naver.client_id
|
11
7
|
@client_secret = Naver.client_secret
|
12
|
-
@oauth_base_uri =
|
8
|
+
@oauth_base_uri = Configration::DEFAULT_OAUTH_BASE_URI
|
13
9
|
@redirect_uri = redirect_uri
|
14
10
|
|
15
|
-
headers = { user_agent:
|
11
|
+
headers = { user_agent: Configration::DEFAULT_USER_AGENT }
|
16
12
|
@oauth = OAuth2::Client.new(@client_id, @client_secret, site: @oauth_base_uri, authorize_url: "/oauth2.0/authorize", token_url: "/oauth2.0/token", headers: headers) do |http|
|
17
13
|
http.request :multipart
|
18
14
|
http.request :url_encoded
|
@@ -60,9 +56,8 @@ module Naver
|
|
60
56
|
private
|
61
57
|
|
62
58
|
def refresh_token!
|
63
|
-
return
|
59
|
+
return unless @oauth_token.expired?
|
64
60
|
@oauth_token = @oauth_token.refresh_token
|
65
61
|
end
|
66
62
|
end
|
67
63
|
end
|
68
|
-
|
data/lib/naver/papago.rb
CHANGED
@@ -6,7 +6,7 @@ module Naver # :nodoc:
|
|
6
6
|
# @param source [String] 번역 소스 텍스트의 언어 설정: (ko:한국어, en:영어, ja:일본어, zh-CN:중국어(간체), zh-TW:중국어(번체)
|
7
7
|
# @param target [String] 번역 대상 언어, 가능한 값은 source 파라미터와 동일
|
8
8
|
# @param text [String] 번역할 문장이며 UTF-8만 지원
|
9
|
-
# @return [
|
9
|
+
# @return [ObjectifiedHash] 번역된 문장
|
10
10
|
def translate(source:, target:, text:)
|
11
11
|
params = method(__method__).parameters.map(&:last).map { |p| [p, eval(p.to_s)] }.to_h
|
12
12
|
parse(JSON.parse(connection.post("/v1/language/translate", params).body)["message"]["result"])
|
@@ -14,7 +14,7 @@ module Naver # :nodoc:
|
|
14
14
|
|
15
15
|
# 한글인명 - 로마자 변환
|
16
16
|
# @param query [String] 로마자로 바꾸려는 한글 이름
|
17
|
-
# @return [
|
17
|
+
# @return [ObjectifiedHash] 변환 결과
|
18
18
|
def romanization(query:)
|
19
19
|
params = { query: query }
|
20
20
|
result = JSON.parse(connection.get("/v1/krdict/romanization", params).body)["aResult"][0]
|
data/lib/naver/sdk.rb
CHANGED
@@ -2,8 +2,8 @@ require "oauth2"
|
|
2
2
|
require "faraday"
|
3
3
|
|
4
4
|
require "naver/sdk/version"
|
5
|
-
require "naver/
|
6
|
-
require "naver/
|
5
|
+
require "naver/core_ext/hash/keys"
|
6
|
+
require "naver/configration"
|
7
7
|
require "naver/connection"
|
8
8
|
require "naver/client"
|
9
9
|
require "naver/error"
|
@@ -20,8 +20,5 @@ require "naver/vision"
|
|
20
20
|
require "naver/voice"
|
21
21
|
|
22
22
|
module Naver
|
23
|
-
extend
|
24
|
-
|
25
|
-
module Sdk
|
26
|
-
end
|
23
|
+
extend Configration
|
27
24
|
end
|
data/lib/naver/sdk/version.rb
CHANGED
data/lib/naver/search.rb
CHANGED
@@ -11,7 +11,7 @@ module Naver # :nodoc:
|
|
11
11
|
# Search > News (검색 > 뉴스)
|
12
12
|
# @param params [Hash] Params for the search
|
13
13
|
def news(params = {})
|
14
|
-
|
14
|
+
parse(JSON.parse(connection.get("/v1/search/news", params).body))
|
15
15
|
end
|
16
16
|
|
17
17
|
# Search > Book (검색 > 책)
|
data/lib/naver/vision.rb
CHANGED
@@ -4,7 +4,7 @@ module Naver # :nodoc:
|
|
4
4
|
class << self
|
5
5
|
# 유명인 얼굴인식(Beta)
|
6
6
|
# @param image [Binary] 얼굴이 포함된 이미지 (최대 2MB)
|
7
|
-
# @return [
|
7
|
+
# @return [ObjectifiedHash] 인식결과
|
8
8
|
def celebrity(image:)
|
9
9
|
params = {}
|
10
10
|
params[:image] = Faraday::UploadIO.new(image, "image/jpeg")
|
@@ -13,7 +13,7 @@ module Naver # :nodoc:
|
|
13
13
|
|
14
14
|
# 얼굴 감지(Beta)
|
15
15
|
# @param image [Binary] 얼굴이 포함된 이미지 (최대 2MB)
|
16
|
-
# @return [
|
16
|
+
# @return [ObjectifiedHash] 인식결과
|
17
17
|
def face(image:)
|
18
18
|
params = {}
|
19
19
|
params[:image] = Faraday::UploadIO.new(image, "image/jpeg")
|
data/naver-sdk.gemspec
CHANGED
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
+
spec.required_ruby_version = ">= 2.2.2"
|
25
|
+
|
24
26
|
spec.add_dependency "faraday", [">= 0.8", "< 1.0"]
|
25
27
|
spec.add_dependency "oauth2", "~> 1.0"
|
26
28
|
|
@@ -28,5 +30,5 @@ Gem::Specification.new do |spec|
|
|
28
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
31
|
spec.add_development_dependency "minitest", "~> 5.0"
|
30
32
|
spec.add_development_dependency "rubocop", "~> 0.49.0"
|
31
|
-
spec.add_development_dependency "coveralls",
|
33
|
+
spec.add_development_dependency "coveralls", "~> 0.8.21"
|
32
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: naver-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Surim Kim
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -133,10 +133,10 @@ files:
|
|
133
133
|
- bin/console
|
134
134
|
- bin/setup
|
135
135
|
- lib/naver/client.rb
|
136
|
-
- lib/naver/
|
136
|
+
- lib/naver/configration.rb
|
137
137
|
- lib/naver/connection.rb
|
138
|
+
- lib/naver/core_ext/hash/keys.rb
|
138
139
|
- lib/naver/error.rb
|
139
|
-
- lib/naver/ext/hash/to_underscore_keys.rb
|
140
140
|
- lib/naver/map.rb
|
141
141
|
- lib/naver/oauth.rb
|
142
142
|
- lib/naver/objectified_hash.rb
|
@@ -162,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
162
|
requirements:
|
163
163
|
- - ">="
|
164
164
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
165
|
+
version: 2.2.2
|
166
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
167
|
requirements:
|
168
168
|
- - ">="
|
data/lib/naver/config.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module Naver
|
2
|
-
module Config
|
3
|
-
OPTION_KEYS = [
|
4
|
-
:client_id,
|
5
|
-
:client_secret,
|
6
|
-
:redirect_uri,
|
7
|
-
:timeout,
|
8
|
-
:debug
|
9
|
-
]
|
10
|
-
|
11
|
-
attr_accessor *OPTION_KEYS
|
12
|
-
|
13
|
-
def configure
|
14
|
-
yield self
|
15
|
-
self
|
16
|
-
end
|
17
|
-
|
18
|
-
def options
|
19
|
-
options = {}
|
20
|
-
OPTION_KEYS.each{ |key| options[key] = send(key) }
|
21
|
-
options
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# Hash.to_underscore_keys
|
2
|
-
class Hash
|
3
|
-
# Recursively converts CamelCase hash keys to underscore
|
4
|
-
def to_underscore_keys(value = self)
|
5
|
-
case value
|
6
|
-
when Array
|
7
|
-
value.map { |v| to_underscore_keys(v) }
|
8
|
-
when Hash
|
9
|
-
underscore_hash(value)
|
10
|
-
else
|
11
|
-
value
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def underscore_hash(value)
|
18
|
-
Hash[value.map { |k, v| [underscore_key(k), to_underscore_keys(v)] }]
|
19
|
-
end
|
20
|
-
|
21
|
-
def underscore_key(key)
|
22
|
-
if key.is_a?(Symbol)
|
23
|
-
underscore(key.to_s).to_sym
|
24
|
-
elsif key.is_a?(String)
|
25
|
-
underscore(key)
|
26
|
-
else
|
27
|
-
key # can't snakify anything except strings and symbols
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def underscore(camel_cased_word)
|
32
|
-
return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/
|
33
|
-
word = camel_cased_word.to_s.gsub("::".freeze, "/".freeze)
|
34
|
-
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
|
35
|
-
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
|
36
|
-
word.tr!("-".freeze, "_".freeze)
|
37
|
-
word.downcase!
|
38
|
-
word
|
39
|
-
end
|
40
|
-
end
|