digidoc_client 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ff73d502c3fa8d6471314bcbb1bfdcb059fcf39
4
- data.tar.gz: 26dc4a2c1c2b745b9e0ad7a2b6ba3f2853d24866
3
+ metadata.gz: 97cf4180a037e5662c655d3c2d715941bffb8e3d
4
+ data.tar.gz: e4626d04d2fdf7c1ad676425a6a8c2743ece33b1
5
5
  SHA512:
6
- metadata.gz: 55c82ae9b4bfb2e671d573b7e83ba434d7d35c515c74277fa75e1ed4e2ae86adae57179dad1672834c3598b87376da2ef811ba1ffae4050a475fefdccd73114a
7
- data.tar.gz: 9bc495d69b58c94e045a86ee762c7adcb2591660d1c4c525b4bafa89497c3ea84a0248f8724292d5833e5b60d9ee4e8d987f3a935020b491e8e4dcbd2e570b33
6
+ metadata.gz: 2f16df55441c4cb37fa414d6e1189443a83972155aaf9988fc3236581ce21ddaca2e1aef9bed1eae68a77109cd683f51ab34481740a77597835a6cc1c4b202e6
7
+ data.tar.gz: 1b97636970606b98920b80b391a846803ec0a85271832b2c9165ff14bb2fdbd2bce93277921cf150d2c0365d246311937b0dda89b0482341663f0a98076e0bf1
data/README.markdown CHANGED
@@ -12,7 +12,7 @@ Add gem dependency in your `Gemfile` and install the gem:
12
12
 
13
13
  client = Digidoc::Client.new
14
14
  client.authenticate(
15
- :phone => '+3725012345', :message_to_display => 'Authenticating',
15
+ :phone => '+37260000007', :message_to_display => 'Authenticating',
16
16
  :service_name => 'Testing'
17
17
  )
18
18
  client.authentication_status
@@ -20,24 +20,37 @@ Add gem dependency in your `Gemfile` and install the gem:
20
20
  ### Signing
21
21
 
22
22
  client = Digidoc::Client.new
23
+ client.logger = Logger.new('digidoc_service.log')
23
24
  client.start_session
24
- client.create_signed_doc
25
+ client.create_signed_doc
25
26
  client.signed_doc_info
26
-
27
+
27
28
  file1 = File.open('file1.pdf')
28
29
  client.add_datafile(file1)
29
30
  file2 = File.open('file2.pdf')
30
31
  client.add_datafile(file2)
31
-
32
- client.mobile_sign(:phone => '5012345', :role => ' My Company LLC / CTO')
32
+
33
+ client.mobile_sign(:phone => '+37260000007', :role => ' My Company LLC / CTO')
33
34
  client.sign_status
34
-
35
- client.save_signed_doc do |content|
36
- File.open('signed_document.ddoc', 'w') { |f| f.write(content) }
35
+
36
+ # Check signature status here...
37
+
38
+ client.save_signed_doc do |content, format|
39
+ File.open("signed_document.#{format}", 'w') do |f|
40
+ if format == :bdoc
41
+ f.binmode
42
+ f.write(Base64.decode64(content))
43
+ else
44
+ f.write(content)
45
+ end
46
+ end
37
47
  end
38
-
48
+
39
49
  client.close_session
40
50
 
51
+ ### More test numbers and details
52
+ [In English](http://www.id.ee/?id=36381)
53
+
41
54
  ## Digidoc specifications
42
55
 
43
56
  [In English](http://www.sk.ee/upload/files/DigiDocService_spec_eng.pdf)
@@ -6,6 +6,7 @@ require 'crack/xml'
6
6
  require 'mime/types'
7
7
  require 'digest/sha1'
8
8
  require 'nokogiri'
9
+ require 'logger'
9
10
 
10
11
  class NestedOpenStruct < OpenStruct
11
12
  def initialize(hash = nil)
@@ -24,13 +25,13 @@ module Digidoc
24
25
  TestEndpointUrl = 'https://openxades.org:9443/DigiDocService'
25
26
 
26
27
  class Client
27
- cattr_accessor :logger
28
- attr_accessor :session_code, :endpoint_url, :respond_with_nested_struct, :embedded_datafiles
28
+ attr_accessor :logger, :session_code, :endpoint_url, :respond_with_nested_struct, :embedded_datafiles
29
29
 
30
30
  def initialize(endpoint_url = TestEndpointUrl)
31
31
  self.endpoint_url = endpoint_url || TestEndpointUrl
32
32
  self.respond_with_nested_struct = true
33
33
  self.embedded_datafiles = []
34
+ #self.logger = Logger.new(STDOUT)
34
35
  end
35
36
 
36
37
  # Authentication message
@@ -84,9 +85,11 @@ module Digidoc
84
85
  def start_session(*args)
85
86
  self.session_code = nil
86
87
  self.embedded_datafiles = []
88
+
87
89
  options = args.last || {}
88
90
  signed_doc_file = options.delete(:signed_doc_file)
89
91
  signed_doc_xml = signed_doc_file.read if signed_doc_file
92
+ signed_doc_xml = Base64.encode64(signed_doc_xml) if signed_doc_xml && signed_doc_xml.starts_with?('PK')
90
93
 
91
94
  response = savon_client.call('StartSession') do |locals|
92
95
  locals.message 'bHoldSession' => true, 'SigDocXML' => signed_doc_xml
@@ -104,12 +107,20 @@ module Digidoc
104
107
  # Creates DigiDoc container
105
108
  def create_signed_doc(*args)
106
109
  options = args.last || {}
110
+ format = options.delete(:format) || :bdoc # vaikimisi bdoc
111
+
112
+ if format == :xml
113
+ version = '1.3'
114
+ format = 'DIGIDOC-XML'
115
+ elsif format == :bdoc
116
+ version = '2.1'
117
+ format = 'BDOC'
118
+ end
107
119
 
108
120
  session_code = options.delete(:session_code) || self.session_code
109
- version = options.delete(:version) || '1.3'
110
121
 
111
122
  response = savon_client.call('CreateSignedDoc') do |locals|
112
- locals.message 'Sesscode' => session_code, 'Format' => 'DIGIDOC-XML', 'Version' => version
123
+ locals.message 'Sesscode' => session_code, 'Format' => format, 'Version' => version
113
124
  end
114
125
 
115
126
  result = soap_fault?(response) ? response.to_hash[:fault] : response.to_hash[:create_signed_doc_response]
@@ -245,8 +256,7 @@ module Digidoc
245
256
  result = respond_with_hash_or_nested(response.to_hash[:fault])
246
257
  else
247
258
  escaped = Crack::XML.parse(response.http.body).to_hash['SOAP_ENV:Envelope']['SOAP_ENV:Body']['dig:GetSignedDocResponse']['SignedDocData']
248
- # TODO: is escaping needed? - it removes original escaped & form XML
249
- digidoc_container = escaped#CGI.unescapeHTML(escaped)
259
+ digidoc_container = escaped
250
260
 
251
261
  if embedded_datafiles.present?
252
262
  xmldata = Nokogiri::XML(digidoc_container)
@@ -254,8 +264,10 @@ module Digidoc
254
264
  digidoc_container = xmldata.to_xml
255
265
  end
256
266
 
267
+ format = digidoc_container.starts_with?('<?xml') ? :xml : :bdoc
268
+
257
269
  if block_given?
258
- yield digidoc_container
270
+ yield(digidoc_container, format)
259
271
  else
260
272
  digidoc_container
261
273
  end
@@ -314,17 +326,23 @@ module Digidoc
314
326
  end
315
327
 
316
328
  def savon_client
317
- Savon.client(
329
+ options = {
318
330
  raise_errors: false,
319
331
  endpoint: self.endpoint_url,
320
332
  namespace: TargetNamespace,
321
333
  open_timeout: 10,
322
334
  ssl_version: :TLSv1,
323
- ssl_verify_mode: :none,
324
- logger: Client.logger,
325
- log_level: :debug,
326
- log: true
327
- )
335
+ ssl_verify_mode: :none
336
+ }
337
+
338
+ if self.logger
339
+ options.merge!(logger: self.logger,
340
+ log_level: :debug,
341
+ log: true
342
+ )
343
+ end
344
+
345
+ Savon.client(options)
328
346
  end
329
347
 
330
348
  def datafile(filename, mime_type, size, content, id)
@@ -1,3 +1,3 @@
1
1
  module Digidoc
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,153 +1,153 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digidoc_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tarmo Talu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2015-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 2.3.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.3.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: savon
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 2.4.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.4.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mime-types
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.16'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.16'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: crack
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 0.1.8
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.1.8
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: nokogiri
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.4.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.4.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: guard-rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: growl
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rb-fsevent
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  description: An easy way to interact with Estonian DigiDoc services.
@@ -157,7 +157,7 @@ executables: []
157
157
  extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
- - .gitignore
160
+ - ".gitignore"
161
161
  - Gemfile
162
162
  - Guardfile
163
163
  - README.markdown
@@ -178,17 +178,17 @@ require_paths:
178
178
  - lib
179
179
  required_ruby_version: !ruby/object:Gem::Requirement
180
180
  requirements:
181
- - - '>='
181
+ - - ">="
182
182
  - !ruby/object:Gem::Version
183
183
  version: '0'
184
184
  required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  requirements:
186
- - - '>='
186
+ - - ">="
187
187
  - !ruby/object:Gem::Version
188
188
  version: '0'
189
189
  requirements: []
190
190
  rubyforge_project: digidoc_client
191
- rubygems_version: 2.1.10
191
+ rubygems_version: 2.2.2
192
192
  signing_key:
193
193
  specification_version: 4
194
194
  summary: Ruby library to interact with Estonian DigiDoc services.