Class: WebexXmlApi::SecurityContext

Inherits:
Object
  • Object
show all
Defined in:
lib/webex_xml_api/security_context.rb

Overview

SecurityContext class is shared among other API calls and is providing the WebEx XML API Service with user credentials for authentification.

Constant Summary collapse

PARAMETER_MAPPING =

Allowed parameters in the SecurityContext class.

{
  webex_id: 'webExID',
  password: 'password',
  site_id: 'siteID',
  site_name: 'siteName',
  partner_id: 'partnerID',
  email: 'email',
  session_ticket: 'sessionTicket',
  client_id: 'clientID',
  client_secret: 'clientSecret'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ SecurityContext

The initialize method for newly created instance parsing provided parameters (if any).



26
27
28
29
30
# File 'lib/webex_xml_api/security_context.rb', line 26

def initialize(attributes = {})
  attributes.each_pair do |k, v|
    send("#{k}=", v) if PARAMETER_MAPPING.key?(k)
  end
end

Instance Method Details

#to_xmlObject

The to_xml method returns XML representation of the SecurityContext instance as understood by the WebEx XML Service.

Raises:



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/webex_xml_api/security_context.rb', line 36

def to_xml
  raise WebexXmlApi::NotEnoughArguments, 'SecurityContext' unless valid?
  builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
    xml.header do
      xml.securityContext do
        PARAMETER_MAPPING.each_pair do |k, v|
          xml.send(v, send(k)) if send(k)
        end
      end
    end
  end
  builder.to_xml.gsub("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", '')
end

#valid?(context = self) ⇒ Boolean

Returns true if required parameters provided, otherwise false. Parameters :site_name and :webex_id are required. One of the parameters :password or :session_ticket are required too.

Returns:



55
56
57
58
59
# File 'lib/webex_xml_api/security_context.rb', line 55

def valid?(context = self)
  return false if context.site_name.nil? || context.webex_id.nil?
  return false if context.password.nil? && context.session_ticket.nil?
  true
end