Module: WebexXmlApi::Common
- Included in:
- Meeting::CreateMeeting, Meeting::DelMeeting, Meeting::GetMeeting, Meeting::GetjoinurlMeeting, User::GetUser
- Defined in:
- lib/webex_xml_api/common.rb
Instance Method Summary collapse
-
#check_response_and_return_data(resp) ⇒ Object
Check WebEx Response status and raise Exception if FAILURE.
-
#create_xml_request(sec_context, req_type, body_content) ⇒ Object
Create WebEx XML Request.
-
#post_webex_request(site_name, request) ⇒ Object
POST request to the WebEx XML Service.
- #process_object(label, obj, xml, req_type) ⇒ Object
Instance Method Details
#check_response_and_return_data(resp) ⇒ Object
Check WebEx Response status and raise Exception if FAILURE
11 12 13 14 15 16 17 18 |
# File 'lib/webex_xml_api/common.rb', line 11 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
Create WebEx XML Request
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/webex_xml_api/common.rb', line 21 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
POST request to the WebEx XML Service
4 5 6 7 8 |
# File 'lib/webex_xml_api/common.rb', line 4 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
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/webex_xml_api/common.rb', line 39 def process_object(label, obj, xml, req_type) 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 |