So I can successfully get a session token with my REST api like so:
uri = URI.parse("#{@restapi}/users/login/cloud")
response = Net::HTTP.post_form(uri, {"username" => "jason", "password" => "password123"})
It returns the following JSON:
{ "username" : "jason" , "token" : "1234sometoken567890" , "account" : "myaccount" , "profile" : "main"}
I need to use the token with my form data to call this function as stated in the APIs WADL:
<resource path="/removeProfile">
<method id="removeProfile" name="DELETE">
<request>
<representation mediaType="application/x-www-form-urlencoded">
<param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="a" style="query" type="xs:string"/>
<param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="p" style="query" type="xs:string"/>
</representation>
</request>
<response>
<representation mediaType="application/json"/>
</response>
</method>
</resource>
This tells me that I need to do the following in my REST call:
1) Request Method:DELETE
2) Form Data a= and p=
3) append the token to the url
In the browser it looks like: https://my.domain.com/rest/removeProfile?token=1234sometoken567890
with Form Data:
a=myaccount&p=someprofile
I tried this in Ruby:
uri = URI.parse("#{@rest}/removeProfile")
# get the token with the connection code
uri.query = URI.encode_www_form(utk: "#{@token}")
http = Net::HTTP.new(uri.host, uri.port)
http.set_form_data({"a" => "#{@account}", "p" => "#{@profile}"})
request = Net::HTTP::Delete.new(uri.path)
response = http.request(request)
Trying to mimic curl doing this (which doesn't work by the way):
curl -i -X DELETE "https://my.domain.com/rest/removeProfile?utk=1234sometoken567890&a=myaccount&p=someprofile"
What is the proper way to send a http DELETE method with Query String Parameters and form data?
NOTE:
Here is my current code:
def remove_profile(account, profile)
@account = account
@profile = profile
uri = URI.parse("#{@rest}/removeProfile")
http = Net::HTTP.new(uri.host, uri.port)
puts 'uri.path = ' + uri.path
request = Net::HTTP::Delete.new(uri.path)
request.body = "utk=#{@utk}&a=#{@account}&p=#{@profile}"
puts 'request.body = ' + request.body
response = http.request(request)
end
Ruby blows up with a stack trace like so:
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:153:in `read_nonblock': Connection reset by peer (Errno::ECONNRESET)
Any idea what I am doing wrong here?