Skip to content

Commit

Permalink
Add Ruby 3 to Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
nbulaj committed Feb 17, 2021
1 parent 3d15056 commit 276927a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cache: bundler
before_install:
- "find /home/travis/.rvm/rubies -wholename '*default/bundler-*.gemspec' -delete"
- rvm @global do gem uninstall bundler -a -x -I || true
- gem install bundler -v '~> 1.10'
- gem install bundler

bundler_args: --without yard guard benchmarks
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
Expand All @@ -18,6 +18,7 @@ rvm:
- 2.5
- 2.6
- 2.7
- 3.0
- ruby-head
- jruby-9.2.8.0
- truffleruby-head
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ gemspec

gem "nokogiri", "~> 1.8"
gem "oga", "~> 3.2"
gem "rubocop", "~> 0.80"
gem "rubocop", "~> 1.0"

group :test do
gem "coveralls", require: false
gem "webrick"
gem "evil-proxy", "~> 0.2"
end
2 changes: 1 addition & 1 deletion gemfiles/nokogiri.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ gem "nokogiri", "~> 1.8"

group :test do
gem "coveralls", require: false
gem "webrick"
gem "evil-proxy", "~> 0.2"
gem "rspec", "~> 3.9"
end
2 changes: 1 addition & 1 deletion gemfiles/oga.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ gem "oga", "~> 3.0"

group :test do
gem "coveralls", require: false
gem "webrick"
gem "evil-proxy", "~> 0.2"
gem "rspec", "~> 3.9"
end
6 changes: 3 additions & 3 deletions lib/proxy_fetcher/client/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ class Request
# @return [String]
# response body (requested resource content)
#
def self.execute(args)
new(args).execute
def self.execute(**args)
new(**args).execute
end

# Initialize new HTTP request
#
# @return [Request]
#
def initialize(args)
def initialize(**args)
raise ArgumentError, "args must be a Hash!" unless args.is_a?(Hash)

@url = args.fetch(:url)
Expand Down
35 changes: 23 additions & 12 deletions lib/proxy_fetcher/utils/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ class HTTPClient
# @return [String]
# resource content
#
def self.fetch(*args)
url = args.shift
new(url, **args.first).fetch
def self.fetch(*args, **kwargs, &block)
new(*args, **kwargs, &block).fetch
end

# Initialize HTTP client instance
Expand All @@ -56,20 +55,25 @@ def initialize(url, method: :get, params: {}, headers: {})
@params = params
@headers = headers

@http = HTTP.headers(default_headers.merge(headers)).timeout(connect: timeout, read: timeout)
unless HTTP::Request::METHODS.include?(@method)
raise ArgumentError, "'#{@method}' is a wrong HTTP method name"
end

@timeout = ProxyFetcher.config.provider_proxies_load_timeout
@http = build_http_engine

@ssl_ctx = OpenSSL::SSL::SSLContext.new
@ssl_ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
@ssl_ctx = build_ssl_context
end

# Fetches resource content by sending HTTP request to it.
#
# @return [String]
# response body
#
def fetch
response = process_http_request
def fetch(**options)
response = perform_http_request
return response if options.fetch(:raw, false)

response.body.to_s
rescue StandardError => e
ProxyFetcher.config.logger.warn("Failed to process request to #{url} (#{e.message})")
Expand All @@ -78,13 +82,20 @@ def fetch

protected

def process_http_request(http_method: method, http_params: params)
unless HTTP::Request::METHODS.include?(http_method)
raise ArgumentError, "'#{http_method}' is a wrong HTTP method name!"
def build_ssl_context
OpenSSL::SSL::SSLContext.new.tap do |content|
content.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
end

def build_http_engine
HTTP.headers(default_headers.merge(headers)).timeout(connect: timeout, read: timeout)
end

def perform_http_request(http_method: method, http_params: params)
http.public_send(
http_method.to_sym, url,
http_method.to_sym,
url,
form: http_params,
ssl_context: ssl_ctx
)
Expand Down
5 changes: 5 additions & 0 deletions spec/proxy_fetcher/client/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
require "spec_helper"
require "json"

begin
require "webrick"
rescue LoadError
# nop
end
require "evil-proxy"
require "evil-proxy/async"

Expand Down

0 comments on commit 276927a

Please sign in to comment.