module TinyHttpClient
Public Instance Methods
get(url) { |req| ... }
click to toggle source
# File lib/tiny_http_client.rb, line 7 def get(url, &block) uri = URI(url) http_opts = { use_ssl: uri.scheme == 'https' } Net::HTTP.start uri.host, uri.port, http_opts do |https| req = Net::HTTP::Get.new(uri) yield(req) if block_given? case res = https.request(req) when Net::HTTPSuccess res.body when Net::HTTPRedirection get(res['location']) else res.error! end end end