Module: Bosh4r::Utils
- Included in:
- Session
- Defined in:
- lib/bosh4r/utils.rb
Instance Method Summary collapse
- #build_xml(options = {}, &callback) ⇒ Object
-
#send_bosh_request(url, params) ⇒ Object
Sends bosh request.
Instance Method Details
#build_xml(options = {}, &callback) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bosh4r/utils.rb', line 7 def build_xml( = {}, &callback) builder = Builder::XmlMarkup.new params = { :xmlns => 'http://jabber.org/protocol/httpbind', 'xmlns:xmpp' => 'urn:xmpp:xbosh' }.merge() if block_given? builder.body(params) { |body| yield(body) } else builder.body(params) end end |
#send_bosh_request(url, params) ⇒ Object
Sends bosh request
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bosh4r/utils.rb', line 23 def send_bosh_request(url, params) response = RestClient.post(url, params, { 'Content-Type' => 'text/xml; charset=utf-8', 'Accept' => 'text/xml' }) parsed_response = REXML::Document.new(response) terminate = (REXML::XPath.first parsed_response, '/body').attribute('type') == 'terminate' throw Bosh4r::Error.new 'Check your BOSH endpoint' if terminate parsed_response rescue => e throw Bosh4r::Error.new(e.) end |