Module: WebexXmlApi::Common
- Included in:
- Meeting::CreateMeeting, Meeting::DelMeeting, Meeting::GetMeeting, Meeting::GetjoinurlMeeting, User::GetUser
- Defined in:
- lib/webex_xml_api/common.rb
Overview
The Common module is a collection of methods used by many other modules and it is being included within those.
Instance Method Summary collapse
-
#check_response_and_return_data(resp) ⇒ Object
The
check_response_and_return_datamethod checks the WebEx Response status and raisesWebexXmlApi::RequestFailedException if status is otherwise than SUCCESS. -
#create_xml_request(sec_context, req_type, body_content) ⇒ Object
The
create_xml_requestmethod creates a XML formatted document as understood by WebEx XML API Service including the Security Context. -
#post_webex_request(site_name, request) ⇒ Object
The
post_webex_requestmethod sends the request to WebEx XML Service. -
#process_object(label, obj, xml, req_type) ⇒ Object
:nodoc:.
Instance Method Details
#check_response_and_return_data(resp) ⇒ Object
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.
22 23 24 25 26 27 28 29 |
# 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) ⇒ Object
The create_xml_request method creates a XML formatted document as understood by WebEx XML API Service including the Security Context.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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.(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) ⇒ Object
The post_webex_request method sends the request to WebEx XML Service.
10 11 12 13 14 |
# 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 |
#process_object(label, obj, xml, req_type) ⇒ Object
:nodoc:
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/webex_xml_api/common.rb', line 53 def process_object(label, obj, xml, req_type) # :nodoc: xml.send(label) do xml.parent['xsi:type'] = req_type if label == 'bodyContent' obj.each do |key, value| if value.is_a?(Array) || value.is_a?(Hash) process_object(key, value, xml, req_type) else xml.send(key, value) unless value.nil? end end end end |