Class: ProxyFetcher::Client::Request
- Inherits:
-
Object
- Object
- ProxyFetcher::Client::Request
- Defined in:
- lib/proxy_fetcher/client/request.rb
Constant Summary collapse
- URL_ENCODED =
{ 'Content-Type' => 'application/x-www-form-urlencoded' }.freeze
- DEFAULT_SSL_OPTIONS =
{ verify_mode: OpenSSL::SSL::VERIFY_NONE }.freeze
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#max_redirects ⇒ Object
readonly
Returns the value of attribute max_redirects.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#ssl_options ⇒ Object
readonly
Returns the value of attribute ssl_options.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(args) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(args) ⇒ Request
Returns a new instance of Request.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/proxy_fetcher/client/request.rb', line 19 def initialize(args) raise ArgumentError, 'args must be a Hash!' unless args.is_a?(Hash) @uri = URI.parse(args.fetch(:url)) @method = args.fetch(:method).to_s.capitalize @headers = (args[:headers] || {}).dup @payload = preprocess_payload(args[:payload]) @timeout = args.fetch(:timeout, ProxyFetcher.config.timeout) @ssl_options = args.fetch(:ssl_options, DEFAULT_SSL_OPTIONS) @proxy = args.fetch(:proxy) @max_redirects = args.fetch(:max_redirects, 10) build_http_client end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
12 13 14 |
# File 'lib/proxy_fetcher/client/request.rb', line 12 def headers @headers end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
12 13 14 |
# File 'lib/proxy_fetcher/client/request.rb', line 12 def http @http end |
#max_redirects ⇒ Object (readonly)
Returns the value of attribute max_redirects.
12 13 14 |
# File 'lib/proxy_fetcher/client/request.rb', line 12 def max_redirects @max_redirects end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
12 13 14 |
# File 'lib/proxy_fetcher/client/request.rb', line 12 def method @method end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
12 13 14 |
# File 'lib/proxy_fetcher/client/request.rb', line 12 def payload @payload end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
12 13 14 |
# File 'lib/proxy_fetcher/client/request.rb', line 12 def proxy @proxy end |
#ssl_options ⇒ Object (readonly)
Returns the value of attribute ssl_options.
12 13 14 |
# File 'lib/proxy_fetcher/client/request.rb', line 12 def @ssl_options end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
12 13 14 |
# File 'lib/proxy_fetcher/client/request.rb', line 12 def timeout @timeout end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
12 13 14 |
# File 'lib/proxy_fetcher/client/request.rb', line 12 def uri @uri end |
Class Method Details
.execute(args) ⇒ Object
15 16 17 |
# File 'lib/proxy_fetcher/client/request.rb', line 15 def self.execute(args) new(args).execute end |
Instance Method Details
#execute ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/proxy_fetcher/client/request.rb', line 35 def execute request = request_class_for(method).new(uri, headers) http.start do |connection| process_response!(connection.request(request, payload)) end end |