Sha256: e82f375902399fe11cbb02dfa43cd7b28c39b0d9969afa71bbfbd0f26f64f79e

Contents?: true

Size: 674 Bytes

Versions: 19

Compression:

Stored size: 674 Bytes

Contents

module Twitterscraper
  module Http

    module_function

    def get(url, headers = {}, proxy = nil, timeout = nil)
      timeout ||= 3

      if proxy
        ip, port = proxy.split(':')
        http_class = Net::HTTP::Proxy(ip, port.to_i)
      else
        http_class = Net::HTTP
      end

      uri = URI.parse(url)
      http = http_class.new(uri.host, uri.port)
      http.use_ssl = true if url.match?(/^https/)
      http.open_timeout = timeout
      http.read_timeout = timeout
      req = Net::HTTP::Get.new(uri)

      headers.each do |key, value|
        req[key] = value
      end

      res = http.start { http.request(req) }
      res.body
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
twitterscraper-ruby-0.20.1 lib/twitterscraper/http.rb
twitterscraper-ruby-0.20.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.19.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.18.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.17.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.16.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.15.2 lib/twitterscraper/http.rb
twitterscraper-ruby-0.15.1 lib/twitterscraper/http.rb
twitterscraper-ruby-0.15.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.14.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.13.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.12.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.11.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.10.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.9.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.8.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.7.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.6.0 lib/twitterscraper/http.rb
twitterscraper-ruby-0.5.0 lib/twitterscraper/http.rb