Class: IsbmAdaptor::ConsumerPublication

Inherits:
Client
  • Object
show all
Defined in:
lib/isbm_adaptor/consumer_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 = {}) ⇒ ConsumerPublication

Creates a new ISBM ConsumerPublication 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



13
14
15
# File 'lib/isbm_adaptor/consumer_publication.rb', line 13

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

Instance Method Details

#close_session(session_id) ⇒ void

This method returns an undefined value.

Closes a subscription session.

Parameters:

  • session_id (String)

    the session id

Raises:

  • (ArgumentError)

    if session_id is blank



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

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

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

  return true
end

#open_session(uri, topics, listener_url = nil, xpath_expression = nil, xpath_namespaces = []) ⇒ String

Opens a subscription session for a channel.

Parameters:

  • uri (String)

    the channel URI

  • topics (Array<String>, String)

    a collection of topics or single topic

  • listener_url (String) (defaults to: nil)

    the URL for notification callbacks

  • xpath_expression (String) (defaults to: nil)

    the XPath filter expression

  • xpath_namespaces (Array<Hash>) (defaults to: [])

    the prefixes and namespaces used by the XPath expression. The hash key represents the namespace prefix while the value represents the namespace name. For example,

    “xs” => “www.w3.org/2001/XMLSchema”, “isbm” => “www.openoandm.org/xml/ISBM/”

Returns:

  • (String)

    the session id

Raises:

  • (ArgumentError)

    if uri or topics are blank



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/isbm_adaptor/consumer_publication.rb', line 28

def open_session(uri, topics, listener_url = nil, xpath_expression = nil, xpath_namespaces = [])
  validate_presence_of uri, 'Channel URI'
  validate_presence_of topics, 'Topics'
  validate_presence_of xpath_expression, 'XPath Expression' if xpath_namespaces.present?

  topics = [topics].flatten

  # Use Builder to generate XML body as we may have multiple Topic elements
  xml = Builder::XmlMarkup.new
  xml.isbm :ChannelURI, uri
  topics.each do |topic|
    xml.isbm :Topic, topic
  end
  xml.isbm :ListenerURL, listener_url unless listener_url.nil?
  xml.isbm :XPathExpression, xpath_expression unless xpath_expression.nil?
  xpath_namespaces.each do |prefix, name|
    xml.isbm :XPathNamespace do
      xml.isbm :NamespacePrefix, prefix
      xml.isbm :NamespaceName, name
    end
  end

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

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

#read_publication(session_id) ⇒ Message

Reads the first message, if any, in the session queue.

Parameters:

  • session_id (String)

    the session id

Returns:

  • (Message)

    first message in session queue. nil if no message.

Raises:

  • (ArgumentError)

    if session_id is blank



60
61
62
63
64
65
66
# File 'lib/isbm_adaptor/consumer_publication.rb', line 60

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

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

  extract_message(response)
end

#remove_publication(session_id) ⇒ void

This method returns an undefined value.

Removes the first message, if any, in the session queue.

Parameters:

  • session_id (String)

    the session id

Raises:

  • (ArgumentError)

    if session_id is blank



73
74
75
76
77
78
79
# File 'lib/isbm_adaptor/consumer_publication.rb', line 73

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

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

  return true
end