Skip to content

Instantly share code, notes, and snippets.

@bjhaid
Created July 27, 2011 16:43
Show Gist options
  • Save bjhaid/1109780 to your computer and use it in GitHub Desktop.
Save bjhaid/1109780 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'typhoeus'
require 'json'
request = Typhoeus::Request.new("http://10.10.5.240/json",:username => 'admin', :password => 'Passw0rd',
:body => "{'request': {'method': 'switchvox.extensions.getInfo', 'parameters' {'extensions': [ '5001' ]}}
}",
:headers => {'Content-Type' => 'application/json',:Accept => "application/json"},
:method => :post)
hydra = Typhoeus::Hydra.new
hydra.queue(request)
hydra.run
response = request.response
puts response.body # the response bod
puts response.headers
Expected Response:
response.xml
<response method="switchvox.extensions.getInfo">
<result>
<extensions>
<extension server_uuid="9037379394450317312" number="5001" status="1" account_id="1133" display="Obinna Ekezie" date_created="2011-07-14 09:48:29" type="sip" type_display="SIP Extension" first_name="Obinna" last_name="Ekezie" email_address="[email protected]" template_id="1" template_name="" phone_password_score="104" voicemail_password_score="0" lang_locale="en_us" title="" location="" profile_image_id="0" profile_image_link="https://10.10.5.240/dl?cmd=profile_image&amp;amp;cs=0&amp;amp;id=0&amp;amp;hash=de6de8233830fdc935aae4ffe7003a85" />
</extensions>
</result>
</response>
~
Actual Response:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://10.10.5.240/json">here</a>.</p>
</body></html>
#<Typhoeus::Response:0x9e82368 @code=0, @curl_return_code=60, @curl_error_message="Peer certificate cannot be authenticated with known CA certificates", @status_message=nil, @http_version=nil, @headers="", @body="", @time=0.012062, @requested_url=nil, @requested_http_method=nil, @start_time=nil, @start_transfer_time=0.0, @app_connect_time=0.0, @pretransfer_time=0.0, @connect_time=0.000894, @name_lookup_time=0.000508, @request=:method => :post,
:url => https://10.10.5.240/json,
:body => "{'request': {'method': 'switchvox.extensions.getInfo', 'parameters' {'extensions': [ '5001' ]}}\n}",
:headers => {"Accept"=>"text/html", "User-Agent"=>"Typhoeus - http://github.com/dbalatero/typhoeus/tree/master"}, @effective_url="https://10.10.5.240/json", @mock=false>
@noeticpenguin
Copy link

request = Typhoeus::Request.new("http://10.10.5.240/admin/json",:username => 'admin', :password => 'Passw0rd',
:body => "{'request': {'method': 'switchvox.extensions.getInfo', 'parameters' {'extensions': [ '5001' ]}}
}",
:headers => {'Content-Type' => 'application/json', 'Accepts' => 'application/json'},
:method => :post
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment