I've studied Ruby for 2 years. I feel Ruby like Lego blocks: it is cool, funny, and you could even build a wall with this easily but it could be expensive to make a very solid wall.
Anyway, here is a funny to. Look how simple is to do a Getter REST client in ruby (you could try RESTfolia, restfulie, etc). I call Getter REST client because, it just for GET requests.
With authentication, we get:
That is it!
Anyway, here is a funny to. Look how simple is to do a Getter REST client in ruby (you could try RESTfolia, restfulie, etc). I call Getter REST client because, it just for GET requests.
require "net/http"
require "uri"
require 'json'
require 'methodize'
uri = URI.parse("http://localhost:8080/jdb/list")
response = Net::HTTP.get_response(uri)
json = JSON.parse(response.body)
json.extend(Methodize)
With authentication, we get:
req = Net::HTTP::Get.new(uri.request_uri)
req.basic_auth 'user', 'password'
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
http.request(req)
}
json = JSON.parse(res.body)
json.extend(Methodize)
That is it!
Comentários