easycodefrb 1.0.2
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 +7 -0
- data/LICENSE +21 -0
- data/lib/easycodefrb.rb +10 -0
- data/lib/easycodefrb/connector.rb +113 -0
- data/lib/easycodefrb/easycodef.rb +297 -0
- data/lib/easycodefrb/message.rb +39 -0
- data/lib/easycodefrb/properties.rb +45 -0
- data/lib/easycodefrb/response.rb +12 -0
- data/lib/easycodefrb/util.rb +24 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b266bb709932b66307dcd683b3054d72dbc28e7508cc17b6a04d5dc6a20a7477
|
4
|
+
data.tar.gz: a2d79e5e4d8312bdaa46daf1c64454deca5356cbfe15c361a97c7056c769f06e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f2493773bc3348682f7432c6424d8a654319960681eec78bda5fb129827540963710c6d4fe00c0d8940abfafb904aedb19d9b9b3494c4f6f8a8bd254f1b71be
|
7
|
+
data.tar.gz: e4eddeb0dcae91b6ff8e30a09f7fd0463c23531b5325650f66953f13a64455e0c9cd08f9f36a3adce3703febf808ee38c5a307dc5001b1679e9238ea520f0d98
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 CODEF Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/lib/easycodefrb.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require_relative './easycodefrb/connector'
|
2
|
+
require_relative './easycodefrb/easycodef'
|
3
|
+
require_relative './easycodefrb/properties'
|
4
|
+
require_relative './easycodefrb/response'
|
5
|
+
require_relative './easycodefrb/message'
|
6
|
+
require_relative './easycodefrb/util'
|
7
|
+
|
8
|
+
module EasyCodef
|
9
|
+
VERSION = '1.0.2'
|
10
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'cgi'
|
4
|
+
require 'json'
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
require_relative './response'
|
8
|
+
require_relative './message'
|
9
|
+
|
10
|
+
# 상품 요청
|
11
|
+
module Connector
|
12
|
+
module_function()
|
13
|
+
|
14
|
+
def request_product(req_url, token, body_str)
|
15
|
+
uri = URI.parse(req_url)
|
16
|
+
header = {
|
17
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
18
|
+
'Accept': 'application/json'
|
19
|
+
}
|
20
|
+
|
21
|
+
if token != '' && token != nil
|
22
|
+
header['Authorization'] = 'Bearer ' + token
|
23
|
+
end
|
24
|
+
|
25
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
26
|
+
http.use_ssl = true
|
27
|
+
req = Net::HTTP::Post.new(uri.request_uri, header)
|
28
|
+
req.body = body_str
|
29
|
+
|
30
|
+
res = http.request(req)
|
31
|
+
|
32
|
+
return case res
|
33
|
+
when Net::HTTPOK
|
34
|
+
data = CGI::unescape(res.body)
|
35
|
+
return JSON.parse(data)
|
36
|
+
when Net::HTTPBadRequest
|
37
|
+
new_response_message(Message::BAD_REQUEST)
|
38
|
+
when Net::HTTPUnauthorized
|
39
|
+
new_response_message(Message::UNAUTHORIZED)
|
40
|
+
when Net::HTTPForbidden
|
41
|
+
new_response_message(Message::FORBIDDEN)
|
42
|
+
when Net::HTTPNotFound
|
43
|
+
new_response_message(Message::NOT_FOUND)
|
44
|
+
else
|
45
|
+
new_response_message(Message::SERVER_ERROR)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# 엑세스 토큰 요청
|
50
|
+
def request_token(client_id, client_secret)
|
51
|
+
uri = URI.parse(EasyCodef::OAUTH_DOMAIN + EasyCodef::PATH_GET_TOKEN)
|
52
|
+
|
53
|
+
auth = client_id + ':' + client_secret
|
54
|
+
enc_auth = Base64.encode64(auth).gsub(/\n/, '')
|
55
|
+
|
56
|
+
header = {
|
57
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
58
|
+
'Authorization': 'Basic ' + enc_auth
|
59
|
+
}
|
60
|
+
|
61
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
62
|
+
http.use_ssl = true
|
63
|
+
req = Net::HTTP::Post.new(uri.request_uri, header)
|
64
|
+
req.body = 'grant_type=client_credentials&scope=read'
|
65
|
+
|
66
|
+
res = http.request(req)
|
67
|
+
|
68
|
+
return case res
|
69
|
+
when Net::HTTPOK
|
70
|
+
JSON.parse(res.body)
|
71
|
+
else
|
72
|
+
return nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# 토큰 셋팅
|
77
|
+
# Codef 인스턴스 변수에 조회된 access_token을 셋팅한다
|
78
|
+
def set_token(client_id, client_secret, access_token_cls, service_type)
|
79
|
+
repeat_cnt = 3
|
80
|
+
i = 0
|
81
|
+
if access_token_cls.get_token(service_type) == ''
|
82
|
+
while i < repeat_cnt
|
83
|
+
token_map = request_token(client_id, client_secret)
|
84
|
+
if token_map != nil
|
85
|
+
access_token = token_map[EasyCodef::KEY_ACCESS_TOKEN]
|
86
|
+
access_token_cls.set_token(access_token, service_type)
|
87
|
+
if access_token != nil && access_token != ''
|
88
|
+
break
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
sleep(0.020)
|
93
|
+
i += 1
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# API 요청 실행
|
99
|
+
def execute(url_path, body, access_token_cls, req_info, service_type)
|
100
|
+
set_token(
|
101
|
+
req_info.client_id,
|
102
|
+
req_info.client_secret,
|
103
|
+
access_token_cls,
|
104
|
+
service_type
|
105
|
+
)
|
106
|
+
enc_body = CGI::escape(body.to_json())
|
107
|
+
return request_product(
|
108
|
+
req_info.domain + url_path,
|
109
|
+
access_token_cls.get_token(service_type),
|
110
|
+
enc_body
|
111
|
+
)
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,297 @@
|
|
1
|
+
require_relative './message'
|
2
|
+
require_relative './connector'
|
3
|
+
|
4
|
+
module EasyCodef
|
5
|
+
# AccessToken 정보
|
6
|
+
class AccessToken
|
7
|
+
def initialize()
|
8
|
+
@product = ''
|
9
|
+
@demo = ''
|
10
|
+
@sandbox = ''
|
11
|
+
end
|
12
|
+
|
13
|
+
def set_token(token, service_type)
|
14
|
+
case service_type
|
15
|
+
when TYPE_PRODUCT
|
16
|
+
@product = token
|
17
|
+
when TYPE_DEMO
|
18
|
+
@demo = token
|
19
|
+
else
|
20
|
+
@sandbox = token
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_token(service_type)
|
25
|
+
return case service_type
|
26
|
+
when TYPE_PRODUCT
|
27
|
+
@product
|
28
|
+
when TYPE_DEMO
|
29
|
+
@demo
|
30
|
+
else
|
31
|
+
@sandbox
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# API 요청에 필요한 정보 클래스
|
37
|
+
# Codef 인스턴스에서 API 요청을 보낼때 서비스 타입별 필요한 정보를 가져와서 사용한다
|
38
|
+
# 이때 정보를 저장하는 역할을 한다
|
39
|
+
class RequestInfo
|
40
|
+
def initialize(domain, client_id, client_secret)
|
41
|
+
@domain = domain
|
42
|
+
@client_id = client_id
|
43
|
+
@client_secret = client_secret
|
44
|
+
end
|
45
|
+
|
46
|
+
def domain()
|
47
|
+
return @domain
|
48
|
+
end
|
49
|
+
|
50
|
+
def client_id()
|
51
|
+
return @client_id
|
52
|
+
end
|
53
|
+
|
54
|
+
def client_secret()
|
55
|
+
return @client_secret
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Codef 클래스
|
60
|
+
# 요청에 필요한 설정 값들을 가지고 있으며
|
61
|
+
# 유저의 요청 파라미터에 따라 실제 API를 요청하는 역할을 한다
|
62
|
+
class Codef
|
63
|
+
def initialize(public_key='')
|
64
|
+
@access_token = AccessToken.new()
|
65
|
+
@demo_client_id = ''
|
66
|
+
@demo_client_secret = ''
|
67
|
+
@client_id = ''
|
68
|
+
@client_secret = ''
|
69
|
+
@public_key = public_key
|
70
|
+
end
|
71
|
+
|
72
|
+
# 정식버전 클라이언트 정보 셋팅
|
73
|
+
def set_client_info(id, secret)
|
74
|
+
@client_id = id
|
75
|
+
@client_secret = secret
|
76
|
+
end
|
77
|
+
|
78
|
+
# 데모버전 클라이언트 정보 셋팅
|
79
|
+
def set_client_info_for_demo(id, secret)
|
80
|
+
@demo_client_id = id
|
81
|
+
@demo_client_secret = secret
|
82
|
+
end
|
83
|
+
|
84
|
+
def demo_client_id
|
85
|
+
return @demo_client_id
|
86
|
+
end
|
87
|
+
|
88
|
+
def demo_client_secret
|
89
|
+
return @demo_client_secret
|
90
|
+
end
|
91
|
+
|
92
|
+
def client_id
|
93
|
+
return @client_id
|
94
|
+
end
|
95
|
+
|
96
|
+
def client_secret
|
97
|
+
return @client_secret
|
98
|
+
end
|
99
|
+
|
100
|
+
def access_token
|
101
|
+
return @access_token
|
102
|
+
end
|
103
|
+
|
104
|
+
def public_key (public_key=nil)
|
105
|
+
@public_key = public_key if public_key
|
106
|
+
return @public_key
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
# 서비스 타입에 해당하는 요청 정보 객체 가져오기
|
111
|
+
def get_req_info_by_service_type(service_type)
|
112
|
+
return case service_type
|
113
|
+
when TYPE_PRODUCT
|
114
|
+
RequestInfo.new(
|
115
|
+
API_DOMAIN,
|
116
|
+
@client_id,
|
117
|
+
@client_secret
|
118
|
+
)
|
119
|
+
when TYPE_DEMO
|
120
|
+
RequestInfo.new(
|
121
|
+
DEMO_DOMAIN,
|
122
|
+
@demo_client_id,
|
123
|
+
@demo_client_secret
|
124
|
+
)
|
125
|
+
else
|
126
|
+
RequestInfo.new(
|
127
|
+
SANDBOX_DOMAIN,
|
128
|
+
SANDBOX_CLIENT_ID,
|
129
|
+
SANDBOX_CLIENT_SECRET
|
130
|
+
)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# API 요청
|
135
|
+
def request_product(product_path, service_type, param)
|
136
|
+
|
137
|
+
# 클라이언트 정보 검사
|
138
|
+
if !has_client_info(service_type)
|
139
|
+
res = new_response_message(Message::EMPTY_CLIENT_INFO)
|
140
|
+
return res.to_json()
|
141
|
+
end
|
142
|
+
|
143
|
+
# 퍼블릭키 검사
|
144
|
+
if @public_key == ''
|
145
|
+
res = new_response_message(Message::EMPTY_PUBLIC_KEY)
|
146
|
+
return res.to_json()
|
147
|
+
end
|
148
|
+
|
149
|
+
# 추가인증 키워드 비어있는지 체크
|
150
|
+
if !is_empty_two_way_keyword(param)
|
151
|
+
res = new_response_message(Message::INVALID_2WAY_KEYWORD)
|
152
|
+
return res.to_json()
|
153
|
+
end
|
154
|
+
|
155
|
+
# 리퀘스트 정보 조회
|
156
|
+
req_info = get_req_info_by_service_type(service_type)
|
157
|
+
|
158
|
+
# 요청
|
159
|
+
res = Connector.execute(
|
160
|
+
product_path,
|
161
|
+
param,
|
162
|
+
@access_token,
|
163
|
+
req_info,
|
164
|
+
service_type
|
165
|
+
)
|
166
|
+
return res.to_json()
|
167
|
+
end
|
168
|
+
|
169
|
+
# 상품 추가인증 요청
|
170
|
+
def request_certification(product_path, service_type, param)
|
171
|
+
# 클라이언트 정보 검사
|
172
|
+
if !has_client_info(service_type)
|
173
|
+
res = new_response_message(Message::EMPTY_CLIENT_INFO)
|
174
|
+
return res.to_json()
|
175
|
+
end
|
176
|
+
|
177
|
+
# 퍼블릭키 검사
|
178
|
+
if @public_key == ''
|
179
|
+
res = new_response_message(Message::EMPTY_PUBLIC_KEY)
|
180
|
+
return res.to_json()
|
181
|
+
end
|
182
|
+
|
183
|
+
# 추가인증 파라미터 필수 입력 체크
|
184
|
+
if !has_require_two_way_info(param)
|
185
|
+
res = new_response_message(Message::INVALID_2WAY_INFO)
|
186
|
+
return res.to_json()
|
187
|
+
end
|
188
|
+
|
189
|
+
# 리퀘스트 정보 조회
|
190
|
+
req_info = get_req_info_by_service_type(service_type)
|
191
|
+
|
192
|
+
# 요청
|
193
|
+
res = Connector.execute(
|
194
|
+
product_path,
|
195
|
+
param,
|
196
|
+
@access_token,
|
197
|
+
req_info,
|
198
|
+
service_type
|
199
|
+
)
|
200
|
+
return res.to_json()
|
201
|
+
end
|
202
|
+
|
203
|
+
# 토큰 요청
|
204
|
+
def request_token(service_type)
|
205
|
+
if !has_client_info(service_type)
|
206
|
+
return nil
|
207
|
+
end
|
208
|
+
|
209
|
+
return case service_type
|
210
|
+
when TYPE_PRODUCT
|
211
|
+
Connector.request_token(@client_id, @client_secret)
|
212
|
+
when TYPE_DEMO
|
213
|
+
Connector.request_token(@demo_client_id, @demo_client_secret)
|
214
|
+
else
|
215
|
+
Connector.request_token(SANDBOX_CLIENT_ID, SANDBOX_CLIENT_SECRET)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
# connectedID 발급을 위한 계정 등록
|
220
|
+
def create_account(service_type, param)
|
221
|
+
return request_product(PATH_CREATE_ACCOUNT, service_type, param)
|
222
|
+
end
|
223
|
+
|
224
|
+
# 계정 정보 추가
|
225
|
+
def add_account(service_type, param)
|
226
|
+
return request_product(PATH_ADD_ACCOUNT, service_type, param)
|
227
|
+
end
|
228
|
+
|
229
|
+
# 계정 정보 수정
|
230
|
+
def update_account(service_type, param)
|
231
|
+
return request_product(PATH_UPDATE_ACCOUNT, service_type, param)
|
232
|
+
end
|
233
|
+
|
234
|
+
# 계정 정보 삭제
|
235
|
+
def delete_account(service_type, param)
|
236
|
+
return request_product(PATH_DELETE_ACCOUNT, service_type, param)
|
237
|
+
end
|
238
|
+
|
239
|
+
# connectedID로 등록된 계정 목록 조회
|
240
|
+
def get_account_list(service_type, param)
|
241
|
+
return request_product(PATH_GET_ACCOUNT_LIST, service_type, param)
|
242
|
+
end
|
243
|
+
|
244
|
+
# 클라이언트 정보로 등록된 모든 connectedID 목록 조회
|
245
|
+
def get_connected_id_list(service_type, param)
|
246
|
+
return request_product(PATH_GET_CID_LIST, service_type, param)
|
247
|
+
end
|
248
|
+
|
249
|
+
private
|
250
|
+
|
251
|
+
# 클라이언트 정보 검사
|
252
|
+
def has_client_info(service_type)
|
253
|
+
return case service_type
|
254
|
+
when TYPE_PRODUCT
|
255
|
+
@client_id.strip != '' && client_secret.strip != ''
|
256
|
+
when TYPE_DEMO
|
257
|
+
@demo_client_id.strip != '' && @demo_client_secret.strip != ''
|
258
|
+
else
|
259
|
+
SANDBOX_CLIENT_ID.strip != '' && SANDBOX_CLIENT_SECRET.strip != ''
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
# 2Way 키워드 존재 여부 검사
|
266
|
+
def is_empty_two_way_keyword(param)
|
267
|
+
if param == nil
|
268
|
+
return true
|
269
|
+
end
|
270
|
+
return param['is2Way'] == nil && param['twoWayInfo'] == nil
|
271
|
+
end
|
272
|
+
|
273
|
+
# 2Way 필수 데이터 검사
|
274
|
+
def has_require_two_way_info(param)
|
275
|
+
if param == nil
|
276
|
+
return false
|
277
|
+
end
|
278
|
+
is2_way = param['is2Way']
|
279
|
+
if !!is2_way != is2_way || !is2_way
|
280
|
+
return false
|
281
|
+
end
|
282
|
+
|
283
|
+
two_way_info = param['twoWayInfo']
|
284
|
+
if two_way_info == nil
|
285
|
+
return false
|
286
|
+
end
|
287
|
+
|
288
|
+
return check_need_value_in_two_way_info(two_way_info)
|
289
|
+
end
|
290
|
+
|
291
|
+
# twoWayInfo 내부에 필요한 데이터가 존재하는지 검사
|
292
|
+
def check_need_value_in_two_way_info(two_way_info)
|
293
|
+
return two_way_info['jobIndex'] != nil &&
|
294
|
+
two_way_info['threadIndex'] != nil &&
|
295
|
+
two_way_info['jti'] != nil &&
|
296
|
+
two_way_info['twoWayTimestamp'] != nil
|
297
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# 메시지 정보 클래스
|
2
|
+
class MessageInfo
|
3
|
+
def initialize(code, message, extra_message='')
|
4
|
+
@code = code
|
5
|
+
@message = message
|
6
|
+
@extra_message = extra_message
|
7
|
+
end
|
8
|
+
|
9
|
+
def code()
|
10
|
+
return @code
|
11
|
+
end
|
12
|
+
|
13
|
+
def message()
|
14
|
+
return @message
|
15
|
+
end
|
16
|
+
|
17
|
+
def extra_message()
|
18
|
+
return @extra_message
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# 결과 메시지
|
23
|
+
module Message
|
24
|
+
OK = MessageInfo.new("CF-00000", "성공")
|
25
|
+
INVALID_JSON = MessageInfo.new("CF-00002", "json형식이 올바르지 않습니다.")
|
26
|
+
INVALID_PARAMETER= MessageInfo.new("CF-00007", "요청 파라미터가 올바르지 않습니다.")
|
27
|
+
UNSUPPORTED_ENCODING = MessageInfo.new("CF-00009", "지원하지 않는 형식으로 인코딩된 문자열입니다.")
|
28
|
+
EMPTY_CLIENT_INFO = MessageInfo.new("CF-00014", "상품 요청을 위해서는 클라이언트 정보가 필요합니다. 클라이언트 아이디와 시크릿 정보를 설정하세요.")
|
29
|
+
EMPTY_PUBLIC_KEY = MessageInfo.new("CF-00015", "상품 요청을 위해서는 퍼블릭키가 필요합니다. 퍼블릭키 정보를 설정하세요.")
|
30
|
+
INVALID_2WAY_INFO = MessageInfo.new("CF-03003", "2WAY 요청 처리를 위한 정보가 올바르지 않습니다. 응답으로 받은 항목을 그대로 2way요청 항목에 포함해야 합니다.")
|
31
|
+
INVALID_2WAY_KEYWORD = MessageInfo.new("CF-03004", "추가 인증(2Way)을 위한 요청은 requestCertification메서드를 사용해야 합니다.")
|
32
|
+
BAD_REQUEST = MessageInfo.new("CF-00400", "클라이언트 요청 오류로 인해 요청을 처리 할 수 없습니다.")
|
33
|
+
UNAUTHORIZED = MessageInfo.new("CF-00401", "요청 권한이 없습니다.")
|
34
|
+
FORBIDDEN = MessageInfo.new("CF-00403", "잘못된 요청입니다.")
|
35
|
+
NOT_FOUND = MessageInfo.new("CF-00404", "요청하신 페이지(Resource)를 찾을 수 없습니다.")
|
36
|
+
METHOD_NOT_ALLOWED = MessageInfo.new("CF-00405", "요청하신 방법(Method)이 잘못되었습니다.")
|
37
|
+
LIBRARY_SERNDER_ERROR = MessageInfo.new("CF-09980", "통신 요청에 실패했습니다. 응답정보를 확인하시고 올바른 요청을 시도하세요.")
|
38
|
+
SERVER_ERROR = MessageInfo.new("CF-09999", "서버 처리중 에러가 발생 했습니다. 관리자에게 문의하세요.")
|
39
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module EasyCodef
|
2
|
+
OAUTH_DOMAIN = "https://oauth.codef.io" # OAUTH 서버 도메인
|
3
|
+
PATH_GET_TOKEN = "/oauth/token" # OAUTH 엑세스 토큰 발급 URL PATH
|
4
|
+
SANDBOX_DOMAIN = "https://sandbox.codef.io" # 샌드박스 서버 도메인
|
5
|
+
SANDBOX_CLIENT_ID = "ef27cfaa-10c1-4470-adac-60ba476273f9" # 샌드박스 엑세스 토큰 발급을 위한 클라이언트 아이디
|
6
|
+
SANDBOX_CLIENT_SECRET = "83160c33-9045-4915-86d8-809473cdf5c3" # 샌드박스 액세스 토큰 발급을 위한 클라이언트 시크릿
|
7
|
+
DEMO_DOMAIN = "https://development.codef.io" # 데모 서버 도메인
|
8
|
+
API_DOMAIN = "https://api.codef.io" # 정식 서버 도메인
|
9
|
+
|
10
|
+
PATH_CREATE_ACCOUNT = "/v1/account/create" # 계정 등록 URL
|
11
|
+
PATH_ADD_ACCOUNT = "/v1/account/add" # 계정 추가 URL
|
12
|
+
PATH_UPDATE_ACCOUNT = "/v1/account/update" # 계정 수정 URL
|
13
|
+
PATH_DELETE_ACCOUNT = "/v1/account/delete" # 계정 삭제 URL
|
14
|
+
PATH_GET_ACCOUNT_LIST = "/v1/account/list" # 계정 목록 조회 URL
|
15
|
+
PATH_GET_CID_LIST = "/v1/account/connectedId-list" # 커넥티드 아이디 목록 조회 URL
|
16
|
+
|
17
|
+
KEY_RESULT = "result" # 응답부 수행 결과 키워드
|
18
|
+
KEY_CODE = "code" # 응답부 수행 결과 메시지 코드 키워드
|
19
|
+
KEY_MESSAGE = "message" # 응답부 수행 결과 메시지 키워드
|
20
|
+
KEY_EXTRA_MESSAGE = "extraMessage" # 응답부 수행 결과 추가 메시지 키워드
|
21
|
+
KEY_DATA = "data"
|
22
|
+
KEY_ACCOUNT_LIST = "accountList" # 계정 목록 키워드
|
23
|
+
KEY_CONNECTED_ID = "connectedId"
|
24
|
+
KEY_ACCESS_TOKEN = 'access_token'
|
25
|
+
|
26
|
+
KEY_INVALID_TOKEN = "invalidToken" # 엑세스 토큰 거절 사유1
|
27
|
+
KEY_ACCESS_DENIEND = "accessDenied" # 엑세스 토큰 거절 사유2
|
28
|
+
|
29
|
+
TYPE_PRODUCT = 0
|
30
|
+
TYPE_DEMO = 1
|
31
|
+
TYPE_SANDBOX = 2
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# 서비스 타입에 해당하는 코드에프 도메인 반환
|
36
|
+
def get_codef_domain(service_type)
|
37
|
+
return case service_type
|
38
|
+
when EasyCodef::TYPE_PRODUCT
|
39
|
+
EasyCodef::API_DOMAIN
|
40
|
+
when EasyCodef::TYPE_DEMO
|
41
|
+
EasyCodef::DEMO_DOMAIN
|
42
|
+
else
|
43
|
+
EasyCodef::SANDBOX_DOMAIN
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# 메시지 정보로 결과 생성
|
2
|
+
# MessageInfo 인스턴스를 받아서 메시지 정보로 해시를 만든다
|
3
|
+
def new_response_message(message_info)
|
4
|
+
return {
|
5
|
+
'result'=>{
|
6
|
+
'code'=>message_info.code,
|
7
|
+
'message'=>message_info.message,
|
8
|
+
'extra_message'=>message_info.extra_message,
|
9
|
+
},
|
10
|
+
'data'=>{}
|
11
|
+
}
|
12
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
module EasyCodef
|
5
|
+
module_function()
|
6
|
+
|
7
|
+
# 파일을 base64 인코딩한다
|
8
|
+
# 파일 경로를 인자로 받는다
|
9
|
+
def encode_to_file_str(file_path)
|
10
|
+
file = File.open(file_path)
|
11
|
+
base_64 = Base64.encode64(file.read)
|
12
|
+
file.close()
|
13
|
+
return base_64.encode('UTF-8').gsub(/\n/, '')
|
14
|
+
end
|
15
|
+
|
16
|
+
# RSA 암호화한다
|
17
|
+
# 암호화할 정보와 퍼블릭키를 인자로 받는다
|
18
|
+
def encrypt_RSA(text, public_key)
|
19
|
+
pub = Base64.decode64(public_key)
|
20
|
+
key = OpenSSL::PKey::RSA.new(pub)
|
21
|
+
enc_str = key.public_encrypt(text)
|
22
|
+
return Base64.encode64(enc_str).gsub(/\n/, '')
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easycodefrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- CODEF
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This library for using CODEF API
|
14
|
+
email:
|
15
|
+
- codef.io.dev@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- LICENSE
|
21
|
+
- lib/easycodefrb.rb
|
22
|
+
- lib/easycodefrb/connector.rb
|
23
|
+
- lib/easycodefrb/easycodef.rb
|
24
|
+
- lib/easycodefrb/message.rb
|
25
|
+
- lib/easycodefrb/properties.rb
|
26
|
+
- lib/easycodefrb/response.rb
|
27
|
+
- lib/easycodefrb/util.rb
|
28
|
+
homepage: https://github.com/codef-io/easycodefrb
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubygems_version: 3.1.4
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: COODEF Library
|
51
|
+
test_files: []
|