Sha256: 4c41b56fddaa168a6312863b32cfb41654d1141b5224c637d3764898d7e97a6e
Contents?: true
Size: 1.01 KB
Versions: 22
Compression:
Stored size: 1.01 KB
Contents
require 'net/http' require 'open-uri' require 'yajl/json_gem' require 'kurchatov/version' module Kurchatov module Mixin module Http USER_AGENT = "Kurchatov (Riemann client)".freeze # /path/to/file, https://ya.ru, http://a:a@yandex.ru def rest_get(url) uri = URI(url) if uri.userinfo open("#{uri.scheme}://#{uri.hostname}:#{uri.port}#{uri.request_uri}", :http_basic_authentication => [uri.user, uri.password], 'User-Agent' => USER_AGENT).read else open(url, 'User-Agent' => USER_AGENT).read end end # return: body, http_code def http_get(url) uri = URI(url) req = Net::HTTP::Get.new(uri) req['User-Agent'] = USER_AGENT res = nil begin Net::HTTP.start(uri.hostname, uri.port) {|http| res = http.request(req)} rescue SocketError, Errno::ECONNREFUSED return nil, 0 end return res.body, res.code.to_i end end end end
Version data entries
22 entries across 22 versions & 1 rubygems