isbm_adaptor 1.0.rc8.6 → 1.0.rc8.7
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/LICENSE +9 -9
- data/README.md +133 -59
- data/lib/isbm_adaptor/channel.rb +38 -37
- data/lib/isbm_adaptor/channel_management.rb +78 -78
- data/lib/isbm_adaptor/client.rb +93 -86
- data/lib/isbm_adaptor/consumer_publication.rb +71 -71
- data/lib/isbm_adaptor/consumer_request.rb +109 -109
- data/lib/isbm_adaptor/duration.rb +88 -88
- data/lib/isbm_adaptor/message.rb +23 -23
- data/lib/isbm_adaptor/provider_publication.rb +92 -92
- data/lib/isbm_adaptor/provider_request.rb +110 -110
- data/lib/isbm_adaptor/version.rb +4 -3
- data/lib/isbm_adaptor.rb +12 -12
- data/wsdls/ISBMConsumerRequestService.wsdl +348 -348
- data/wsdls/ISBMProviderRequestService.wsdl +375 -375
- metadata +29 -31
@@ -1,71 +1,71 @@
|
|
1
|
-
require 'isbm_adaptor/client'
|
2
|
-
|
3
|
-
module IsbmAdaptor
|
4
|
-
class ConsumerPublication < IsbmAdaptor::Client
|
5
|
-
|
6
|
-
# Creates a new ISBM ConsumerPublication client.
|
7
|
-
#
|
8
|
-
# @param endpoint [String] the SOAP endpoint URI
|
9
|
-
# @option options [Object] :logger (Rails.logger or $stdout) location where log should be output
|
10
|
-
# @option options [Boolean] :log (true) specify whether requests are logged
|
11
|
-
# @option options [Boolean] :pretty_print_xml (false) specify whether request and response XML are formatted
|
12
|
-
def initialize(endpoint, options = {})
|
13
|
-
super('ISBMConsumerPublicationService.wsdl', endpoint, options)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Opens a subscription session for a channel.
|
17
|
-
#
|
18
|
-
# @param uri [String] the channel URI
|
19
|
-
# @param topics [Array<String>] an array of topics
|
20
|
-
# @param listener_uri [String] the URI for notification callbacks
|
21
|
-
# @return [String] the session id
|
22
|
-
# @raise [ArgumentError] if uri or topics are
|
23
|
-
def open_session(uri, topics, listener_uri = nil)
|
24
|
-
validate_presence_of uri, 'Channel URI'
|
25
|
-
validate_presence_of topics, 'Topics'
|
26
|
-
|
27
|
-
# Use Builder to generate XML body as we may have multiple Topic elements
|
28
|
-
xml = Builder::XmlMarkup.new
|
29
|
-
xml.isbm :ChannelURI, uri
|
30
|
-
topics.each do |topic|
|
31
|
-
xml.isbm :Topic, topic
|
32
|
-
end
|
33
|
-
xml.isbm :ListenerURI, listener_uri unless listener_uri.nil?
|
34
|
-
|
35
|
-
response = @client.call(:open_subscription_session, message: xml.target!)
|
36
|
-
|
37
|
-
response.to_hash[:open_subscription_session_response][:session_id].to_s
|
38
|
-
end
|
39
|
-
|
40
|
-
# Reads the first message after the specified last message in the message
|
41
|
-
# queue.
|
42
|
-
#
|
43
|
-
# @param session_id [String] the session id
|
44
|
-
# @param last_message_id [String] the id of the last message. When set to
|
45
|
-
# nil, returns the first publication in the message queue
|
46
|
-
# @return [Message] first message after specified last message. nil if no message.
|
47
|
-
# @raise [ArgumentError] if session_id is
|
48
|
-
def read_publication(session_id, last_message_id)
|
49
|
-
validate_presence_of session_id, 'Session Id'
|
50
|
-
|
51
|
-
message = { 'SessionID' => session_id }
|
52
|
-
message['LastMessageID'] = last_message_id unless last_message_id.nil?
|
53
|
-
response = @client.call(:read_publication, message: message)
|
54
|
-
|
55
|
-
extract_message(response)
|
56
|
-
end
|
57
|
-
|
58
|
-
# Closes a subscription session.
|
59
|
-
#
|
60
|
-
# @param session_id [String] the session id
|
61
|
-
# @return [void]
|
62
|
-
# @raise [ArgumentError] if session_id is
|
63
|
-
def close_session(session_id)
|
64
|
-
validate_presence_of session_id, 'Session Id'
|
65
|
-
|
66
|
-
@client.call(:close_subscription_session, message: { 'SessionID' => session_id })
|
67
|
-
|
68
|
-
return true
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
1
|
+
require 'isbm_adaptor/client'
|
2
|
+
|
3
|
+
module IsbmAdaptor
|
4
|
+
class ConsumerPublication < IsbmAdaptor::Client
|
5
|
+
|
6
|
+
# Creates a new ISBM ConsumerPublication client.
|
7
|
+
#
|
8
|
+
# @param endpoint [String] the SOAP endpoint URI
|
9
|
+
# @option options [Object] :logger (Rails.logger or $stdout) location where log should be output
|
10
|
+
# @option options [Boolean] :log (true) specify whether requests are logged
|
11
|
+
# @option options [Boolean] :pretty_print_xml (false) specify whether request and response XML are formatted
|
12
|
+
def initialize(endpoint, options = {})
|
13
|
+
super('ISBMConsumerPublicationService.wsdl', endpoint, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Opens a subscription session for a channel.
|
17
|
+
#
|
18
|
+
# @param uri [String] the channel URI
|
19
|
+
# @param topics [Array<String>] an array of topics
|
20
|
+
# @param listener_uri [String] the URI for notification callbacks
|
21
|
+
# @return [String] the session id
|
22
|
+
# @raise [ArgumentError] if uri or topics are blank
|
23
|
+
def open_session(uri, topics, listener_uri = nil)
|
24
|
+
validate_presence_of uri, 'Channel URI'
|
25
|
+
validate_presence_of topics, 'Topics'
|
26
|
+
|
27
|
+
# Use Builder to generate XML body as we may have multiple Topic elements
|
28
|
+
xml = Builder::XmlMarkup.new
|
29
|
+
xml.isbm :ChannelURI, uri
|
30
|
+
topics.each do |topic|
|
31
|
+
xml.isbm :Topic, topic
|
32
|
+
end
|
33
|
+
xml.isbm :ListenerURI, listener_uri unless listener_uri.nil?
|
34
|
+
|
35
|
+
response = @client.call(:open_subscription_session, message: xml.target!)
|
36
|
+
|
37
|
+
response.to_hash[:open_subscription_session_response][:session_id].to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
# Reads the first message after the specified last message in the message
|
41
|
+
# queue.
|
42
|
+
#
|
43
|
+
# @param session_id [String] the session id
|
44
|
+
# @param last_message_id [String] the id of the last message. When set to
|
45
|
+
# nil, returns the first publication in the message queue
|
46
|
+
# @return [Message] first message after specified last message. nil if no message.
|
47
|
+
# @raise [ArgumentError] if session_id is blank
|
48
|
+
def read_publication(session_id, last_message_id)
|
49
|
+
validate_presence_of session_id, 'Session Id'
|
50
|
+
|
51
|
+
message = { 'SessionID' => session_id }
|
52
|
+
message['LastMessageID'] = last_message_id unless last_message_id.nil?
|
53
|
+
response = @client.call(:read_publication, message: message)
|
54
|
+
|
55
|
+
extract_message(response)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Closes a subscription session.
|
59
|
+
#
|
60
|
+
# @param session_id [String] the session id
|
61
|
+
# @return [void]
|
62
|
+
# @raise [ArgumentError] if session_id is blank
|
63
|
+
def close_session(session_id)
|
64
|
+
validate_presence_of session_id, 'Session Id'
|
65
|
+
|
66
|
+
@client.call(:close_subscription_session, message: { 'SessionID' => session_id })
|
67
|
+
|
68
|
+
return true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -1,109 +1,109 @@
|
|
1
|
-
require 'isbm_adaptor/client'
|
2
|
-
|
3
|
-
module IsbmAdaptor
|
4
|
-
class ConsumerRequest < IsbmAdaptor::Client
|
5
|
-
|
6
|
-
# Creates a new ISBM ConsumerRequest client.
|
7
|
-
#
|
8
|
-
# @param endpoint [String] the SOAP endpoint URI
|
9
|
-
# @option options [Object] :logger (Rails.logger or $stdout) location where log should be output
|
10
|
-
# @option options [Boolean] :log (true) specify whether requests are logged
|
11
|
-
# @option options [Boolean] :pretty_print_xml (false) specify whether request and response XML are formatted
|
12
|
-
def initialize(endpoint, options = {})
|
13
|
-
super('ISBMConsumerRequestService.wsdl', endpoint, options)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Opens a consumer request session for a channel for posting requests and
|
17
|
-
# reading responses.
|
18
|
-
#
|
19
|
-
# @param uri [String] the channel URI
|
20
|
-
# @param listener_uri [String] the URI for notification callbacks
|
21
|
-
# @return [String] the session id
|
22
|
-
# @raise [ArgumentError] if uri is
|
23
|
-
def open_session(uri, listener_uri = nil)
|
24
|
-
validate_presence_of uri, 'Channel URI'
|
25
|
-
|
26
|
-
message = { 'ChannelURI' => uri }
|
27
|
-
message['ListenerURI'] = listener_uri if listener_uri
|
28
|
-
|
29
|
-
response = @client.call(:open_consumer_request_session, message: message)
|
30
|
-
|
31
|
-
response.to_hash[:open_consumer_request_session_response][:session_id].to_s
|
32
|
-
end
|
33
|
-
|
34
|
-
# Posts a request message on a channel.
|
35
|
-
#
|
36
|
-
# @param session_id [String] the session id
|
37
|
-
# @param content [String] a valid XML string as message contents
|
38
|
-
# @param topic [String] the topic
|
39
|
-
# @return [String] the request message id
|
40
|
-
# @raise [ArgumentError] if session_id, content or topics are
|
41
|
-
# content is not valid XML
|
42
|
-
def post_request(session_id, content, topic)
|
43
|
-
validate_presence_of session_id, 'Session Id'
|
44
|
-
validate_presence_of content, 'Content'
|
45
|
-
validate_presence_of topic, 'Topic'
|
46
|
-
validate_xml content
|
47
|
-
|
48
|
-
# Use Builder to generate XML body as we need to concatenate XML message content
|
49
|
-
xml = Builder::XmlMarkup.new
|
50
|
-
xml.isbm :SessionID, session_id
|
51
|
-
xml.isbm :MessageContent do
|
52
|
-
xml << content
|
53
|
-
end
|
54
|
-
xml.isbm :Topic, topic
|
55
|
-
|
56
|
-
response = @client.call(:post_request, message: xml.target!)
|
57
|
-
|
58
|
-
response.to_hash[:post_request_response][:message_id].to_s
|
59
|
-
end
|
60
|
-
|
61
|
-
# Returns the first response message, if any, in the message queue
|
62
|
-
# associated with the request.
|
63
|
-
#
|
64
|
-
# @param session_id [String] the session id
|
65
|
-
# @param request_message_id [String] the id of the original request message
|
66
|
-
# @return [Message] the first message in the queue for the session.
|
67
|
-
# nil if no message.
|
68
|
-
# @raise [ArgumentError] if session_id or request_message_id are
|
69
|
-
def read_response(session_id, request_message_id)
|
70
|
-
validate_presence_of session_id, 'Session Id'
|
71
|
-
validate_presence_of request_message_id, 'Request Message Id'
|
72
|
-
|
73
|
-
message = { 'SessionID' => session_id, 'RequestMessageID' => request_message_id }
|
74
|
-
response = @client.call(:read_response, message: message)
|
75
|
-
|
76
|
-
extract_message(response)
|
77
|
-
end
|
78
|
-
|
79
|
-
# Deletes the first response message, if any, in the message queue
|
80
|
-
# associated with the request.
|
81
|
-
#
|
82
|
-
# @param session_id [String] the session id
|
83
|
-
# @param request_message_id [String] the id of the original request message
|
84
|
-
# @return [void]
|
85
|
-
# @raise [ArgumentError] if session_id is
|
86
|
-
def remove_response(session_id, request_message_id)
|
87
|
-
validate_presence_of session_id, 'Session Id'
|
88
|
-
validate_presence_of request_message_id, 'Request Message Id'
|
89
|
-
|
90
|
-
message = { 'SessionID' => session_id, 'RequestMessageID' => request_message_id }
|
91
|
-
@client.call(:remove_response, message: message)
|
92
|
-
|
93
|
-
return true
|
94
|
-
end
|
95
|
-
|
96
|
-
# Closes a consumer request session.
|
97
|
-
#
|
98
|
-
# @param session_id [String] the session id
|
99
|
-
# @return [void]
|
100
|
-
# @raise [ArgumentError] if session_id is
|
101
|
-
def close_session(session_id)
|
102
|
-
validate_presence_of session_id, 'Session Id'
|
103
|
-
|
104
|
-
@client.call(:close_consumer_request_session, message: { 'SessionID' => session_id })
|
105
|
-
|
106
|
-
return true
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
1
|
+
require 'isbm_adaptor/client'
|
2
|
+
|
3
|
+
module IsbmAdaptor
|
4
|
+
class ConsumerRequest < IsbmAdaptor::Client
|
5
|
+
|
6
|
+
# Creates a new ISBM ConsumerRequest client.
|
7
|
+
#
|
8
|
+
# @param endpoint [String] the SOAP endpoint URI
|
9
|
+
# @option options [Object] :logger (Rails.logger or $stdout) location where log should be output
|
10
|
+
# @option options [Boolean] :log (true) specify whether requests are logged
|
11
|
+
# @option options [Boolean] :pretty_print_xml (false) specify whether request and response XML are formatted
|
12
|
+
def initialize(endpoint, options = {})
|
13
|
+
super('ISBMConsumerRequestService.wsdl', endpoint, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Opens a consumer request session for a channel for posting requests and
|
17
|
+
# reading responses.
|
18
|
+
#
|
19
|
+
# @param uri [String] the channel URI
|
20
|
+
# @param listener_uri [String] the URI for notification callbacks
|
21
|
+
# @return [String] the session id
|
22
|
+
# @raise [ArgumentError] if uri is blank
|
23
|
+
def open_session(uri, listener_uri = nil)
|
24
|
+
validate_presence_of uri, 'Channel URI'
|
25
|
+
|
26
|
+
message = { 'ChannelURI' => uri }
|
27
|
+
message['ListenerURI'] = listener_uri if listener_uri
|
28
|
+
|
29
|
+
response = @client.call(:open_consumer_request_session, message: message)
|
30
|
+
|
31
|
+
response.to_hash[:open_consumer_request_session_response][:session_id].to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
# Posts a request message on a channel.
|
35
|
+
#
|
36
|
+
# @param session_id [String] the session id
|
37
|
+
# @param content [String] a valid XML string as message contents
|
38
|
+
# @param topic [String] the topic
|
39
|
+
# @return [String] the request message id
|
40
|
+
# @raise [ArgumentError] if session_id, content or topics are blank, or
|
41
|
+
# content is not valid XML
|
42
|
+
def post_request(session_id, content, topic)
|
43
|
+
validate_presence_of session_id, 'Session Id'
|
44
|
+
validate_presence_of content, 'Content'
|
45
|
+
validate_presence_of topic, 'Topic'
|
46
|
+
validate_xml content
|
47
|
+
|
48
|
+
# Use Builder to generate XML body as we need to concatenate XML message content
|
49
|
+
xml = Builder::XmlMarkup.new
|
50
|
+
xml.isbm :SessionID, session_id
|
51
|
+
xml.isbm :MessageContent do
|
52
|
+
xml << content
|
53
|
+
end
|
54
|
+
xml.isbm :Topic, topic
|
55
|
+
|
56
|
+
response = @client.call(:post_request, message: xml.target!)
|
57
|
+
|
58
|
+
response.to_hash[:post_request_response][:message_id].to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns the first response message, if any, in the message queue
|
62
|
+
# associated with the request.
|
63
|
+
#
|
64
|
+
# @param session_id [String] the session id
|
65
|
+
# @param request_message_id [String] the id of the original request message
|
66
|
+
# @return [Message] the first message in the queue for the session.
|
67
|
+
# nil if no message.
|
68
|
+
# @raise [ArgumentError] if session_id or request_message_id are blank
|
69
|
+
def read_response(session_id, request_message_id)
|
70
|
+
validate_presence_of session_id, 'Session Id'
|
71
|
+
validate_presence_of request_message_id, 'Request Message Id'
|
72
|
+
|
73
|
+
message = { 'SessionID' => session_id, 'RequestMessageID' => request_message_id }
|
74
|
+
response = @client.call(:read_response, message: message)
|
75
|
+
|
76
|
+
extract_message(response)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Deletes the first response message, if any, in the message queue
|
80
|
+
# associated with the request.
|
81
|
+
#
|
82
|
+
# @param session_id [String] the session id
|
83
|
+
# @param request_message_id [String] the id of the original request message
|
84
|
+
# @return [void]
|
85
|
+
# @raise [ArgumentError] if session_id is blank
|
86
|
+
def remove_response(session_id, request_message_id)
|
87
|
+
validate_presence_of session_id, 'Session Id'
|
88
|
+
validate_presence_of request_message_id, 'Request Message Id'
|
89
|
+
|
90
|
+
message = { 'SessionID' => session_id, 'RequestMessageID' => request_message_id }
|
91
|
+
@client.call(:remove_response, message: message)
|
92
|
+
|
93
|
+
return true
|
94
|
+
end
|
95
|
+
|
96
|
+
# Closes a consumer request session.
|
97
|
+
#
|
98
|
+
# @param session_id [String] the session id
|
99
|
+
# @return [void]
|
100
|
+
# @raise [ArgumentError] if session_id is blank
|
101
|
+
def close_session(session_id)
|
102
|
+
validate_presence_of session_id, 'Session Id'
|
103
|
+
|
104
|
+
@client.call(:close_consumer_request_session, message: { 'SessionID' => session_id })
|
105
|
+
|
106
|
+
return true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -1,88 +1,88 @@
|
|
1
|
-
module IsbmAdaptor
|
2
|
-
class Duration
|
3
|
-
# @return [Numeric] the years component of the duration
|
4
|
-
attr_accessor :years
|
5
|
-
|
6
|
-
# @return [Numeric] the months component of the duration
|
7
|
-
attr_accessor :months
|
8
|
-
|
9
|
-
# @return [Numeric] the days component of the duration
|
10
|
-
attr_accessor :days
|
11
|
-
|
12
|
-
# @return [Numeric] the hours component of the duration
|
13
|
-
attr_accessor :hours
|
14
|
-
|
15
|
-
# @return [Numeric] the minutes component of the duration
|
16
|
-
attr_accessor :minutes
|
17
|
-
|
18
|
-
# @return [Numeric] the seconds component of the duration
|
19
|
-
attr_accessor :seconds
|
20
|
-
|
21
|
-
# Creates a new Duration based on specified time components.
|
22
|
-
#
|
23
|
-
# @option duration [Numeric] :years duration in years
|
24
|
-
# @option duration [Numeric] :months duration in months
|
25
|
-
# @option duration [Numeric] :days duration in days
|
26
|
-
# @option duration [Numeric] :hours duration in hours
|
27
|
-
# @option duration [Numeric] :minutes duration in minutes
|
28
|
-
# @option duration [Numeric] :seconds duration in seconds
|
29
|
-
def initialize(duration)
|
30
|
-
duration.keys.each do |key|
|
31
|
-
raise ArgumentError.new "Invalid key: #{key}" unless VALID_SYMBOLS.include?(key)
|
32
|
-
end
|
33
|
-
|
34
|
-
duration.each do |key, value|
|
35
|
-
raise ArgumentError.new "Value for #{key} cannot be less than 0" if value < 0
|
36
|
-
end
|
37
|
-
|
38
|
-
@years = duration[:years]
|
39
|
-
@months = duration[:months]
|
40
|
-
@days = duration[:days]
|
41
|
-
@hours = duration[:hours]
|
42
|
-
@minutes = duration[:minutes]
|
43
|
-
@seconds = duration[:seconds]
|
44
|
-
end
|
45
|
-
|
46
|
-
# @return [String] ISO 8601 formatted duration
|
47
|
-
def to_s
|
48
|
-
date = []
|
49
|
-
date << "#{@years}Y" unless @years.nil?
|
50
|
-
date << "#{@months}M" unless @months.nil?
|
51
|
-
date << "#{@days}D" unless @days.nil?
|
52
|
-
|
53
|
-
time = []
|
54
|
-
time << "#{@hours}H" unless @hours.nil?
|
55
|
-
time << "#{@minutes}M" unless @minutes.nil?
|
56
|
-
time << "#{@seconds}S" unless @seconds.nil?
|
57
|
-
|
58
|
-
result = nil
|
59
|
-
|
60
|
-
if !date.empty? || !time.empty?
|
61
|
-
result = 'P'
|
62
|
-
result += date.join unless date.empty?
|
63
|
-
result += 'T' + time.join unless time.empty?
|
64
|
-
end
|
65
|
-
|
66
|
-
result
|
67
|
-
end
|
68
|
-
|
69
|
-
# Creates a hash of the time components. Any keys with nil values are
|
70
|
-
# excluded from the result.
|
71
|
-
#
|
72
|
-
# @return [Hash] all specified time components
|
73
|
-
def to_hash
|
74
|
-
hash = {}
|
75
|
-
hash[:years] = @years if @years
|
76
|
-
hash[:months] = @months if @months
|
77
|
-
hash[:days] = @days if @days
|
78
|
-
hash[:hours] = @hours if @hours
|
79
|
-
hash[:minutes] = @minutes if @minutes
|
80
|
-
hash[:seconds] = @seconds if @seconds
|
81
|
-
hash
|
82
|
-
end
|
83
|
-
|
84
|
-
private
|
85
|
-
|
86
|
-
VALID_SYMBOLS = [:years, :months, :days, :hours, :minutes, :seconds]
|
87
|
-
end
|
88
|
-
end
|
1
|
+
module IsbmAdaptor
|
2
|
+
class Duration
|
3
|
+
# @return [Numeric] the years component of the duration
|
4
|
+
attr_accessor :years
|
5
|
+
|
6
|
+
# @return [Numeric] the months component of the duration
|
7
|
+
attr_accessor :months
|
8
|
+
|
9
|
+
# @return [Numeric] the days component of the duration
|
10
|
+
attr_accessor :days
|
11
|
+
|
12
|
+
# @return [Numeric] the hours component of the duration
|
13
|
+
attr_accessor :hours
|
14
|
+
|
15
|
+
# @return [Numeric] the minutes component of the duration
|
16
|
+
attr_accessor :minutes
|
17
|
+
|
18
|
+
# @return [Numeric] the seconds component of the duration
|
19
|
+
attr_accessor :seconds
|
20
|
+
|
21
|
+
# Creates a new Duration based on specified time components.
|
22
|
+
#
|
23
|
+
# @option duration [Numeric] :years duration in years
|
24
|
+
# @option duration [Numeric] :months duration in months
|
25
|
+
# @option duration [Numeric] :days duration in days
|
26
|
+
# @option duration [Numeric] :hours duration in hours
|
27
|
+
# @option duration [Numeric] :minutes duration in minutes
|
28
|
+
# @option duration [Numeric] :seconds duration in seconds
|
29
|
+
def initialize(duration)
|
30
|
+
duration.keys.each do |key|
|
31
|
+
raise ArgumentError.new "Invalid key: #{key}" unless VALID_SYMBOLS.include?(key)
|
32
|
+
end
|
33
|
+
|
34
|
+
duration.each do |key, value|
|
35
|
+
raise ArgumentError.new "Value for #{key} cannot be less than 0" if value < 0
|
36
|
+
end
|
37
|
+
|
38
|
+
@years = duration[:years]
|
39
|
+
@months = duration[:months]
|
40
|
+
@days = duration[:days]
|
41
|
+
@hours = duration[:hours]
|
42
|
+
@minutes = duration[:minutes]
|
43
|
+
@seconds = duration[:seconds]
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [String] ISO 8601 formatted duration
|
47
|
+
def to_s
|
48
|
+
date = []
|
49
|
+
date << "#{@years}Y" unless @years.nil?
|
50
|
+
date << "#{@months}M" unless @months.nil?
|
51
|
+
date << "#{@days}D" unless @days.nil?
|
52
|
+
|
53
|
+
time = []
|
54
|
+
time << "#{@hours}H" unless @hours.nil?
|
55
|
+
time << "#{@minutes}M" unless @minutes.nil?
|
56
|
+
time << "#{@seconds}S" unless @seconds.nil?
|
57
|
+
|
58
|
+
result = nil
|
59
|
+
|
60
|
+
if !date.empty? || !time.empty?
|
61
|
+
result = 'P'
|
62
|
+
result += date.join unless date.empty?
|
63
|
+
result += 'T' + time.join unless time.empty?
|
64
|
+
end
|
65
|
+
|
66
|
+
result
|
67
|
+
end
|
68
|
+
|
69
|
+
# Creates a hash of the time components. Any keys with nil values are
|
70
|
+
# excluded from the result.
|
71
|
+
#
|
72
|
+
# @return [Hash] all specified time components
|
73
|
+
def to_hash
|
74
|
+
hash = {}
|
75
|
+
hash[:years] = @years if @years
|
76
|
+
hash[:months] = @months if @months
|
77
|
+
hash[:days] = @days if @days
|
78
|
+
hash[:hours] = @hours if @hours
|
79
|
+
hash[:minutes] = @minutes if @minutes
|
80
|
+
hash[:seconds] = @seconds if @seconds
|
81
|
+
hash
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
# Valid time components in a duration
|
86
|
+
VALID_SYMBOLS = [:years, :months, :days, :hours, :minutes, :seconds]
|
87
|
+
end
|
88
|
+
end
|
data/lib/isbm_adaptor/message.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
module IsbmAdaptor
|
2
|
-
class Message
|
3
|
-
# @return [String] the id of the message
|
4
|
-
attr_accessor :id
|
5
|
-
|
6
|
-
# @return [
|
7
|
-
attr_accessor :content
|
8
|
-
|
9
|
-
# @return [Array<String>] topics associated with the message
|
10
|
-
attr_accessor :topics
|
11
|
-
|
12
|
-
# Creates a new ISBM Message container.
|
13
|
-
#
|
14
|
-
# @param id [String] message id
|
15
|
-
# @param content [
|
16
|
-
# @param topics [Array<String>, String] collection of topics or single topic
|
17
|
-
def initialize(id, content, topics)
|
18
|
-
@id = id
|
19
|
-
@content = content
|
20
|
-
@topics = [topics].flatten
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
1
|
+
module IsbmAdaptor
|
2
|
+
class Message
|
3
|
+
# @return [String] the id of the message
|
4
|
+
attr_accessor :id
|
5
|
+
|
6
|
+
# @return [Nokogiri::XML::Document] the XML content of the message
|
7
|
+
attr_accessor :content
|
8
|
+
|
9
|
+
# @return [Array<String>] topics associated with the message
|
10
|
+
attr_accessor :topics
|
11
|
+
|
12
|
+
# Creates a new ISBM Message container.
|
13
|
+
#
|
14
|
+
# @param id [String] message id
|
15
|
+
# @param content [Nokogiri::XML::Document] XML content
|
16
|
+
# @param topics [Array<String>, String] collection of topics or single topic
|
17
|
+
def initialize(id, content, topics)
|
18
|
+
@id = id
|
19
|
+
@content = content
|
20
|
+
@topics = [topics].flatten
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|