Class: IsbmAdaptor::ChannelManagement

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

Instance Method Summary collapse

Methods inherited from Client

#extract_message, #validate_inclusion_in, #validate_presence_of, #validate_xml

Constructor Details

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

Creates a new ISBM ChannelManagement 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/channel_management.rb', line 13

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

Instance Method Details

#add_security_tokens(uri, tokens = {}) ⇒ void

This method returns an undefined value.

Adds security tokens to a channel.

Parameters:

  • uri (String)

    the channel URI

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

    username password pairs, e.g. => ‘p1’, ‘u2’ => ‘p2’

Raises:

  • (ArgumentError)

    if uri is blank or no tokens are provided



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/isbm_adaptor/channel_management.rb', line 47

def add_security_tokens(uri, tokens = {})
  validate_presence_of uri, 'Channel URI'
  validate_presence_of tokens, 'Security Tokens'

  message = { 'ChannelURI' => uri,
              'SecurityToken' => security_token_hash(tokens) }

  @client.call(:add_security_tokens, message: message)

  return true
end

#create_channel(uri, type, description = nil, tokens = {}) ⇒ void

This method returns an undefined value.

Creates a new channel.

Parameters:

  • uri (String)

    the channel URI

  • type (Symbol)

    the channel type, either publication or request (symbol or titleized string)

  • description (String) (defaults to: nil)

    the channel description, defaults to nil

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

    username password pairs, e.g. => ‘p1’, ‘u2’ => ‘p2’

Raises:

  • (ArgumentError)

    if uri or type are blank or type is not a valid Symbol



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/isbm_adaptor/channel_management.rb', line 25

def create_channel(uri, type, description = nil, tokens = {})
  validate_presence_of uri, 'Channel URI'
  validate_presence_of type, 'Channel Type'
  channel_type = type.to_s.downcase.capitalize
  validate_inclusion_in channel_type, IsbmAdaptor::Channel::TYPES, 'Channel Type'

  message = { 'ChannelURI' => uri,
              'ChannelType' => channel_type }
  message['ChannelDescription'] = description unless description.nil?
  message['SecurityToken'] = security_token_hash(tokens) if tokens.any?

  @client.call(:create_channel, message: message)

  return true
end

#delete_channel(uri) ⇒ void

This method returns an undefined value.

Deletes the specified channel.

Parameters:

  • uri (String)

    the channel URI

Raises:

  • (ArgumentError)

    if uri is blank



82
83
84
85
86
87
88
# File 'lib/isbm_adaptor/channel_management.rb', line 82

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

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

  return true
end

#get_channel(uri) { ... } ⇒ Channel

Gets information about the specified channel.

Parameters:

  • uri (String)

    the channel URI

Yields:

  • locals local options, including :wsse_auth

Returns:

  • (Channel)

    the queried channel

Raises:

  • (ArgumentError)

    if uri is blank



96
97
98
99
100
101
102
103
# File 'lib/isbm_adaptor/channel_management.rb', line 96

def get_channel(uri, &block)
  validate_presence_of uri, 'Channel URI'

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

  hash = response.to_hash[:get_channel_response][:channel]
  IsbmAdaptor::Channel.from_hash(hash)
end

#get_channels { ... } ⇒ Array<Channel>

Gets information about all channels.

Yields:

  • locals local options, including :wsse_auth

Returns:

  • (Array<Channel>)

    all authorized channels on the ISBM



109
110
111
112
113
114
115
116
117
# File 'lib/isbm_adaptor/channel_management.rb', line 109

def get_channels(&block)
  response = @client.call(:get_channels, {}, &block)

  channels = response.to_hash[:get_channels_response][:channel]
  channels = [channels].compact unless channels.is_a?(Array)
  channels.map do |hash|
    IsbmAdaptor::Channel.from_hash(hash)
  end
end

#remove_security_tokens(uri, tokens = {}) ⇒ void

This method returns an undefined value.

Removes security tokens from a channel.

Parameters:

  • uri (String)

    the channel URI

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

    username password pairs, e.g. => ‘p1’, ‘u2’ => ‘p2’

Raises:

  • (ArgumentError)

    if uri is blank or no tokens are provided



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/isbm_adaptor/channel_management.rb', line 65

def remove_security_tokens(uri, tokens = {})
  validate_presence_of uri, 'Channel URI'
  validate_presence_of tokens, 'Security Tokens'

  message = { 'ChannelURI' => uri,
              'SecurityToken' => security_token_hash(tokens) }

  @client.call(:remove_security_tokens, message: message)

  return true
end