kiji 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,114 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext/object'
3
+
4
+ module Kiji
5
+ module Access
6
+ def apply(file_name, file_data)
7
+ appl_data = Nokogiri::XML::Builder.new do |xml|
8
+ xml.DataRoot {
9
+ xml.ApplData(Id: 'ApplData') {
10
+ xml.Upload {
11
+ xml.FileName file_name
12
+ xml.FileData file_data
13
+ }
14
+ }
15
+ }
16
+ end
17
+
18
+ connection.post('/shinsei/1/access/apply') do |req|
19
+ req.body = appl_data.to_xml
20
+ end
21
+ end
22
+
23
+ def sended_applications_by_id(send_number)
24
+ connection.get("/shinsei/1/access/apply;id=#{send_number}")
25
+ end
26
+
27
+ def sended_applications_by_date(from, to)
28
+ connection.get("/shinsei/1/access/apply;date=#{from}-#{to}")
29
+ end
30
+
31
+ def arrived_applications(send_number)
32
+ connection.get("/shinsei/1/access/apply/#{send_number}")
33
+ end
34
+
35
+ def reference(arrive_id)
36
+ connection.get("/shinsei/1/access/reference/#{arrive_id}")
37
+ end
38
+
39
+ def withdraw(arrive_id, file_data)
40
+ appl_data = Nokogiri::XML::Builder.new do |xml|
41
+ xml.DataRoot {
42
+ xml.ApplData(Id: 'ApplData') {
43
+ xml.ArriveID arrive_id
44
+ xml.Upload {
45
+ xml.FileData file_data
46
+ }
47
+ }
48
+ }
49
+ end
50
+
51
+ connection.post('/shinsei/1/access/withdrawal') do |req|
52
+ req.body = appl_data.to_xml
53
+ end
54
+ end
55
+
56
+ def amends(arrive_id)
57
+ connection.get("/shinsei/1/access/amend/#{arrive_id}")
58
+ end
59
+
60
+ def notices(arrive_id)
61
+ connection.get("/shinsei/1/access/notice/#{arrive_id}")
62
+ end
63
+
64
+ def officialdocument(arrive_id, notice_sub_id)
65
+ connection.get("/shinsei/1/access/officialdocument/#{arrive_id}/#{notice_sub_id}")
66
+ end
67
+
68
+ def verify_officialdocument(arrive_id, file_name, file_data, sig_xml_file_name)
69
+ appl_data = Nokogiri::XML::Builder.new do |xml|
70
+ xml.DataRoot {
71
+ xml.ApplData(Id: 'ApplData') {
72
+ xml.ArriveID arrive_id
73
+ xml.Upload {
74
+ xml.FileName file_name
75
+ xml.FileData file_data
76
+ xml.SigVerificationXMLFileName sig_xml_file_name
77
+ }
78
+ }
79
+ }
80
+ end
81
+
82
+ connection.post('/shinsei/1/access/officialdocument/verify') do |req|
83
+ req.body = appl_data.to_xml
84
+ end
85
+ end
86
+
87
+ def comment(arrive_id, notice_sub_id)
88
+ connection.get("/shinsei/1/access/comment/#{arrive_id}/#{notice_sub_id}")
89
+ end
90
+
91
+ def done_comment(arrive_id, notice_sub_id)
92
+ appl_data = Nokogiri::XML::Builder.new do |xml|
93
+ xml.DataRoot {
94
+ xml.ApplData(Id: 'ApplData') {
95
+ xml.ArriveID arrive_id
96
+ xml.NoticeSubID notice_sub_id
97
+ }
98
+ }
99
+ end
100
+
101
+ connection.put('/shinsei/1/access/comment') do |req|
102
+ req.body = appl_data.to_xml
103
+ end
104
+ end
105
+
106
+ def banks
107
+ connection.get('/shinsei/1/access/bank')
108
+ end
109
+
110
+ def payments(arrive_id)
111
+ connection.get("/shinsei/1/access/payment/#{arrive_id}")
112
+ end
113
+ end
114
+ end
data/lib/kiji/api.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'kiji/authentication'
2
+ require 'kiji/access'
3
+
4
+ module Kiji
5
+ module API
6
+ include Kiji::Authentication
7
+ include Kiji::Access
8
+ end
9
+ end
@@ -0,0 +1,82 @@
1
+ module Kiji
2
+ module Authentication
3
+ def register(user_id)
4
+ appl_data = Nokogiri::XML::Builder.new do |xml|
5
+ xml.DataRoot {
6
+ xml.ApplData(Id: 'ApplData') {
7
+ xml.UserID user_id
8
+ }
9
+ }
10
+ end
11
+
12
+ connection.post('/shinsei/1/authentication/user') do |req|
13
+ req.body = sign(appl_data).to_xml
14
+ end
15
+ end
16
+
17
+ def login(user_id)
18
+ appl_data = Nokogiri::XML::Builder.new do |xml|
19
+ xml.DataRoot {
20
+ xml.ApplData(Id: 'ApplData') {
21
+ xml.UserID user_id
22
+ }
23
+ }
24
+ end
25
+
26
+ connection.post('/shinsei/1/authentication/login') do |req|
27
+ req.body = sign(appl_data).to_xml
28
+ end
29
+ end
30
+
31
+ def append_certificate(user_id, new_cert)
32
+ x509_cert = Base64.encode64(new_cert.to_der).gsub('\n', '')
33
+
34
+ appl_data = Nokogiri::XML::Builder.new do |xml|
35
+ xml.DataRoot {
36
+ xml.ApplData(Id: 'ApplData') {
37
+ xml.UserID user_id
38
+ xml.AddX509Certificate x509_cert
39
+ }
40
+ }
41
+ end
42
+
43
+ connection.post('/shinsei/1/authentication/certificate/append') do |req|
44
+ req.body = sign(appl_data).to_xml
45
+ end
46
+ end
47
+
48
+ def update_certificate(user_id, old_cert)
49
+ x509_cert = Base64.encode64(old_cert.to_der).gsub('\n', '')
50
+
51
+ appl_data = Nokogiri::XML::Builder.new do |xml|
52
+ xml.DataRoot {
53
+ xml.ApplData(Id: 'ApplData') {
54
+ xml.UserID user_id
55
+ xml.X509Certificate x509_cert
56
+ }
57
+ }
58
+ end
59
+
60
+ connection.post('/shinsei/1/authentication/certificate/update') do |req|
61
+ req.body = sign(appl_data).to_xml
62
+ end
63
+ end
64
+
65
+ def delete_certificate(user_id, cert_to_delete)
66
+ x509_cert = Base64.encode64(cert_to_delete.to_der).gsub('\n', '')
67
+
68
+ appl_data = Nokogiri::XML::Builder.new do |xml|
69
+ xml.DataRoot {
70
+ xml.ApplData(Id: 'ApplData') {
71
+ xml.UserID user_id
72
+ xml.DelX509Certificate x509_cert
73
+ }
74
+ }
75
+ end
76
+
77
+ connection.post('/shinsei/1/authentication/certificate/delete') do |req|
78
+ req.body = sign(appl_data).to_xml
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,56 @@
1
+ require 'faraday'
2
+ require 'kiji/signer'
3
+ require 'kiji/api'
4
+
5
+ module Kiji
6
+ class Client
7
+ include Kiji::API
8
+ attr_accessor :cert, :private_key, :access_key,
9
+ :software_id, :api_end_point,
10
+ :basic_auth_id, :basic_auth_password
11
+
12
+ def initialize
13
+ @software_id = software_id
14
+ @api_end_point = api_end_point
15
+ @basic_auth_id = basic_auth_id
16
+ @basic_auth_password = basic_auth_password
17
+
18
+ yield(self) if block_given?
19
+ end
20
+
21
+ private
22
+
23
+ def connection
24
+ Faraday.new(url: @api_end_point) do |c|
25
+ # c.response :logger
26
+ c.adapter Faraday.default_adapter
27
+ c.basic_auth(@basic_auth_id, @basic_auth_password) unless @basic_auth_id.nil?
28
+ c.headers['User-Agent'] = 'SmartHR v0.0.1'
29
+ c.headers['x-eGovAPI-SoftwareID'] = software_id
30
+ c.headers['x-eGovAPI-AccessKey'] = access_key unless access_key.nil?
31
+ end
32
+ end
33
+
34
+ def sign(appl_data)
35
+ fail 'Please specify cert & private_key' if cert.nil? || private_key.nil?
36
+
37
+ doc = appl_data.to_xml(save_with: 0)
38
+
39
+ signer = Signer.new(doc) do |s|
40
+ s.cert = cert
41
+ s.private_key = private_key
42
+ s.digest_algorithm = :sha256
43
+ s.signature_digest_algorithm = :sha256
44
+ end
45
+
46
+ signer.security_node = signer.document.root
47
+
48
+ signer.document.xpath('/DataRoot/ApplData').each do |node|
49
+ signer.digest!(node, id: '#ApplData')
50
+ end
51
+
52
+ signer.sign!(issuer_serial: true)
53
+ signer
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,77 @@
1
+ # Copyright (c) 2012 Edgars Beigarts
2
+ # Released under the MIT license
3
+ # http://opensource.org/licenses/mit-license.php
4
+ require 'openssl'
5
+
6
+ module Kiji
7
+ # Digest algorithms supported "out of the box"
8
+ DIGEST_ALGORITHMS = {
9
+ # SHA 1
10
+ sha1: {
11
+ name: 'SHA1',
12
+ id: 'http://www.w3.org/2000/09/xmldsig#sha1',
13
+ digester: -> { OpenSSL::Digest::SHA1.new }
14
+ },
15
+ # SHA 256
16
+ sha256: {
17
+ name: 'SHA256',
18
+ id: 'http://www.w3.org/2001/04/xmlenc#sha256',
19
+ digester: -> { OpenSSL::Digest::SHA256.new }
20
+ },
21
+ # GOST R 34-11 94
22
+ gostr3411: {
23
+ name: 'GOST R 34.11-94',
24
+ id: 'http://www.w3.org/2001/04/xmldsig-more#gostr3411',
25
+ digester: -> { OpenSSL::Digest.new('md_gost94') }
26
+ }
27
+ }
28
+
29
+ # Class that holds +OpenSSL::Digest+ instance with some meta information for digesting in XML.
30
+ class Digester
31
+ # You may pass either a one of +:sha1+, +:sha256+ or +:gostr3411+ symbols
32
+ # or +Hash+ with keys +:id+ with a string, which will denote algorithm in XML Reference tag
33
+ # and +:digester+ with instance of class with interface compatible with +OpenSSL::Digest+ class.
34
+ def initialize(algorithm)
35
+ if algorithm.is_a? Symbol
36
+ @digest_info = DIGEST_ALGORITHMS[algorithm].dup
37
+ @digest_info[:digester] = @digest_info[:digester].call
38
+ @symbol = algorithm
39
+ else
40
+ @digest_info = algorithm
41
+ end
42
+ end
43
+
44
+ attr_reader :symbol
45
+
46
+ # Digest
47
+ def digest(message)
48
+ digester.digest(message)
49
+ end
50
+
51
+ def hexdigest(message)
52
+ digester.hexdigest(message)
53
+ end
54
+
55
+ def base64(message)
56
+ hex = digester.hexdigest(message)
57
+ [[hex].pack('H*')].pack('m0')
58
+ end
59
+
60
+ alias_method :call, :digest
61
+
62
+ # Returns +OpenSSL::Digest+ (or derived class) instance
63
+ def digester
64
+ @digest_info[:digester].reset
65
+ end
66
+
67
+ # Human-friendly name
68
+ def digest_name
69
+ @digest_info[:name]
70
+ end
71
+
72
+ # XML-friendly name (for specifying in XML +DigestMethod+ node +Algorithm+ attribute)
73
+ def digest_id
74
+ @digest_info[:id]
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,126 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <?xml-stylesheet type="text/xsl" href="900A01020000100001.xsl" ?>
3
+ <DataRoot>
4
+ <様式ID>900A01020000100001</様式ID>
5
+ <様式バージョン>0003</様式バージョン>
6
+ <STYLESHEET>900A01020000100001.xsl</STYLESHEET>
7
+ <様式コピー情報>0</様式コピー情報>
8
+ <Doctype>1</Doctype>
9
+ <G00005-A-250045-001_1>
10
+ <帳票種別>13101</帳票種別>
11
+ <被保険者番号>
12
+ <被保険者番号4桁></被保険者番号4桁>
13
+ <被保険者番号6桁></被保険者番号6桁>
14
+ <被保険者番号CD></被保険者番号CD>
15
+ </被保険者番号>
16
+ <取得></取得>
17
+ <被保険者氏名></被保険者氏名>
18
+ <被保険者氏名フリガナ></被保険者氏名フリガナ>
19
+ <変更後の氏名></変更後の氏名>
20
+ <変更後の氏名フリガナ></変更後の氏名フリガナ>
21
+ <性別></性別>
22
+ <生年月日>
23
+ <年号>昭和</年号>
24
+ <年></年>
25
+ <月></月>
26
+ <日></日>
27
+ </生年月日>
28
+ <事業所番号>
29
+ <事業所番号4桁></事業所番号4桁>
30
+ <事業所番号6桁></事業所番号6桁>
31
+ <事業所番号CD></事業所番号CD>
32
+ </事業所番号>
33
+ <資格取得年月日>
34
+ <年号>平成</年号>
35
+ <年></年>
36
+ <月></月>
37
+ <日></日>
38
+ </資格取得年月日>
39
+ <被保険者となったことの原因></被保険者となったことの原因>
40
+ <賃金>
41
+ <支払の態様></支払の態様>
42
+ <賃金月額></賃金月額>
43
+ </賃金>
44
+ <雇用形態></雇用形態>
45
+ <職種></職種>
46
+ <取得時被保険者種類区分></取得時被保険者種類区分>
47
+ <番号複数取得チェック不要></番号複数取得チェック不要>
48
+ <契約期間の定め></契約期間の定め>
49
+ <契約期間の定めの有無>
50
+ <契約期間の定め有>
51
+ <契約期間開始>
52
+ <年号>平成</年号>
53
+ <年></年>
54
+ <月></月>
55
+ <日></日>
56
+ </契約期間開始>
57
+ <契約期間終了>
58
+ <年号>平成</年号>
59
+ <年></年>
60
+ <月></月>
61
+ <日></日>
62
+ </契約期間終了>
63
+ <契約更新条項有無></契約更新条項有無>
64
+ </契約期間の定め有>
65
+ </契約期間の定めの有無>
66
+ <一週間の所定労働時間>
67
+ <時間></時間>
68
+ <分></分>
69
+ </一週間の所定労働時間>
70
+ <事業所名称></事業所名称>
71
+ <備考欄_申請者>
72
+ <国籍></国籍>
73
+ <在留資格></在留資格>
74
+ <在留期間>
75
+ <年></年>
76
+ <月></月>
77
+ <日></日>
78
+ </在留期間>
79
+ <資格外活動許可の有無></資格外活動許可の有無>
80
+ <派遣請負労働者></派遣請負労働者>
81
+ <備考></備考>
82
+ </備考欄_申請者>
83
+ <事業主>
84
+ <住所></住所>
85
+ <氏名></氏名>
86
+ <電話番号>
87
+ <市外局番></市外局番>
88
+ <市内局番></市内局番>
89
+ <加入者番号></加入者番号>
90
+ </電話番号>
91
+ </事業主>
92
+ <届出年月日>
93
+ <年号>平成</年号>
94
+ <年></年>
95
+ <月></月>
96
+ <日></日>
97
+ </届出年月日>
98
+ <あて先></あて先>
99
+ <社会保険労務士記載欄>
100
+ <作成年月日>
101
+ <年号>平成</年号>
102
+ <年></年>
103
+ <月></月>
104
+ <日></日>
105
+ </作成年月日>
106
+ <提出代行者事務代理者の表示></提出代行者事務代理者の表示>
107
+ <氏名></氏名>
108
+ <電話番号>
109
+ <市外局番></市外局番>
110
+ <市内局番></市内局番>
111
+ <加入者番号></加入者番号>
112
+ </電話番号>
113
+ <付記欄></付記欄>
114
+ </社会保険労務士記載欄>
115
+ <備考欄_職員>
116
+ <備考></備考>
117
+ <確認通知年月日>
118
+ <年号>平成</年号>
119
+ <年></年>
120
+ <月></月>
121
+ <日></日>
122
+ </確認通知年月日>
123
+ </備考欄_職員>
124
+ <Xmit>0</Xmit>
125
+ </G00005-A-250045-001_1>
126
+ </DataRoot>