Class: WebexApi::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/webex_api/request.rb

Direct Known Subclasses

MeetingRequest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Request

Returns a new instance of Request.



4
5
6
7
8
# File 'lib/webex_api/request.rb', line 4

def initialize(client)
  @client = client
  @success = false

end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



3
4
5
# File 'lib/webex_api/request.rb', line 3

def client
  @client
end

#errorObject

Returns the value of attribute error.



3
4
5
# File 'lib/webex_api/request.rb', line 3

def error
  @error
end

#successObject

Returns the value of attribute success.



3
4
5
# File 'lib/webex_api/request.rb', line 3

def success
  @success
end

#xml_responseObject

Returns the value of attribute xml_response.



3
4
5
# File 'lib/webex_api/request.rb', line 3

def xml_response
  @xml_response
end

Instance Method Details

#perform_request(body) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/webex_api/request.rb', line 34

def perform_request(body)
  
  uri = URI.parse("https://#{@client.site_name}.webex.com")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  response = http.post('/WBXService/XMLService', body)
  xml_data = Nokogiri::XML(response.body).remove_namespaces!
  if xml_data.at_xpath('/message/header/response/result') && xml_data.at_xpath('/message/header/response/result').text == 'SUCCESS'
    @success = true
    @xml_response = xml_data.at_xpath('/message/body/bodyContent')
  else
    @error = xml_data.at_xpath('/message/header/response/reason').text rescue "error"
    raise WebexApi::WebexError.new(@error)
  end
end

#webex_xml_request(email = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/webex_api/request.rb', line 9

def webex_xml_request(email=nil)
  Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
    xml.message('xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
                        'xmlns:serv' =>  "http://www.webex.com/schemas/2002/06/service",
                        'xsi:schemaLocation' => "http://www.webex.com/schemas/2002/06/service"){
      xml.parent.namespace = xml.parent.namespace_definitions.find{|ns|ns.prefix=="serv"}
      xml.header{
        xml.parent.namespace = xml.parent.namespace_definitions.first
        xml.securityContext {
          xml.webExID @client.webex_id
          xml.password @client.webex_password
          xml.siteID @client.site_id
          xml.partnerID @client.partner_id if !!@client.partner_id
          xml.email email if !!email
        }
      }
      xml.body{
        xml.parent.namespace = xml.parent.namespace_definitions.first
        yield xml
      }
    }
  end.to_xml
end