I concede - I tried to crack this nut for several hours, but I canโt understand. I'm too new to Ruby (and I don't have a Python background!) To translate this, and then post my JSON data to a site that requires a user / password, and then get the response data.
This is the Python code:
r = requests.post('https://keychain.oneid.com/validate/', json.dumps(data), auth=('username', 'password')) r.json()
where data :
{"some" => "data", "fun" => "times"}
I am trying to replicate the functionality of this code in Ruby for use with a Rails application, but between finding out how the Python requests.post() function works and then writing the Ruby code for POST and GET, I got completely lost.
I tried Net :: HTTP, but I donโt understand if I should put the username / password in the body or use the basic_auth method - basic_auth seems to work only inside Net::HTTP.get ... and Net :: HTTP, it seems does not cope with JSON, but then again, I could be completely ready for dinner at this point.
Any suggestions or help would be greatly appreciated!
source share