It has been a while since I have used Rails. I currently have a curl request as follows
curl -X GET -H 'Authorization: Element TOKEN, User TOKEN' 'https://api.cloud-elements.com/elements/api-v2/hubs/marketing/ping'
All I am looking to do is to be able to run this request from inside of a rails controller, but my lack of understanding when it comes to HTTP requests is preventing me from figuring it out to how best handle this. Thanks in advance.
It would be something like the following. Note that the connection will be blocking, so it can tie up your server depending on how quickly the remote host returns the HTTP response and how many of these requests you are making.
Once the block exits, you can use the
response
object as necessary. Theresponse
object is always a subclass (or subclass of a subclass) ofNet::HTTPResponse
and you can useresponse.is_a? Net::HTTPSuccess
to check for a 2xx response. The actual body of the response will be inresponse.body
as a String.Use this method for HTTP requests:
Your example will be: