Class: ProxyFetcher::Client::Request
- Inherits:
-
Object
- Object
- ProxyFetcher::Client::Request
- Defined in:
- lib/proxy_fetcher/client/request.rb
Overview
ProxyFetcher::Client HTTP request abstraction.
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#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.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.execute(args) ⇒ String
Initializes a new HTTP request and processes it.
Instance Method Summary collapse
-
#execute ⇒ String
Executes HTTP request with defined options.
-
#initialize(args) ⇒ Request
constructor
Initialize new HTTP request.
Constructor Details
#initialize(args) ⇒ Request
Initialize new HTTP request
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/proxy_fetcher/client/request.rb', line 52 def initialize(args) raise ArgumentError, "args must be a Hash!" unless args.is_a?(Hash) @url = args.fetch(:url) @method = args.fetch(:method).to_s.downcase @headers = (args[:headers] || {}).dup @payload = args[:payload] @timeout = args.fetch(:timeout, ProxyFetcher.config.client_timeout) @ssl_options = args.fetch(:ssl_options, ) @proxy = args.fetch(:proxy) @max_redirects = args.fetch(:max_redirects, 10) @http = build_http_client end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
17 18 19 |
# File 'lib/proxy_fetcher/client/request.rb', line 17 def headers @headers end |
#max_redirects ⇒ Object (readonly)
Returns the value of attribute max_redirects.
33 34 35 |
# File 'lib/proxy_fetcher/client/request.rb', line 33 def max_redirects @max_redirects end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
9 10 11 |
# File 'lib/proxy_fetcher/client/request.rb', line 9 def method @method end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
25 26 27 |
# File 'lib/proxy_fetcher/client/request.rb', line 25 def payload @payload end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
29 30 31 |
# File 'lib/proxy_fetcher/client/request.rb', line 29 def proxy @proxy end |
#ssl_options ⇒ Object (readonly)
Returns the value of attribute ssl_options.
37 38 39 |
# File 'lib/proxy_fetcher/client/request.rb', line 37 def @ssl_options end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
21 22 23 |
# File 'lib/proxy_fetcher/client/request.rb', line 21 def timeout @timeout end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
13 14 15 |
# File 'lib/proxy_fetcher/client/request.rb', line 13 def url @url end |
Class Method Details
.execute(args) ⇒ String
Initializes a new HTTP request and processes it
44 45 46 |
# File 'lib/proxy_fetcher/client/request.rb', line 44 def self.execute(args) new(args).execute end |
Instance Method Details
#execute ⇒ String
Executes HTTP request with defined options.
73 74 75 76 77 78 |
# File 'lib/proxy_fetcher/client/request.rb', line 73 def execute response = send_request response.body.to_s rescue HTTP::Redirector::TooManyRedirectsError raise ProxyFetcher::Exceptions::MaximumRedirectsReached end |