module WebexXmlApi::Common
The Common
module is a collection of methods used by many other modules and it is being included within those.
Public Instance Methods
check_response_and_return_data(resp)
click to toggle source
The check_response_and_return_data
method checks the WebEx Response status and raises WebexXmlApi::RequestFailed
Exception if status is otherwise than SUCCESS. If the request was successful than the parsed Response Hash is returned.
# File lib/webex_xml_api/common.rb, line 22 def check_response_and_return_data(resp) status = resp.parsed_response['message']['header']['response']['result'] return resp.parsed_response['message']['body']['bodyContent'] if status == 'SUCCESS' c = resp.parsed_response['message']['header']['response']['exceptionID'] t = resp.parsed_response['message']['header']['response']['reason'] raise WebexXmlApi::RequestFailed.new(resp), "Error #{c}: #{t}" end
create_xml_request(sec_context, req_type, body_content)
click to toggle source
The create_xml_request
method creates a XML formatted document as understood by WebEx XML API Service including the Security Context.
# File lib/webex_xml_api/common.rb, line 35 def create_xml_request(sec_context, req_type, body_content) namespaces = { 'xmlns:serv' => 'http://www.webex.com/schemas/2002/06/service', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation' => 'http://www.webex.com/schemas/2002/06/service' }.freeze builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| xml.message(namespaces) do xml.<< sec_context xml.body do process_object('bodyContent', body_content, xml, req_type) end end end builder.doc.root.name = 'serv:message' builder.to_xml.gsub(%r{(<\w+\/>)}, '') end
post_webex_request(site_name, request)
click to toggle source
The post_webex_request
method sends the request to WebEx XML Service.
# File lib/webex_xml_api/common.rb, line 10 def post_webex_request(site_name, request) endpoint = "https://#{site_name}.webex.com/WBXService/XMLService".freeze HTTParty.post(endpoint, body: request, headers: { 'Content-Type' => 'application/xml' }) end