Class: IsbmAdaptor::ProviderPublication

Inherits:
Client
  • Object
show all
Defined in:
lib/isbm_adaptor/provider_publication.rb

Instance Method Summary collapse

Methods inherited from Client

#extract_message, #validate_inclusion_in, #validate_presence_of, #validate_xml

Constructor Details

#initialize(endpoint, options = {}) ⇒ ProviderPublication

Creates a new ISBM ProviderPublication client.

Parameters:

  • endpoint (String)

    the SOAP endpoint URI

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :wsse_auth (Array<String>)

    username and password, i.e. [username, password]

  • :logger (Object) — default: Rails.logger or $stdout

    location where log should be output

  • :log (Boolean) — default: true

    specify whether requests are logged

  • :pretty_print_xml (Boolean) — default: false

    specify whether request and response XML are formatted



14
15
16
# File 'lib/isbm_adaptor/provider_publication.rb', line 14

def initialize(endpoint, options = {})
  super('ProviderPublicationService.wsdl', endpoint, options)
end

Instance Method Details

#close_session(session_id) ⇒ void

This method returns an undefined value.

Closes a publication session.

Parameters:

  • session_id (String)

    the session id

Raises:

  • (ArgumentError)

    if session_id is blank



85
86
87
88
89
90
91
# File 'lib/isbm_adaptor/provider_publication.rb', line 85

def close_session(session_id)
  validate_presence_of session_id, 'Session Id'

  @client.call(:close_publication_session, message: { 'SessionID' => session_id })

  return true
end

#expire_publication(session_id, message_id) ⇒ void

This method returns an undefined value.

Expires a posted publication message.

Parameters:

  • session_id (String)

    the session id used to post the publication

  • message_id (String)

    the message id received after posting the publication

Raises:

  • (ArgumentError)

    if session_id or message_id are blank



71
72
73
74
75
76
77
78
# File 'lib/isbm_adaptor/provider_publication.rb', line 71

def expire_publication(session_id, message_id)
  validate_presence_of session_id, 'Session Id'
  validate_presence_of message_id, 'Message Id'

  @client.call(:expire_publication, message: { 'SessionID' => session_id, 'MessageID' => message_id })

  return true
end

#open_session(uri) ⇒ String

Opens a publication session for a channel.

Parameters:

  • uri (String)

    the channel URI

Returns:

  • (String)

    the session id

Raises:

  • (ArgumentError)

    if uri is blank



23
24
25
26
27
28
29
# File 'lib/isbm_adaptor/provider_publication.rb', line 23

def open_session(uri)
  validate_presence_of uri, 'Channel URI'

  response = @client.call(:open_publication_session, message: { 'ChannelURI' => uri })

  response.to_hash[:open_publication_session_response][:session_id].to_s
end

#post_publication(session_id, content, topics, expiry = nil) ⇒ String

Posts a publication message.

Parameters:

  • session_id (String)

    the session id

  • content (String)

    a valid XML string as message contents

  • topics (Array<String>, String)

    a collection of topics or single topic

  • expiry (Duration) (defaults to: nil)

    when the message should expire

Returns:

  • (String)

    the message id

Raises:

  • (ArgumentError)

    if session_id, content or topics are blank, or content is not valid XML



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/isbm_adaptor/provider_publication.rb', line 40

def post_publication(session_id, content, topics, expiry = nil)
  validate_presence_of session_id, 'Session Id'
  validate_presence_of content, 'Content'
  validate_presence_of topics, 'Topics'
  validate_xml content

  topics = [topics].flatten

  # Use Builder to generate XML body as we need to concatenate XML message content
  xml = Builder::XmlMarkup.new
  xml.isbm :SessionID, session_id
  xml.isbm :MessageContent do
    xml << content
  end
  topics.each do |topic|
    xml.isbm :Topic, topic
  end
  duration = expiry.to_s
  xml.isbm :Expiry, duration unless duration.nil?

  response = @client.call(:post_publication, message: xml.target!)

  response.to_hash[:post_publication_response][:message_id].to_s
end