Class: SimpleHttpService::Client
- Inherits:
-
Object
- Object
- SimpleHttpService::Client
- Defined in:
- lib/simple_http_service/client.rb
Instance Attribute Summary collapse
-
#additional_headers ⇒ Object
Returns the value of attribute additional_headers.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#max_retries ⇒ Object
Returns the value of attribute max_retries.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#request_body ⇒ Object
Returns the value of attribute request_body.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#write_timeout ⇒ Object
Returns the value of attribute write_timeout.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(opts) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(opts) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/simple_http_service/client.rb', line 7 def initialize(opts) raise 'URL must be present' unless opts[:url] raise 'http_method must be present' unless opts[:http_method] @uri = URI(opts[:url]) @http_method = opts[:http_method] @headers = opts[:headers] || {} @request_body = opts[:request_body] @open_timeout = opts[:open_timeout] || false @read_timeout = opts[:read_timeout] || false @write_timeout = opts[:write_timeout] || false @max_retries = opts[:max_retries] || 1 @additional_headers = opts[:additional_headers] || {} end |
Instance Attribute Details
#additional_headers ⇒ Object
Returns the value of attribute additional_headers.
4 5 6 |
# File 'lib/simple_http_service/client.rb', line 4 def additional_headers @additional_headers end |
#headers ⇒ Object
Returns the value of attribute headers.
4 5 6 |
# File 'lib/simple_http_service/client.rb', line 4 def headers @headers end |
#http_method ⇒ Object
Returns the value of attribute http_method.
4 5 6 |
# File 'lib/simple_http_service/client.rb', line 4 def http_method @http_method end |
#max_retries ⇒ Object
Returns the value of attribute max_retries.
4 5 6 |
# File 'lib/simple_http_service/client.rb', line 4 def max_retries @max_retries end |
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
4 5 6 |
# File 'lib/simple_http_service/client.rb', line 4 def open_timeout @open_timeout end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
4 5 6 |
# File 'lib/simple_http_service/client.rb', line 4 def read_timeout @read_timeout end |
#request_body ⇒ Object
Returns the value of attribute request_body.
4 5 6 |
# File 'lib/simple_http_service/client.rb', line 4 def request_body @request_body end |
#uri ⇒ Object
Returns the value of attribute uri.
4 5 6 |
# File 'lib/simple_http_service/client.rb', line 4 def uri @uri end |
#write_timeout ⇒ Object
Returns the value of attribute write_timeout.
4 5 6 |
# File 'lib/simple_http_service/client.rb', line 4 def write_timeout @write_timeout end |
Instance Method Details
#call ⇒ Object
22 23 24 25 26 27 |
# File 'lib/simple_http_service/client.rb', line 22 def call enable_ssl set_headers set_timeout http.request(request) end |