I get access to different servers for data and I tried different methods in different classes using basic http :: net, curb, rest-client and open-uri
(1) How to measure performance in Ruby / Rails in general? (2) Which method do you think is faster?
Sample code from all 4 different methods:
url = "..." begin io_output = open(url, :http_basic_authentication => [@user_id, @user_password]) rescue => e error = e.message #for debugging return this return '-' else output = io_output.read
or
require 'net/https' uri = URI.parse("...") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_PEER data = http.get(uri.request_uri)
or
require 'curb' url = "..." c = Curl::Easy.new(url) do |curl| curl.headers["Content-type"] = "application/json" curl.headers["Authorization"] = "Token ..." end c.perform puts c.body_str
or
url = "..." resource = RestClient::Resource.new(url, :headers => { :Authorization => "Token ...", :content_type => "application/json"}) begin output = resource.get rescue => e error = e.message #for debugging return this return '-' else ... end
ruby-on-rails curl open-uri rest-client curb
nevermind
source share