Class: WebexXmlApi::SecurityContext
- Inherits:
-
Object
- Object
- WebexXmlApi::SecurityContext
- 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
-
#initialize(attributes = {}) ⇒ SecurityContext
constructor
The
initializemethod for newly created instance parsing provided parameters (if any). -
#to_xml ⇒ Object
The
to_xmlmethod returns XML representation of theSecurityContextinstance as understood by the WebEx XML Service. -
#valid?(context = self) ⇒ Boolean
Returns true if required parameters provided, otherwise false.
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_xml ⇒ Object
The to_xml method returns XML representation of the SecurityContext instance as understood by the WebEx XML Service.
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.
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 |