I’m trying to use a super simple API from is.gd:
http://is.gd/api.php?longurl=http://www.example.com
Which returns a response header “HTTP/1.1 200 OK” if the URL was shortened as expected, or “HTTP/1.1 500 Internal Server Error” if there was any problem that prevented this. Assuming the request was successful, the body of the response will contain only the new shortened URL
I don’t even know where to begin or if there are any available ruby methods to make sending and receiving of these API requests frictionless. I basically want to assign the response (the shortened url) to a ruby object.
How would you do this? Thanks in advance.
Super simple:
open-uriis part of the Ruby standard library and (among other things) makes it possible to do HTTP requests using theopenmethod (which usually opens files).openreturns an IO, and callingreadon the IO returns the body.open-uriwill throw an exception if the server returns a 500 error, and in this case I’m catching the exception and returnnil, but if you want you can let the exception bubble up to the caller, or raise another exception.Oh, and you would use it like this: