ruby_isds 0.9.0
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/.gitignore +13 -0
- data/.overcommit.yml +47 -0
- data/.rspec +2 -0
- data/.rubocop.yml +23 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/DOCS.md +133 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +139 -0
- data/Guardfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +160 -0
- data/Rakefile +6 -0
- data/_config.yml +1 -0
- data/bin/console +7 -0
- data/lib/ruby_isds.rb +85 -0
- data/lib/ruby_isds/configuration.rb +51 -0
- data/lib/ruby_isds/data_box.rb +33 -0
- data/lib/ruby_isds/data_message.rb +129 -0
- data/lib/ruby_isds/request.rb +105 -0
- data/lib/ruby_isds/response.rb +17 -0
- data/lib/ruby_isds/responses/body.rb +19 -0
- data/lib/ruby_isds/responses/data_box.rb +14 -0
- data/lib/ruby_isds/responses/db/body.rb +9 -0
- data/lib/ruby_isds/responses/db/status.rb +13 -0
- data/lib/ruby_isds/responses/dm/body.rb +9 -0
- data/lib/ruby_isds/responses/dm/status.rb +13 -0
- data/lib/ruby_isds/responses/message.rb +21 -0
- data/lib/ruby_isds/responses/messages/attachment.rb +22 -0
- data/lib/ruby_isds/responses/messages/collection.rb +28 -0
- data/lib/ruby_isds/responses/messages/delivery_info.rb +23 -0
- data/lib/ruby_isds/responses/messages/envelope.rb +23 -0
- data/lib/ruby_isds/responses/messages/event.rb +14 -0
- data/lib/ruby_isds/responses/status.rb +19 -0
- data/lib/ruby_isds/utils/errors.rb +10 -0
- data/lib/ruby_isds/version.rb +3 -0
- data/lib/ruby_isds/web_services/db_access/.gitkeep +0 -0
- data/lib/ruby_isds/web_services/db_access/change_isds_password.rb +21 -0
- data/lib/ruby_isds/web_services/db_search/check_data_box.rb +17 -0
- data/lib/ruby_isds/web_services/db_search/d_t_info.rb +17 -0
- data/lib/ruby_isds/web_services/db_search/data_box_credit_info.rb +17 -0
- data/lib/ruby_isds/web_services/db_search/find_data_box.rb +25 -0
- data/lib/ruby_isds/web_services/db_search/find_personal_data_box.rb +22 -0
- data/lib/ruby_isds/web_services/db_search/get_data_box_activity_status.rb +17 -0
- data/lib/ruby_isds/web_services/db_search/get_data_box_list.rb +20 -0
- data/lib/ruby_isds/web_services/db_search/isds_search_2.rb +18 -0
- data/lib/ruby_isds/web_services/db_search/p_d_z_info.rb +17 -0
- data/lib/ruby_isds/web_services/db_search/p_d_z_send_info.rb +17 -0
- data/lib/ruby_isds/web_services/db_search/request.rb +19 -0
- data/lib/ruby_isds/web_services/db_search/response.rb +13 -0
- data/lib/ruby_isds/web_services/dm_info/confirm_delivery.rb +17 -0
- data/lib/ruby_isds/web_services/dm_info/erase_message.rb +17 -0
- data/lib/ruby_isds/web_services/dm_info/get_delivery_info.rb +25 -0
- data/lib/ruby_isds/web_services/dm_info/get_list_of_received_messages.rb +26 -0
- data/lib/ruby_isds/web_services/dm_info/get_list_of_sent_messages.rb +26 -0
- data/lib/ruby_isds/web_services/dm_info/get_message_author.rb +17 -0
- data/lib/ruby_isds/web_services/dm_info/get_message_state_changes.rb +17 -0
- data/lib/ruby_isds/web_services/dm_info/get_signed_delivery_info.rb +17 -0
- data/lib/ruby_isds/web_services/dm_info/mark_message_as_downloaded.rb +17 -0
- data/lib/ruby_isds/web_services/dm_info/message_envelope_download.rb +25 -0
- data/lib/ruby_isds/web_services/dm_info/request.rb +19 -0
- data/lib/ruby_isds/web_services/dm_info/response.rb +13 -0
- data/lib/ruby_isds/web_services/dm_info/verify_message.rb +17 -0
- data/lib/ruby_isds/web_services/dm_operations/authenticate_message.rb +17 -0
- data/lib/ruby_isds/web_services/dm_operations/create_message.rb +30 -0
- data/lib/ruby_isds/web_services/dm_operations/create_multiple_messages.rb +30 -0
- data/lib/ruby_isds/web_services/dm_operations/message_download.rb +25 -0
- data/lib/ruby_isds/web_services/dm_operations/ping.rb +15 -0
- data/lib/ruby_isds/web_services/dm_operations/request.rb +19 -0
- data/lib/ruby_isds/web_services/dm_operations/resign_isds_document.rb +17 -0
- data/lib/ruby_isds/web_services/dm_operations/response.rb +13 -0
- data/lib/ruby_isds/web_services/dm_operations/signed_message_download.rb +17 -0
- data/lib/ruby_isds/web_services/dm_operations/signed_sent_message_download.rb +17 -0
- data/ruby_isds.gemspec +47 -0
- data/wercker.yml +12 -0
- metadata +303 -0
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Andrej Antas
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# Work in Progress
|
2
|
+
|
3
|
+
# RubyIsds [](https://app.wercker.com/project/byKey/04043d3ae16228db7dc8d9d3ae51d1e6)
|
4
|
+
|
5
|
+
Wrapper for API love [ISDS](https://www.datoveschranky.info/) shares with us through this XML API.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ruby_isds'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ruby_isds
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Before usage please add config (for rails initializer) with following:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
RubyIsds.configure do |c|
|
29
|
+
c.data_box = 'data_box_id'
|
30
|
+
c.username = 'somebody'
|
31
|
+
c.password = 'data_box_password'
|
32
|
+
c.env = :development
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
you do not have to provide `env` in setup unless you go to production, gem
|
37
|
+
defaults to `:development` anyway...
|
38
|
+
|
39
|
+
This gem provides you with 2 basic classes and those are:
|
40
|
+
- `RubyIsds::DataBox` (operations and manipulation around data box itself)
|
41
|
+
- `RubyIsds::DataMessage` (operations and manipulation with message)
|
42
|
+
|
43
|
+
Kinda important to mention is that results of calls are trying to be the same each time of course and in form of neat object that looks like this:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
=> #<RubyIsds::WebServices::DbSearch::Response:0x00007fd3d44f0fd8
|
47
|
+
@body=#<RubyIsds::Responses::Db::Body:0x00007fd3d449b808 @ciRecords=nil, @currentCredit="596400", @notifEmail=nil>,
|
48
|
+
@response=
|
49
|
+
{"Envelope"=>
|
50
|
+
{"xmlns:SOAP_ENV"=>"http://schemas.xmlsoap.org/soap/envelope/",
|
51
|
+
"xmlns:xsd"=>"http://www.w3.org/2001/XMLSchema",
|
52
|
+
"Body"=>{"DataBoxCreditInfoResponse"=>{"xmlns:p"=>"http://isds.czechpoint.cz/v20", "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", "currentCredit"=>"596400", "notifEmail"=>{"xsi:nil"=>"true"}, "ciRecords"=>nil, "dbStatus"=>{"dbStatusCode"=>"0000", "dbStatusMessage"=>"Provedeno úspěšně."}}}}},
|
53
|
+
@status=#<RubyIsds::Responses::Db::Status:0x00007fd3d449be48 @code="0000", @message="Provedeno úspěšně.">>
|
54
|
+
```
|
55
|
+
|
56
|
+
To take it apart consist of:
|
57
|
+
- `body` -> in case of request for messages will be `messages` is parsed body taking original attribute names and their values
|
58
|
+
- inspect and use like so:
|
59
|
+
```ruby
|
60
|
+
> result.body.currentCredit
|
61
|
+
=> "596400"
|
62
|
+
```
|
63
|
+
- `status` -> always contains status information in form of `code` and `messsage`
|
64
|
+
- `response` -> simply whole original XML response parsed into Hash for better usage
|
65
|
+
|
66
|
+
Public API looks like so:
|
67
|
+
|
68
|
+
### RubyIsds::DataBox
|
69
|
+
|
70
|
+
#### .check
|
71
|
+
|
72
|
+
checking the status
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
> RubyIsds::DataBox.check
|
76
|
+
|
77
|
+
=> #<RubyIsds::WebServices::DbSearch::Response:0x00007fd3d68487d8
|
78
|
+
@body=#<RubyIsds::Responses::Db::Body:0x00007fd3d41ad2e0 @dbState="1">,
|
79
|
+
@response=
|
80
|
+
{"Envelope"=>
|
81
|
+
{"xmlns:SOAP_ENV"=>"http://schemas.xmlsoap.org/soap/envelope/",
|
82
|
+
"xmlns:xsd"=>"http://www.w3.org/2001/XMLSchema",
|
83
|
+
"Body"=>{"CheckDataBoxResponse"=>{"xmlns:p"=>"http://isds.czechpoint.cz/v20", "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", "dbState"=>"1", "dbStatus"=>{"dbStatusCode"=>"0000", "dbStatusMessage"=>"Provedeno úspěšně."}}}}},
|
84
|
+
@status=#<RubyIsds::Responses::Db::Status:0x00007fd3d41ae280 @code="0000", @message="Provedeno úspěšně.">>
|
85
|
+
```
|
86
|
+
|
87
|
+
|
88
|
+
#### .find
|
89
|
+
|
90
|
+
#### .credit_info
|
91
|
+
|
92
|
+
#### .received
|
93
|
+
|
94
|
+
#### .sent
|
95
|
+
|
96
|
+
#### .state_changes
|
97
|
+
|
98
|
+
|
99
|
+
### RubyIsds::DataMessage
|
100
|
+
|
101
|
+
#### .find
|
102
|
+
|
103
|
+
#### #download
|
104
|
+
|
105
|
+
#### #verify
|
106
|
+
|
107
|
+
#### #authenticate
|
108
|
+
|
109
|
+
#### #signed
|
110
|
+
|
111
|
+
#### #author
|
112
|
+
|
113
|
+
#### #delivery_info
|
114
|
+
|
115
|
+
#### #envelope
|
116
|
+
|
117
|
+
#### #confirm_delivery
|
118
|
+
|
119
|
+
#### #mark_as_downloaded
|
120
|
+
|
121
|
+
#### #destroy
|
122
|
+
|
123
|
+
#### #sent?
|
124
|
+
|
125
|
+
#### #received?
|
126
|
+
|
127
|
+
### Help
|
128
|
+
|
129
|
+
If in doubt, or my so called 'README' seems not that helpful, please refer to [ISDS provozni rad](https://www.datoveschranky.info/dulezite-informace/provozni-rad-isds)
|
130
|
+
|
131
|
+
## Development
|
132
|
+
|
133
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
134
|
+
|
135
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
136
|
+
|
137
|
+
## Contributing
|
138
|
+
|
139
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruby_isds. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
140
|
+
|
141
|
+
## TODO
|
142
|
+
|
143
|
+
Still WIP although we test it already how this is going to turn out, so fingers
|
144
|
+
crossed... we still need to finish:
|
145
|
+
- massive portion of specs
|
146
|
+
- refactoring (a lot of same code and misused inheritance)
|
147
|
+
- sending messages...
|
148
|
+
- better documentation
|
149
|
+
|
150
|
+
## License
|
151
|
+
|
152
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
153
|
+
|
154
|
+
## Thanks
|
155
|
+
|
156
|
+
Many thanks to Petr Písař <petr.pisar@atlas.cz> for writing awesome libisds C library and compiling many usefull information around ISDS :)
|
157
|
+
|
158
|
+
## Code of Conduct
|
159
|
+
|
160
|
+
Everyone interacting in the RubyIsds project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ruby_isds/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-modernist
|
data/bin/console
ADDED
data/lib/ruby_isds.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'base64'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'active_support/core_ext/hash'
|
5
|
+
|
6
|
+
require 'ruby_isds/utils/errors'
|
7
|
+
|
8
|
+
require 'ruby_isds/version'
|
9
|
+
require 'ruby_isds/configuration'
|
10
|
+
require 'ruby_isds/request'
|
11
|
+
require 'ruby_isds/response'
|
12
|
+
|
13
|
+
require 'ruby_isds/data_box'
|
14
|
+
require 'ruby_isds/data_message'
|
15
|
+
|
16
|
+
require 'ruby_isds/responses/body'
|
17
|
+
require 'ruby_isds/responses/status'
|
18
|
+
require 'ruby_isds/responses/db/status'
|
19
|
+
require 'ruby_isds/responses/dm/status'
|
20
|
+
require 'ruby_isds/responses/dm/body'
|
21
|
+
require 'ruby_isds/responses/db/body'
|
22
|
+
require 'ruby_isds/responses/message'
|
23
|
+
require 'ruby_isds/responses/messages/event'
|
24
|
+
require 'ruby_isds/responses/messages/envelope'
|
25
|
+
require 'ruby_isds/responses/messages/attachment'
|
26
|
+
require 'ruby_isds/responses/messages/collection'
|
27
|
+
require 'ruby_isds/responses/messages/delivery_info'
|
28
|
+
|
29
|
+
require 'ruby_isds/web_services/db_search/response'
|
30
|
+
require 'ruby_isds/web_services/db_search/request'
|
31
|
+
require 'ruby_isds/web_services/db_search/find_data_box'
|
32
|
+
require 'ruby_isds/web_services/db_search/d_t_info'
|
33
|
+
require 'ruby_isds/web_services/db_search/get_data_box_activity_status'
|
34
|
+
require 'ruby_isds/web_services/db_search/check_data_box'
|
35
|
+
require 'ruby_isds/web_services/db_search/data_box_credit_info'
|
36
|
+
require 'ruby_isds/web_services/db_search/find_personal_data_box'
|
37
|
+
require 'ruby_isds/web_services/db_search/get_data_box_list'
|
38
|
+
require 'ruby_isds/web_services/db_search/isds_search_2'
|
39
|
+
require 'ruby_isds/web_services/db_search/p_d_z_info'
|
40
|
+
require 'ruby_isds/web_services/db_search/p_d_z_send_info'
|
41
|
+
|
42
|
+
require 'ruby_isds/web_services/db_access/change_isds_password'
|
43
|
+
|
44
|
+
require 'ruby_isds/web_services/dm_info/request'
|
45
|
+
require 'ruby_isds/web_services/dm_info/response'
|
46
|
+
require 'ruby_isds/web_services/dm_info/confirm_delivery'
|
47
|
+
require 'ruby_isds/web_services/dm_info/erase_message'
|
48
|
+
require 'ruby_isds/web_services/dm_info/get_delivery_info'
|
49
|
+
require 'ruby_isds/web_services/dm_info/get_list_of_received_messages'
|
50
|
+
require 'ruby_isds/web_services/dm_info/get_list_of_sent_messages'
|
51
|
+
require 'ruby_isds/web_services/dm_info/get_message_author'
|
52
|
+
require 'ruby_isds/web_services/dm_info/get_message_state_changes'
|
53
|
+
require 'ruby_isds/web_services/dm_info/get_signed_delivery_info'
|
54
|
+
require 'ruby_isds/web_services/dm_info/mark_message_as_downloaded'
|
55
|
+
require 'ruby_isds/web_services/dm_info/message_envelope_download'
|
56
|
+
require 'ruby_isds/web_services/dm_info/verify_message'
|
57
|
+
|
58
|
+
require 'ruby_isds/web_services/dm_operations/request'
|
59
|
+
require 'ruby_isds/web_services/dm_operations/response'
|
60
|
+
require 'ruby_isds/web_services/dm_operations/authenticate_message'
|
61
|
+
require 'ruby_isds/web_services/dm_operations/create_message'
|
62
|
+
require 'ruby_isds/web_services/dm_operations/create_multiple_messages'
|
63
|
+
require 'ruby_isds/web_services/dm_operations/message_download'
|
64
|
+
require 'ruby_isds/web_services/dm_operations/ping'
|
65
|
+
require 'ruby_isds/web_services/dm_operations/resign_isds_document'
|
66
|
+
require 'ruby_isds/web_services/dm_operations/signed_message_download'
|
67
|
+
require 'ruby_isds/web_services/dm_operations/signed_sent_message_download'
|
68
|
+
|
69
|
+
module RubyIsds
|
70
|
+
def self.configuration
|
71
|
+
@configuration ||= Configuration.new
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.reset
|
75
|
+
@configuration = Configuration.new
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.configure
|
79
|
+
yield(configuration)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.ping
|
83
|
+
::RubyIsds::WebServices::DmOperations::Ping.new.call
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module RubyIsds
|
2
|
+
class Configuration
|
3
|
+
attr_writer :data_box, :username, :password, :env, :api_url
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@username = nil
|
7
|
+
@password = nil
|
8
|
+
@data_box = nil
|
9
|
+
@env = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def data_box
|
13
|
+
raise ConfigNotSet, 'data_box' unless @data_box
|
14
|
+
@data_box
|
15
|
+
end
|
16
|
+
|
17
|
+
def username
|
18
|
+
raise ConfigNotSet, 'username' unless @username
|
19
|
+
@username
|
20
|
+
end
|
21
|
+
|
22
|
+
def password
|
23
|
+
raise ConfigNotSet, 'password' unless @password
|
24
|
+
@password
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# env values:
|
29
|
+
# :development (default)
|
30
|
+
# :production
|
31
|
+
#
|
32
|
+
def env
|
33
|
+
return :development unless @env
|
34
|
+
@env
|
35
|
+
end
|
36
|
+
|
37
|
+
def api_domain
|
38
|
+
case @env
|
39
|
+
when :production then 'https://ws1c.mojedatovaschranka.cz'
|
40
|
+
else 'https://ws1.czebox.cz'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def xml_url
|
45
|
+
case @env
|
46
|
+
when :production then 'mojedatovaschranka.cz'
|
47
|
+
else 'czechpoint.cz'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module RubyIsds
|
2
|
+
class DataBox
|
3
|
+
def self.check(options = {})
|
4
|
+
::RubyIsds::WebServices::DbSearch::CheckDataBox
|
5
|
+
.call(options.merge(dbID: ::RubyIsds.configuration.data_box))
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.find_by(options = {})
|
9
|
+
::RubyIsds::WebServices::DbSearch::FindDataBox
|
10
|
+
.call(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.credit_info(options = {})
|
14
|
+
::RubyIsds::WebServices::DbSearch::DataBoxCreditInfo
|
15
|
+
.call(options.merge(dbID: ::RubyIsds.configuration.data_box))
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.received(options = {})
|
19
|
+
RubyIsds::WebServices::DmInfo::GetListOfReceivedMessages
|
20
|
+
.call(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.sent(options = {})
|
24
|
+
RubyIsds::WebServices::DmInfo::GetListOfSentMessages
|
25
|
+
.call(options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.state_changes(options = {})
|
29
|
+
RubyIsds::WebServices::DmInfo::GetMessageStateChanges
|
30
|
+
.call(options)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# rubocop:disable Metrics/ClassLength
|
2
|
+
module RubyIsds
|
3
|
+
class DataMessage
|
4
|
+
ATTRIBUTES = %w[dmType dmOrdinal dmID dbIDSender dmSender
|
5
|
+
dmSenderAddress dmSenderType dmRecipient dmRecipientAddress
|
6
|
+
dmSenderOrgUnit dmSenderOrgUnitNum dbIDRecipient dmRecipientOrgUnit
|
7
|
+
dmRecipientOrgUnitNum dmToHands dmAnnotation dmRecipientRefNumber
|
8
|
+
dmSenderRefNumber dmRecipientIdent dmSenderIdent dmLegalTitleLaw
|
9
|
+
dmLegalTitleYear dmLegalTitleSect dmLegalTitlePar dmLegalTitlePoint
|
10
|
+
dmPersonalDelivery dmAllowSubstDelivery dmMessageStatus
|
11
|
+
dmAttachmentSize dmDeliveryTime dmAcceptanceTime dmHash
|
12
|
+
dmQTimestamp dmAttachments dmAmbiguousRecipient].freeze
|
13
|
+
|
14
|
+
attr_accessor(*ATTRIBUTES)
|
15
|
+
|
16
|
+
def self.find(dmID)
|
17
|
+
RubyIsds::WebServices::DmOperations::MessageDownload
|
18
|
+
.call(dmID: dmID)
|
19
|
+
end
|
20
|
+
|
21
|
+
def download(destination = '/tmp')
|
22
|
+
File.open("#{destination}/#{dmID}.zfo", 'wb') do |f|
|
23
|
+
f.write(Base64.decode64(signed.body.dmSignature))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(params = {})
|
28
|
+
@params = params.dup
|
29
|
+
status_info = @params.delete('dmDm')
|
30
|
+
@dmAttachments = load_attachments
|
31
|
+
@dmEvents = load_events
|
32
|
+
unified_params = status_info ? status_info.merge(@params) : params
|
33
|
+
unified_params.each do |key, value|
|
34
|
+
raise "Not valid attribute of DataMessage #{key}" unless ATTRIBUTES.include?(key)
|
35
|
+
instance_variable_set("@#{key}", parsed_value(value))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def verify
|
40
|
+
RubyIsds::WebServices::DmInfo::VerifyMessage
|
41
|
+
.call(dmID: dmID)
|
42
|
+
end
|
43
|
+
|
44
|
+
def authenticate
|
45
|
+
RubyIsds::WebServices::DmOperations::AuthenticateMessage
|
46
|
+
.call(dmMessage: signed.body.dmSignature)
|
47
|
+
end
|
48
|
+
|
49
|
+
def signed
|
50
|
+
RubyIsds::WebServices::DmOperations::SignedMessageDownload
|
51
|
+
.call(dmID: dmID)
|
52
|
+
end
|
53
|
+
|
54
|
+
def author
|
55
|
+
RubyIsds::WebServices::DmInfo::GetMessageAuthor
|
56
|
+
.call(dmID: dmID)
|
57
|
+
end
|
58
|
+
|
59
|
+
def delivery_info
|
60
|
+
RubyIsds::WebServices::DmInfo::GetDeliveryInfo
|
61
|
+
.call(dmID: dmID)
|
62
|
+
end
|
63
|
+
|
64
|
+
def envelope
|
65
|
+
RubyIsds::WebServices::DmInfo::MessageEnvelopeDownload
|
66
|
+
.call(dmID: dmID)
|
67
|
+
end
|
68
|
+
|
69
|
+
def confirm_delivery
|
70
|
+
RubyIsds::WebServices::DmInfo::ConfirmDelivery
|
71
|
+
.call(dmID: dmID)
|
72
|
+
end
|
73
|
+
|
74
|
+
def mark_as_downloaded
|
75
|
+
RubyIsds::WebServices::DmInfo::MarkMessageAsDownloaded
|
76
|
+
.call(dmID: dmID)
|
77
|
+
end
|
78
|
+
|
79
|
+
def destroy(options = {})
|
80
|
+
RubyIsds::WebServices::DmInfo::EraseMessage
|
81
|
+
.call(options.merge(dmID: dmID))
|
82
|
+
end
|
83
|
+
|
84
|
+
def sent?
|
85
|
+
dbIDSender == ::RubyIsds.configuration.data_box
|
86
|
+
end
|
87
|
+
|
88
|
+
def received?
|
89
|
+
dbIDSender != ::RubyIsds.configuration.data_box
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def load_events
|
95
|
+
return {} if @params['dmEvents'].blank?
|
96
|
+
events_hash = @params.delete('dmEvents')['dmEvent']
|
97
|
+
if events_hash.is_a?(Array)
|
98
|
+
events_hash.map do |event|
|
99
|
+
::RubyIsds::Responses::Messages::Event.new(event)
|
100
|
+
end
|
101
|
+
else
|
102
|
+
::RubyIsds::Responses::Messages::Event.new(events_hash)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def load_attachments
|
107
|
+
return {} if @params['dmFiles'].blank?
|
108
|
+
attachments_hash = @params.delete('dmFiles')['dmFile']
|
109
|
+
if attachments_hash.is_a?(Array)
|
110
|
+
attachments_hash.map do |attachment|
|
111
|
+
::RubyIsds::Responses::Messages::Attachment.new(attachment)
|
112
|
+
end
|
113
|
+
else
|
114
|
+
::RubyIsds::Responses::Messages::Attachment.new(attachments_hash)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def parsed_value(value)
|
119
|
+
return value unless value.is_a?(Hash)
|
120
|
+
raise "Missing parse rule for #{value}" if value.keys.size > 1
|
121
|
+
if value.keys.first == 'xsi:nil' && value.values.first == 'true'
|
122
|
+
nil
|
123
|
+
else
|
124
|
+
false
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
# rubocop:enable Metrics/ClassLength
|