barocert 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/barocert/kakaocert.rb +452 -0
  3. data/lib/barocert.rb +194 -0
  4. metadata +58 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7fb5994fffa66548e4c988072bd99d52e90501e370ee090591b426a1d69d0fae
4
+ data.tar.gz: 5ed93b292b1ad6170a308acc3f85e2b73e86c7b6deb969034fe4ad57e0039490
5
+ SHA512:
6
+ metadata.gz: 1b85bd946e42896d01312c478293865b3087ba1b3f0ed3241cd37a7cb0e893af7fa9a0bdfab9d81868c873f5a1ce59854facbae22f255a72565d70587820b362
7
+ data.tar.gz: 3ceb78927f35927f922318effc92de49a8f54b7d207c1cbf5afd5a522a2d135f74bae46c26ac5f65f2d76f52a067f9b5af98fbbfb43fa27835be252dea9a2985
@@ -0,0 +1,452 @@
1
+ # -*- coding: utf-8 -*-
2
+ require_relative '../barocert.rb'
3
+ require 'openssl'
4
+ require 'base64'
5
+
6
+ # kakaocert API BaseService class
7
+ class KakaocertService < BarocertService
8
+ # Generate Linkhub Class Singleton Instance
9
+ class << self
10
+ def instance(linkID, secretKey)
11
+ super(linkID, secretKey)
12
+ @instance ||= new
13
+ @instance.addScope("401")
14
+ @instance.addScope("402")
15
+ @instance.addScope("403")
16
+ @instance.addScope("404")
17
+ return @instance
18
+ end
19
+ private :new
20
+ end
21
+
22
+ def _encrypt(plaintext)
23
+ return aes256gcm(plaintext, @linkhub._secretKey)
24
+ end
25
+
26
+ def aes256gcm(plaintext, key)
27
+ iv = OpenSSL::Random.random_bytes(12)
28
+ cipher = OpenSSL::Cipher.new('aes-256-gcm')
29
+ cipher.encrypt
30
+ cipher.key = Base64.decode64(key)
31
+ cipher.iv = iv
32
+ ciphertext = cipher.update(plaintext) + cipher.final
33
+ return Base64.strict_encode64(iv + ciphertext + cipher.auth_tag)
34
+ end
35
+
36
+ def isNumber(str)
37
+ return str.is_i?
38
+ end
39
+
40
+ def isNullorEmptyTitle(tokens)
41
+ if tokens.nil?
42
+ return true
43
+ end
44
+ tokens.each{ |token|
45
+ if token.nil?
46
+ return true
47
+ end
48
+ if token["reqTitle"].to_s == ''
49
+ return true
50
+ end
51
+ }
52
+ false
53
+ end
54
+
55
+ def isNullorEmptyToken(tokens)
56
+ if tokens.nil?
57
+ return true
58
+ end
59
+ tokens.each{ |token|
60
+ if token.nil?
61
+ return true
62
+ end
63
+ if token["token"].to_s == ''
64
+ return true
65
+ end
66
+ }
67
+ false
68
+ end
69
+
70
+ def requestIdentity(clientCode, identity)
71
+
72
+ if clientCode.to_s == ''
73
+ raise BarocertException.new('-99999999', '이용기관코드가 입력되지 않았습니다.')
74
+ end
75
+ if clientCode.is_i? == false
76
+ raise BarocertException.new('-99999999', '이용기관코드는 숫자만 입력할 수 있습니다.')
77
+ end
78
+ if clientCode.length != 12
79
+ raise BarocertException.new('-99999999', '이용기관코드는 12자 입니다.')
80
+ end
81
+ if identity.nil?
82
+ raise BarocertException.new('-99999999', '본인인증 서명요청 정보가 입력되지 않았습니다.s')
83
+ end
84
+ if identity["ci"].to_s == ''
85
+ if identity["receiverHP"].to_s == ''
86
+ raise BarocertException.new('-99999999', '수신자 휴대폰번호가 입력되지 않았습니다.')
87
+ end
88
+ if identity["receiverName"].to_s == ''
89
+ raise BarocertException.new('-99999999', '수신자 성명이 입력되지 않았습니다.')
90
+ end
91
+ if identity["receiverBirthday"].to_s == ''
92
+ raise BarocertException.new('-99999999', '생년월일이 입력되지 않았습니다.')
93
+ end
94
+ end
95
+
96
+ if identity["reqTitle"].to_s == ''
97
+ raise BarocertException.new('-99999999', '인증요청 메시지 제목이 입력되지 않았습니다.')
98
+ end
99
+
100
+ if identity["expireIn"].to_s == ''
101
+ raise BarocertException.new('-99999999', '만료시간이 입력되지 않았습니다.')
102
+ end
103
+
104
+ if identity["token"].to_s == ''
105
+ raise BarocertException.new('-99999999', '토큰 원문이 입력되지 않았습니다.')
106
+ end
107
+
108
+ httppost("/KAKAO/Identity/#{clientCode}", identity.to_json)
109
+ end
110
+
111
+ def getIdentityStatus(clientCode, receiptID)
112
+ puts receiptID
113
+ if clientCode.to_s == ''
114
+ raise BarocertException.new('-99999999', '이용기관코드가 입력되지 않았습니다.')
115
+ end
116
+ if clientCode.is_i? == false
117
+ raise BarocertException.new('-99999999', '이용기관코드는 숫자만 입력할 수 있습니다.')
118
+ end
119
+ if clientCode.length != 12
120
+ raise BarocertException.new('-99999999', '이용기관코드는 12자 입니다.')
121
+ end
122
+ if receiptID.to_s == ''
123
+ raise BarocertException.new('-99999999', '접수아이디가 입력되지 않았습니다.')
124
+ end
125
+ if receiptID.is_i? == false
126
+ raise BarocertException.new('-99999999', '접수아이디는 숫자만 입력할 수 있습니다.')
127
+ end
128
+ if receiptID.length != 32
129
+ raise BarocertException.new('-99999999', '접수아이디는 32자 입니다.')
130
+ end
131
+
132
+ httpget("/KAKAO/Identity/#{clientCode}/#{receiptID}")
133
+ end
134
+
135
+ def verifyIdentity(clientCode, receiptID)
136
+ if clientCode.to_s == ''
137
+ raise BarocertException.new('-99999999', '이용기관코드가 입력되지 않았습니다.')
138
+ end
139
+ if clientCode.is_i? == false
140
+ raise BarocertException.new('-99999999', '이용기관코드는 숫자만 입력할 수 있습니다.')
141
+ end
142
+ if clientCode.length != 12
143
+ raise BarocertException.new('-99999999', '이용기관코드는 12자 입니다.')
144
+ end
145
+ if receiptID.to_s == ''
146
+ raise BarocertException.new('-99999999', '접수아이디가 입력되지 않았습니다.')
147
+ end
148
+ if receiptID.is_i? == false
149
+ raise BarocertException.new('-99999999', '접수아이디는 숫자만 입력할 수 있습니다.')
150
+ end
151
+ if receiptID.length != 32
152
+ raise BarocertException.new('-99999999', '접수아이디는 32자 입니다.')
153
+ end
154
+
155
+ httppost("/KAKAO/Identity/#{clientCode}/#{receiptID}")
156
+ end
157
+
158
+ def requestSign(clientCode, sign)
159
+ if clientCode.to_s == ''
160
+ raise BarocertException.new('-99999999', '이용기관코드가 입력되지 않았습니다.')
161
+ end
162
+ if clientCode.is_i? == false
163
+ raise BarocertException.new('-99999999', '이용기관코드는 숫자만 입력할 수 있습니다.')
164
+ end
165
+ if clientCode.length != 12
166
+ raise BarocertException.new('-99999999', '이용기관코드는 12자 입니다.')
167
+ end
168
+ if sign.nil?
169
+ raise BarocertException.new('-99999999', '본인인증 서명요청 정보가 입력되지 않았습니다.s')
170
+ end
171
+ if sign["ci"].to_s == ''
172
+ if sign["receiverHP"].to_s == ''
173
+ raise BarocertException.new('-99999999', '수신자 휴대폰번호가 입력되지 않았습니다.')
174
+ end
175
+ if sign["receiverName"].to_s == ''
176
+ raise BarocertException.new('-99999999', '수신자 성명이 입력되지 않았습니다.')
177
+ end
178
+ if sign["receiverBirthday"].to_s == ''
179
+ raise BarocertException.new('-99999999', '생년월일이 입력되지 않았습니다.')
180
+ end
181
+ end
182
+
183
+ if sign["reqTitle"].to_s == ''
184
+ raise BarocertException.new('-99999999', '인증요청 메시지 제목이 입력되지 않았습니다.')
185
+ end
186
+
187
+ if sign["expireIn"].to_s == ''
188
+ raise BarocertException.new('-99999999', '만료시간이 입력되지 않았습니다.')
189
+ end
190
+
191
+ if sign["token"].to_s == ''
192
+ raise BarocertException.new('-99999999', '토큰 원문이 입력되지 않았습니다.')
193
+ end
194
+
195
+ if sign["tokenType"].to_s == ''
196
+ raise BarocertException.new('-99999999', '원문 유형이 입력되지 않았습니다.')
197
+ end
198
+ httppost("/KAKAO/Sign/#{clientCode}", sign.to_json)
199
+ end
200
+
201
+ def getSignStatus(clientCode, receiptID)
202
+ if clientCode.to_s == ''
203
+ raise BarocertException.new('-99999999', '이용기관코드가 입력되지 않았습니다.')
204
+ end
205
+ if clientCode.is_i? == false
206
+ raise BarocertException.new('-99999999', '이용기관코드는 숫자만 입력할 수 있습니다.')
207
+ end
208
+ if clientCode.length != 12
209
+ raise BarocertException.new('-99999999', '이용기관코드는 12자 입니다.')
210
+ end
211
+ if receiptID.to_s == ''
212
+ raise BarocertException.new('-99999999', '접수아이디가 입력되지 않았습니다.')
213
+ end
214
+ if receiptID.is_i? == false
215
+ raise BarocertException.new('-99999999', '접수아이디는 숫자만 입력할 수 있습니다.')
216
+ end
217
+ if receiptID.length != 32
218
+ raise BarocertException.new('-99999999', '접수아이디는 32자 입니다.')
219
+ end
220
+
221
+ httpget("/KAKAO/Sign/#{clientCode}/#{receiptID}")
222
+ end
223
+
224
+ def verifySign(clientCode, receiptID)
225
+ if clientCode.to_s == ''
226
+ raise BarocertException.new('-99999999', '이용기관코드가 입력되지 않았습니다.')
227
+ end
228
+ if clientCode.is_i? == false
229
+ raise BarocertException.new('-99999999', '이용기관코드는 숫자만 입력할 수 있습니다.')
230
+ end
231
+ if clientCode.length != 12
232
+ raise BarocertException.new('-99999999', '이용기관코드는 12자 입니다.')
233
+ end
234
+ if receiptID.to_s == ''
235
+ raise BarocertException.new('-99999999', '접수아이디가 입력되지 않았습니다.')
236
+ end
237
+ if receiptID.is_i? == false
238
+ raise BarocertException.new('-99999999', '접수아이디는 숫자만 입력할 수 있습니다.')
239
+ end
240
+ if receiptID.length != 32
241
+ raise BarocertException.new('-99999999', '접수아이디는 32자 입니다.')
242
+ end
243
+
244
+ httppost("/KAKAO/Sign/#{clientCode}/#{receiptID}")
245
+ end
246
+
247
+ def requestMultiSign(clientCode, multiSign)
248
+ if clientCode.to_s == ''
249
+ raise BarocertException.new('-99999999', '이용기관코드가 입력되지 않았습니다.')
250
+ end
251
+ if clientCode.is_i? == false
252
+ raise BarocertException.new('-99999999', '이용기관코드는 숫자만 입력할 수 있습니다.')
253
+ end
254
+ if clientCode.length != 12
255
+ raise BarocertException.new('-99999999', '이용기관코드는 12자 입니다.')
256
+ end
257
+ if multiSign.nil?
258
+ raise BarocertException.new('-99999999', '본인인증 서명요청 정보가 입력되지 않았습니다.s')
259
+ end
260
+ if multiSign["ci"].to_s == ''
261
+ if multiSign["receiverHP"].to_s == ''
262
+ raise BarocertException.new('-99999999', '수신자 휴대폰번호가 입력되지 않았습니다.')
263
+ end
264
+ if multiSign["receiverName"].to_s == ''
265
+ raise BarocertException.new('-99999999', '수신자 성명이 입력되지 않았습니다.')
266
+ end
267
+ if multiSign["receiverBirthday"].to_s == ''
268
+ raise BarocertException.new('-99999999', '생년월일이 입력되지 않았습니다.')
269
+ end
270
+ end
271
+
272
+ if multiSign["reqTitle"].to_s == ''
273
+ raise BarocertException.new('-99999999', '인증요청 메시지 제목이 입력되지 않았습니다.')
274
+ end
275
+
276
+ if multiSign["expireIn"].to_s == ''
277
+ raise BarocertException.new('-99999999', '만료시간이 입력되지 않았습니다.')
278
+ end
279
+
280
+ if isNullorEmptyTitle(multiSign["tokens"])
281
+ raise BarocertException.new('-99999999', '인증요청 메시지 제목이 입력되지 않았습니다.')
282
+ end
283
+
284
+ if isNullorEmptyToken(multiSign["tokens"])
285
+ raise BarocertException.new('-99999999', '토큰 원문이 입력되지 않았습니다.')
286
+ end
287
+
288
+ if multiSign["tokenType"].to_s == ''
289
+ raise BarocertException.new('-99999999', '원문 유형이 입력되지 않았습니다.')
290
+ end
291
+
292
+ httppost("/KAKAO/MultiSign/#{clientCode}", multiSign.to_json)
293
+ end
294
+
295
+ def getMultiSignStatus(clientCode, receiptID)
296
+ if clientCode.to_s == ''
297
+ raise BarocertException.new('-99999999', '이용기관코드가 입력되지 않았습니다.')
298
+ end
299
+ if clientCode.is_i? == false
300
+ raise BarocertException.new('-99999999', '이용기관코드는 숫자만 입력할 수 있습니다.')
301
+ end
302
+ if clientCode.length != 12
303
+ raise BarocertException.new('-99999999', '이용기관코드는 12자 입니다.')
304
+ end
305
+ if receiptID.to_s == ''
306
+ raise BarocertException.new('-99999999', '접수아이디가 입력되지 않았습니다.')
307
+ end
308
+ if receiptID.is_i? == false
309
+ raise BarocertException.new('-99999999', '접수아이디는 숫자만 입력할 수 있습니다.')
310
+ end
311
+ if receiptID.length != 32
312
+ raise BarocertException.new('-99999999', '접수아이디는 32자 입니다.')
313
+ end
314
+
315
+ httpget("/KAKAO/MultiSign/#{clientCode}/#{receiptID}")
316
+ end
317
+
318
+ def verifyMultiSign(clientCode, receiptID)
319
+ if clientCode.to_s == ''
320
+ raise BarocertException.new('-99999999', '이용기관코드가 입력되지 않았습니다.')
321
+ end
322
+ if clientCode.is_i? == false
323
+ raise BarocertException.new('-99999999', '이용기관코드는 숫자만 입력할 수 있습니다.')
324
+ end
325
+ if clientCode.length != 12
326
+ raise BarocertException.new('-99999999', '이용기관코드는 12자 입니다.')
327
+ end
328
+ if receiptID.to_s == ''
329
+ raise BarocertException.new('-99999999', '접수아이디가 입력되지 않았습니다.')
330
+ end
331
+ if receiptID.is_i? == false
332
+ raise BarocertException.new('-99999999', '접수아이디는 숫자만 입력할 수 있습니다.')
333
+ end
334
+ if receiptID.length != 32
335
+ raise BarocertException.new('-99999999', '접수아이디는 32자 입니다.')
336
+ end
337
+
338
+ httppost("/KAKAO/MultiSign/#{clientCode}/#{receiptID}")
339
+ end
340
+
341
+ def requestCMS(clientCode, cms)
342
+ if clientCode.to_s == ''
343
+ raise BarocertException.new('-99999999', '이용기관코드가 입력되지 않았습니다.')
344
+ end
345
+ if clientCode.is_i? == false
346
+ raise BarocertException.new('-99999999', '이용기관코드는 숫자만 입력할 수 있습니다.')
347
+ end
348
+ if clientCode.length != 12
349
+ raise BarocertException.new('-99999999', '이용기관코드는 12자 입니다.')
350
+ end
351
+ if cms.nil?
352
+ raise BarocertException.new('-99999999', '본인인증 서명요청 정보가 입력되지 않았습니다.s')
353
+ end
354
+ if cms["ci"].to_s == ''
355
+ if cms["receiverHP"].to_s == ''
356
+ raise BarocertException.new('-99999999', '수신자 휴대폰번호가 입력되지 않았습니다.')
357
+ end
358
+ if cms["receiverName"].to_s == ''
359
+ raise BarocertException.new('-99999999', '수신자 성명이 입력되지 않았습니다.')
360
+ end
361
+ if cms["receiverBirthday"].to_s == ''
362
+ raise BarocertException.new('-99999999', '생년월일이 입력되지 않았습니다.')
363
+ end
364
+ end
365
+
366
+ if cms["reqTitle"].to_s == ''
367
+ raise BarocertException.new('-99999999', '인증요청 메시지 제목이 입력되지 않았습니다.')
368
+ end
369
+
370
+ if cms["expireIn"].to_s == ''
371
+ raise BarocertException.new('-99999999', '만료시간이 입력되지 않았습니다.')
372
+ end
373
+
374
+ if cms["requestCorp"].to_s == ''
375
+ raise BarocertException.new('-99999999', '청구기관명이 입력되지 않았습니다.')
376
+ end
377
+
378
+ if cms["bankName"].to_s == ''
379
+ raise BarocertException.new('-99999999', '은행명이 입력되지 않았습니다.')
380
+ end
381
+
382
+ if cms["bankAccountNum"].to_s == ''
383
+ raise BarocertException.new('-99999999', '계좌번호가 입력되지 않았습니다.')
384
+ end
385
+
386
+ if cms["bankAccountName"].to_s == ''
387
+ raise BarocertException.new('-99999999', '예금주명이 입력되지 않았습니다.')
388
+ end
389
+
390
+ if cms["bankAccountBirthday"].to_s == ''
391
+ raise BarocertException.new('-99999999', '예금주 생년월일이 입력되지 않았습니다.')
392
+ end
393
+
394
+ if cms["bankServiceType"].to_s == ''
395
+ raise BarocertException.new('-99999999', '출금 유형이 입력되지 않았습니다.')
396
+ end
397
+ httppost("/KAKAO/CMS/#{clientCode}", cms.to_json)
398
+ end
399
+
400
+
401
+ def getCMSStatus(clientCode, receiptID)
402
+ if clientCode.to_s == ''
403
+ raise BarocertException.new('-99999999', '이용기관코드가 입력되지 않았습니다.')
404
+ end
405
+ if clientCode.is_i? == false
406
+ raise BarocertException.new('-99999999', '이용기관코드는 숫자만 입력할 수 있습니다.')
407
+ end
408
+ if clientCode.length != 12
409
+ raise BarocertException.new('-99999999', '이용기관코드는 12자 입니다.')
410
+ end
411
+ if receiptID.to_s == ''
412
+ raise BarocertException.new('-99999999', '접수아이디가 입력되지 않았습니다.')
413
+ end
414
+ if receiptID.is_i? == false
415
+ raise BarocertException.new('-99999999', '접수아이디는 숫자만 입력할 수 있습니다.')
416
+ end
417
+ if receiptID.length != 32
418
+ raise BarocertException.new('-99999999', '접수아이디는 32자 입니다.')
419
+ end
420
+
421
+ httpget("/KAKAO/CMS/#{clientCode}/#{receiptID}")
422
+ end
423
+
424
+ def verifyCMS(clientCode, receiptID)
425
+ if clientCode.to_s == ''
426
+ raise BarocertException.new('-99999999', '이용기관코드가 입력되지 않았습니다.')
427
+ end
428
+ if clientCode.is_i? == false
429
+ raise BarocertException.new('-99999999', '이용기관코드는 숫자만 입력할 수 있습니다.')
430
+ end
431
+ if clientCode.length != 12
432
+ raise BarocertException.new('-99999999', '이용기관코드는 12자 입니다.')
433
+ end
434
+ if receiptID.to_s == ''
435
+ raise BarocertException.new('-99999999', '접수아이디가 입력되지 않았습니다.')
436
+ end
437
+ if receiptID.is_i? == false
438
+ raise BarocertException.new('-99999999', '접수아이디는 숫자만 입력할 수 있습니다.')
439
+ end
440
+ if receiptID.length != 32
441
+ raise BarocertException.new('-99999999', '접수아이디는 32자 입니다.')
442
+ end
443
+
444
+ httppost("/KAKAO/CMS/#{clientCode}/#{receiptID}")
445
+ end
446
+ end
447
+
448
+ class String
449
+ def is_i?
450
+ !!(self =~ /^\d+$/)
451
+ end
452
+ end
data/lib/barocert.rb ADDED
@@ -0,0 +1,194 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'json'
5
+ require 'date'
6
+ require 'linkhub'
7
+
8
+ # Barocert API BaseService class
9
+ class BarocertService
10
+ ServiceID_REAL = "BAROCERT"
11
+ ServiceURL = "https://barocert.linkhub.co.kr"
12
+ ServiceURL_Static = "https://static-barocert.linkhub.co.kr"
13
+ APIVersion = "2.0"
14
+ BOUNDARY = "==BAROCERT_RUBY_SDK=="
15
+
16
+ attr_accessor :token_table, :scopes, :linkhub, :ipRestrictOnOff, :useStaticIP, :useLocalTimeYN
17
+
18
+ # Generate Linkhub Class Singleton Instance
19
+ class << self
20
+ def instance(linkID, secretKey)
21
+ @instance ||= new
22
+ @instance.token_table = {}
23
+ @instance.linkhub = Linkhub.instance(linkID, secretKey)
24
+ @instance.scopes = ["partner"]
25
+ @instance.ipRestrictOnOff = false
26
+ @instance.useStaticIP = false
27
+ @instance.useLocalTimeYN = true
28
+ return @instance
29
+ end
30
+
31
+ private :new
32
+ end
33
+
34
+
35
+ # add Service Scope array
36
+ def addScope(scopeValue)
37
+ @scopes.push(scopeValue)
38
+ end
39
+
40
+ def setIpRestrictOnOff(value)
41
+ @ipRestrictOnOff = value
42
+ end
43
+
44
+ def setUseStaticIP(value)
45
+ @useStaticIP = value
46
+ end
47
+
48
+ def setUseLocalTimeYN(value)
49
+ @useLocalTimeYN = value
50
+ end
51
+
52
+ def getServiceURL()
53
+ if @useStaticIP
54
+ return ServiceURL_Static
55
+ else
56
+ return ServiceURL
57
+ end
58
+ end
59
+
60
+ # Get Session Token by checking token-cached hash or token Request
61
+ def getSession_Token()
62
+ targetToken = nil
63
+ refresh = false
64
+
65
+ # check already cached CorpNum's SessionToken
66
+ if @token_table.key?(@linkhub._linkID)
67
+ targetToken = @token_table[@linkhub._linkID]
68
+ end
69
+
70
+ if targetToken.nil?
71
+ refresh = true
72
+ else
73
+ # Token's expireTime must use parse() because time format is hh:mm:ss.SSSZ
74
+ expireTime = DateTime.parse(targetToken['expiration'])
75
+ serverUTCTime = DateTime.strptime(@linkhub.getTime(@useStaticIP, false, @useLocalTimeYN))
76
+ refresh = expireTime < serverUTCTime
77
+ end
78
+
79
+ if refresh
80
+ begin
81
+ # getSessionToken from Linkhub
82
+ targetToken = @linkhub.getSessionToken(ServiceID_REAL, "" , @scopes, @ipRestrictOnOff ? "" : "*", @useStaticIP, false, @useLocalTimeYN)
83
+
84
+ rescue LinkhubException => le
85
+ raise BarocertException.new(le.code, le.message)
86
+ end
87
+ # append token to cache hash
88
+ @token_table[@linkhub._linkID] = targetToken
89
+ end
90
+
91
+ targetToken['session_token']
92
+ end
93
+
94
+ # end of getSession_Token
95
+
96
+ def gzip_parse (target)
97
+ sio = StringIO.new(target)
98
+ gz = Zlib::GzipReader.new(sio)
99
+ gz.read()
100
+ end
101
+
102
+ # Barocert API http Get Request Func
103
+ def httpget(url)
104
+ headers = {
105
+ "Accept-Encoding" => "gzip,deflate",
106
+ }
107
+
108
+ headers["Authorization"] = "Bearer " + getSession_Token()
109
+
110
+ uri = URI(getServiceURL() + url)
111
+ request = Net::HTTP.new(uri.host, 443)
112
+ request.use_ssl = true
113
+
114
+ Net::HTTP::Get.new(uri)
115
+
116
+ res = request.get(uri.request_uri, headers)
117
+
118
+ if res.code == "200"
119
+ if res.header['Content-Encoding'].eql?('gzip')
120
+ JSON.parse(gzip_parse(res.body))
121
+ else
122
+ JSON.parse(res.body)
123
+ end
124
+ else
125
+ raise BarocertException.new(JSON.parse(res.body)["code"], JSON.parse(res.body)["message"])
126
+ end
127
+ end
128
+
129
+ #end of httpget
130
+
131
+ # Request HTTP Post
132
+ def httppost(url, postData=nil)
133
+
134
+ headers = {
135
+ "Accept-Encoding" => "gzip,deflate",
136
+ "x-bc-version" => APIVersion,
137
+ }
138
+
139
+ date = @linkhub.getTime(@useStaticIP, false)
140
+
141
+ hmacTarget = "POST\n"
142
+ hmacTarget += url + "\n"
143
+ if postData != nil
144
+ hmacTarget += Base64.strict_encode64(Digest::SHA256.digest(postData)) + "\n"
145
+ end
146
+ hmacTarget += date + "\n"
147
+
148
+ key = Base64.decode64(@linkhub._secretKey)
149
+
150
+ data = hmacTarget
151
+ digest = OpenSSL::Digest.new("sha256")
152
+ hmac = Base64.strict_encode64(OpenSSL::HMAC.digest(digest, key, data))
153
+
154
+ headers["x-bc-auth"] = hmac
155
+ headers["x-bc-date"] = date
156
+
157
+ headers["x-bc-encryptionmode"] = "GCM"
158
+
159
+ headers["Content-Type"] = "application/json; charset=utf8"
160
+
161
+ headers["Authorization"] = "Bearer " + getSession_Token()
162
+
163
+
164
+ uri = URI(getServiceURL() + url)
165
+
166
+ https = Net::HTTP.new(uri.host, 443)
167
+ https.use_ssl = true
168
+ Net::HTTP::Post.new(uri)
169
+
170
+ res = https.post(uri.request_uri, postData, headers)
171
+
172
+ if res.code == "200"
173
+ if res.header['Content-Encoding'].eql?('gzip')
174
+ JSON.parse(gzip_parse(res.body))
175
+ else
176
+ JSON.parse(res.body)
177
+ end
178
+ else
179
+ raise BarocertException.new(JSON.parse(res.body)["code"], JSON.parse(res.body)["message"])
180
+ end
181
+ end
182
+
183
+ #end of httppost
184
+ end
185
+
186
+ # Barocert API Exception Handler class
187
+ class BarocertException < StandardError
188
+ attr_reader :code, :message
189
+
190
+ def initialize(code, message)
191
+ @code = code
192
+ @message = message
193
+ end
194
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: barocert
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Linkhub Dev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: linkhub
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.0
27
+ description: barocert API SDK
28
+ email: dev@linkhub.co.kr
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/barocert.rb
34
+ - lib/barocert/kakaocert.rb
35
+ homepage: https://github.com/barocert/barocert.ruby
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.1.4
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: barocert API SDK
58
+ test_files: []