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.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.overcommit.yml +47 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +23 -0
  6. data/.ruby-gemset +1 -0
  7. data/.ruby-version +1 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/DOCS.md +133 -0
  10. data/Gemfile +6 -0
  11. data/Gemfile.lock +139 -0
  12. data/Guardfile +7 -0
  13. data/LICENSE.txt +21 -0
  14. data/README.md +160 -0
  15. data/Rakefile +6 -0
  16. data/_config.yml +1 -0
  17. data/bin/console +7 -0
  18. data/lib/ruby_isds.rb +85 -0
  19. data/lib/ruby_isds/configuration.rb +51 -0
  20. data/lib/ruby_isds/data_box.rb +33 -0
  21. data/lib/ruby_isds/data_message.rb +129 -0
  22. data/lib/ruby_isds/request.rb +105 -0
  23. data/lib/ruby_isds/response.rb +17 -0
  24. data/lib/ruby_isds/responses/body.rb +19 -0
  25. data/lib/ruby_isds/responses/data_box.rb +14 -0
  26. data/lib/ruby_isds/responses/db/body.rb +9 -0
  27. data/lib/ruby_isds/responses/db/status.rb +13 -0
  28. data/lib/ruby_isds/responses/dm/body.rb +9 -0
  29. data/lib/ruby_isds/responses/dm/status.rb +13 -0
  30. data/lib/ruby_isds/responses/message.rb +21 -0
  31. data/lib/ruby_isds/responses/messages/attachment.rb +22 -0
  32. data/lib/ruby_isds/responses/messages/collection.rb +28 -0
  33. data/lib/ruby_isds/responses/messages/delivery_info.rb +23 -0
  34. data/lib/ruby_isds/responses/messages/envelope.rb +23 -0
  35. data/lib/ruby_isds/responses/messages/event.rb +14 -0
  36. data/lib/ruby_isds/responses/status.rb +19 -0
  37. data/lib/ruby_isds/utils/errors.rb +10 -0
  38. data/lib/ruby_isds/version.rb +3 -0
  39. data/lib/ruby_isds/web_services/db_access/.gitkeep +0 -0
  40. data/lib/ruby_isds/web_services/db_access/change_isds_password.rb +21 -0
  41. data/lib/ruby_isds/web_services/db_search/check_data_box.rb +17 -0
  42. data/lib/ruby_isds/web_services/db_search/d_t_info.rb +17 -0
  43. data/lib/ruby_isds/web_services/db_search/data_box_credit_info.rb +17 -0
  44. data/lib/ruby_isds/web_services/db_search/find_data_box.rb +25 -0
  45. data/lib/ruby_isds/web_services/db_search/find_personal_data_box.rb +22 -0
  46. data/lib/ruby_isds/web_services/db_search/get_data_box_activity_status.rb +17 -0
  47. data/lib/ruby_isds/web_services/db_search/get_data_box_list.rb +20 -0
  48. data/lib/ruby_isds/web_services/db_search/isds_search_2.rb +18 -0
  49. data/lib/ruby_isds/web_services/db_search/p_d_z_info.rb +17 -0
  50. data/lib/ruby_isds/web_services/db_search/p_d_z_send_info.rb +17 -0
  51. data/lib/ruby_isds/web_services/db_search/request.rb +19 -0
  52. data/lib/ruby_isds/web_services/db_search/response.rb +13 -0
  53. data/lib/ruby_isds/web_services/dm_info/confirm_delivery.rb +17 -0
  54. data/lib/ruby_isds/web_services/dm_info/erase_message.rb +17 -0
  55. data/lib/ruby_isds/web_services/dm_info/get_delivery_info.rb +25 -0
  56. data/lib/ruby_isds/web_services/dm_info/get_list_of_received_messages.rb +26 -0
  57. data/lib/ruby_isds/web_services/dm_info/get_list_of_sent_messages.rb +26 -0
  58. data/lib/ruby_isds/web_services/dm_info/get_message_author.rb +17 -0
  59. data/lib/ruby_isds/web_services/dm_info/get_message_state_changes.rb +17 -0
  60. data/lib/ruby_isds/web_services/dm_info/get_signed_delivery_info.rb +17 -0
  61. data/lib/ruby_isds/web_services/dm_info/mark_message_as_downloaded.rb +17 -0
  62. data/lib/ruby_isds/web_services/dm_info/message_envelope_download.rb +25 -0
  63. data/lib/ruby_isds/web_services/dm_info/request.rb +19 -0
  64. data/lib/ruby_isds/web_services/dm_info/response.rb +13 -0
  65. data/lib/ruby_isds/web_services/dm_info/verify_message.rb +17 -0
  66. data/lib/ruby_isds/web_services/dm_operations/authenticate_message.rb +17 -0
  67. data/lib/ruby_isds/web_services/dm_operations/create_message.rb +30 -0
  68. data/lib/ruby_isds/web_services/dm_operations/create_multiple_messages.rb +30 -0
  69. data/lib/ruby_isds/web_services/dm_operations/message_download.rb +25 -0
  70. data/lib/ruby_isds/web_services/dm_operations/ping.rb +15 -0
  71. data/lib/ruby_isds/web_services/dm_operations/request.rb +19 -0
  72. data/lib/ruby_isds/web_services/dm_operations/resign_isds_document.rb +17 -0
  73. data/lib/ruby_isds/web_services/dm_operations/response.rb +13 -0
  74. data/lib/ruby_isds/web_services/dm_operations/signed_message_download.rb +17 -0
  75. data/lib/ruby_isds/web_services/dm_operations/signed_sent_message_download.rb +17 -0
  76. data/ruby_isds.gemspec +47 -0
  77. data/wercker.yml +12 -0
  78. metadata +303 -0
@@ -0,0 +1,105 @@
1
+ module RubyIsds
2
+ class Request
3
+ def initialize(params = {})
4
+ params.each do |k, v|
5
+ instance_variable_set("@#{k}", v)
6
+ end if params.any?
7
+ end
8
+
9
+ def self.call(params = {})
10
+ new(params).call
11
+ end
12
+
13
+ # rubocop:disable Metrics/AbcSize
14
+ def call
15
+ uri = URI(full_url)
16
+ request = Net::HTTP::Post.new(uri)
17
+ default_headers.each { |k, v| request[k] = v }
18
+ request.body = to_xml
19
+ request.basic_auth RubyIsds.configuration.username, RubyIsds.configuration.password
20
+ response = Net::HTTP.start(uri.hostname, uri.port,
21
+ use_ssl: uri.scheme == 'https') do |http|
22
+ http.request(request)
23
+ end
24
+ call_reponse_wrapper(response)
25
+ end
26
+ # rubocop:enable Metrics/AbcSize
27
+
28
+ def call_reponse_wrapper(response)
29
+ response_wrapper.new(response)
30
+ end
31
+
32
+ def default_headers
33
+ {
34
+ 'Content-Type' => 'text/xml;charset=UTF-8',
35
+ 'Accept-Encoding' => 'gzip,deflate'
36
+ }
37
+ end
38
+
39
+ def to_xml
40
+ Nokogiri::XML::Builder.new(encoding: 'utf-8') do |xml|
41
+ xml[:soapenv].Envelope(envelope_namespaces) do
42
+ xml[:soapenv].Header
43
+ xml[:soapenv].Body do
44
+ body(xml)
45
+ end
46
+ end
47
+ end.to_xml
48
+ end
49
+
50
+ def envelope_namespaces
51
+ {
52
+ 'xmlns:soapenv' => 'http://schemas.xmlsoap.org/soap/envelope/',
53
+ 'xmlns:v20' => xml_url
54
+ }
55
+ end
56
+
57
+ def full_url
58
+ "#{RubyIsds.configuration.api_domain}#{api_url}"
59
+ end
60
+
61
+ ##
62
+ # each subclass needs to have availbale attrs put in constant `ATTRS`
63
+ #
64
+ def values(xml)
65
+ self.class::ATTRS.each do |attribute|
66
+ value = instance_variable_get("@#{attribute}") || ''
67
+ xml[:v20].public_send(attribute, value)
68
+ end
69
+ end
70
+
71
+ ##
72
+ # Each subclass must implement
73
+ # this is whole body of message which differs and also needs to be
74
+ # accompanied with att_accessors
75
+ #
76
+ def body
77
+ raise NotImplementedError, "#{self.class} must implement #body!"
78
+ end
79
+
80
+ ##
81
+ # relative part of url because they differ...
82
+ # domain such as https://ws1.czebox.cz is take from config as such:
83
+ # `RubyIsds.configuration.api_domain`
84
+ # it includes `https://` so only ending is supposed to be here
85
+ #
86
+ def api_url
87
+ raise NotImplementedError, "#{self.class} must implement #api_url!"
88
+ end
89
+
90
+ ##
91
+ # URL will differ based on endpoint that it accesses
92
+ #
93
+ def xml_url
94
+ "http://#{RubyIsds.configuration.xml_url}"
95
+ end
96
+
97
+ ##
98
+ # Here you can change which response object will wrap the reponse
99
+ # reponse object has to inherit from `::RubyIsds::Response`
100
+ #
101
+ def response_wrapper
102
+ ::RubyIsds::Response
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,17 @@
1
+ module RubyIsds
2
+ class Response
3
+ attr_accessor :status, :body
4
+
5
+ def initialize(response)
6
+ @response = Hash.from_xml(response.body)
7
+ end
8
+
9
+ def parsed_body
10
+ @response['Envelope']['Body'][result_key]
11
+ end
12
+
13
+ def result_key
14
+ @response['Envelope']['Body'].first[0]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module RubyIsds
2
+ module Responses
3
+ class Body
4
+ def initialize(response)
5
+ (response.keys - self.class::REMOVED_KEYS).each do |key|
6
+ self.class.send(:attr_accessor, key.to_sym)
7
+ instance_variable_set("@#{key}", parsed_value(response[key]))
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def parsed_value(value)
14
+ return value unless value.is_a?(Hash)
15
+ value.keys.first == 'xsi:nil' && value.values.first == 'true' ? nil : false
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module RubyIsds
2
+ module Responses
3
+ class DataBox < Body
4
+ REMOVED_KEYS = %w[xmlns:p xmlns:xsi dbStatus].freeze
5
+
6
+ def initialize(response)
7
+ (response.keys - REMOVED_KEYS).each do |key|
8
+ self.class.send(:attr_accessor, key.to_sym)
9
+ instance_variable_set("@#{key}", response[key])
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module RubyIsds
2
+ module Responses
3
+ module Db
4
+ class Body < ::RubyIsds::Responses::Body
5
+ REMOVED_KEYS = %w[xmlns:p xmlns:xsi dbStatus].freeze
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module RubyIsds
2
+ module Responses
3
+ module Db
4
+ class Status < ::RubyIsds::Responses::Status
5
+ private
6
+
7
+ def namespace
8
+ 'db'
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module RubyIsds
2
+ module Responses
3
+ module Dm
4
+ class Body < ::RubyIsds::Responses::Body
5
+ REMOVED_KEYS = %w[xmlns:q xmlns:p xmlns:xsi dmStatus].freeze
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module RubyIsds
2
+ module Responses
3
+ module Dm
4
+ class Status < ::RubyIsds::Responses::Status
5
+ private
6
+
7
+ def namespace
8
+ 'dm'
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module RubyIsds
2
+ module Responses
3
+ class Message < ::RubyIsds::Response
4
+ def initialize(response)
5
+ super
6
+ end
7
+
8
+ def message
9
+ ::RubyIsds::DataMessage.new(message_hash)
10
+ end
11
+
12
+ private
13
+
14
+ def message_hash
15
+ hash = parsed_body['dmReturnedMessage']
16
+ hash['dmDm'].delete('xmlns:p')
17
+ hash
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ module RubyIsds
2
+ module Responses
3
+ module Messages
4
+ class Attachment
5
+ attr_accessor :file_type, :file_name, :encoded_content, :decoded_content
6
+
7
+ def initialize(hash)
8
+ @file_type = hash['dmMimeType']
9
+ @file_name = hash['dmFileDescr']
10
+ @encoded_content = hash['dmEncodedContent']
11
+ @decoded_content = Base64.decode64(@encoded_content)
12
+ end
13
+
14
+ def download(destination = '/tmp')
15
+ File.open("#{destination}/#{@file_name}", 'wb') do |f|
16
+ f.write(@decoded_content)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ module RubyIsds
2
+ module Responses
3
+ module Messages
4
+ class Collection < ::RubyIsds::Response
5
+ attr_accessor :messages
6
+
7
+ def initialize(response)
8
+ super
9
+ @messages = load_messages
10
+ @status = ::RubyIsds::Responses::Dm::Status.new(parsed_body)
11
+ end
12
+
13
+ def load_messages
14
+ return [::RubyIsds::DataMessage.new(results)] if results.is_a?(Hash)
15
+ results.map do |result|
16
+ ::RubyIsds::DataMessage.new(result)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def results
23
+ parsed_body['dmRecords']['dmRecord']
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ module RubyIsds
2
+ module Responses
3
+ module Messages
4
+ class DeliveryInfo < ::RubyIsds::Response
5
+ def initialize(response)
6
+ super
7
+ end
8
+
9
+ def message
10
+ ::RubyIsds::DataMessage.new(message_hash)
11
+ end
12
+
13
+ private
14
+
15
+ def message_hash
16
+ hash = parsed_body['dmDelivery']
17
+ hash['dmDm'].delete('xmlns:p')
18
+ hash
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module RubyIsds
2
+ module Responses
3
+ module Messages
4
+ class Envelope < ::RubyIsds::Response
5
+ def initialize(response)
6
+ super
7
+ end
8
+
9
+ def message
10
+ ::RubyIsds::DataMessage.new(message_hash)
11
+ end
12
+
13
+ private
14
+
15
+ def message_hash
16
+ hash = parsed_body['dmReturnedMessageEnvelope']
17
+ hash['dmDm'].delete('xmlns:p')
18
+ hash
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ module RubyIsds
2
+ module Responses
3
+ module Messages
4
+ class Event < ::RubyIsds::Response
5
+ attr_accessor :dmEventTime, :dmEventDescr
6
+
7
+ def initialize(hash)
8
+ @dmEventTime = hash['dmEventTime']
9
+ @dmEventDescr = hash['dmEventDescr']
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ module RubyIsds
2
+ module Responses
3
+ class Status
4
+ attr_accessor :code, :message
5
+
6
+ def initialize(response)
7
+ status = response["#{namespace}Status"]
8
+ @code = status["#{namespace}StatusCode"]
9
+ @message = status["#{namespace}StatusMessage"]
10
+ end
11
+
12
+ private
13
+
14
+ def namespace
15
+ raise NotImplementedError, "#{self.class} must implement #namespace!"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ module RubyIsds
2
+ class Error < StandardError; end
3
+
4
+ class ConfigNotSet < Error
5
+ def initialize(param)
6
+ msg = "Please check if you set #{param}, seems it is missing."
7
+ super(msg)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module RubyIsds
2
+ VERSION = '0.9.0'.freeze
3
+ end
File without changes
@@ -0,0 +1,21 @@
1
+ module RubyIsds
2
+ module WebServices
3
+ module DbAccess
4
+ class ChangeIsdsPassword < ::RubyIsds::WebServices::DbSearch::Request
5
+ ATTRS = %i[dbOldPassword dbNewPassword].freeze
6
+
7
+ attr_accessor(*ATTRS)
8
+
9
+ def body(xml)
10
+ xml[:v20].ChangeISDSPassword do
11
+ values(xml)
12
+ end
13
+ end
14
+
15
+ def api_url
16
+ '/DS/DsManage'
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module RubyIsds
2
+ module WebServices
3
+ module DbSearch
4
+ class CheckDataBox < ::RubyIsds::WebServices::DbSearch::Request
5
+ ATTRS = %i[dbID dbApproved dbExternRefNumber].freeze
6
+
7
+ attr_accessor(*ATTRS)
8
+
9
+ def body(xml)
10
+ xml[:v20].CheckDataBox do
11
+ values(xml)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module RubyIsds
2
+ module WebServices
3
+ module DbSearch
4
+ class DTInfo < ::RubyIsds::WebServices::DbSearch::Request
5
+ ATTRS = [:dbId].freeze
6
+
7
+ attr_accessor(*ATTRS)
8
+
9
+ def body(xml)
10
+ xml[:v20].DTInfo do
11
+ values(xml)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end