Class: Hibp::HttpClient
- Inherits:
-
Object
show all
- Includes:
- HTTParty
- Defined in:
- lib/hibp/http_client.rb
Defined Under Namespace
Classes: ClientError, ConnectionError, HttpError, RequestError, Response, ServerError, UnhandledError
Constant Summary
collapse
- DEFAULT_TIMEOUT =
0.5
- DEFAULT_RETRIES =
3
- HANDLED_EXCEPTIONS =
[
ServerError,
ClientError,
Timeout::Error,
Errno::ETIMEDOUT,
Errno::ECONNRESET,
Errno::ECONNREFUSED,
Errno::ENETUNREACH,
Errno::EHOSTUNREACH,
EOFError
]
Instance Method Summary
collapse
Constructor Details
#initialize(config = {}) ⇒ HttpClient
Returns a new instance of HttpClient.
40
41
42
43
44
45
46
|
# File 'lib/hibp/http_client.rb', line 40
def initialize(config = {})
@config = {
:timeout => DEFAULT_TIMEOUT,
:retries => DEFAULT_RETRIES,
}.merge(config)
default_timeout = @config[:timeout]
end
|
Instance Method Details
#do_delete(path, params = nil, opt = {}) ⇒ Object
60
61
62
|
# File 'lib/hibp/http_client.rb', line 60
def do_delete(path, params=nil, opt={})
do_request(:delete, path, {:query => params}.merge(opt))
end
|
#do_get(path, params = nil, opt = {}) ⇒ Object
48
49
50
|
# File 'lib/hibp/http_client.rb', line 48
def do_get(path, params=nil, opt={})
do_request(:get, path, {:query => params}.merge(opt))
end
|
#do_post(path, params = nil, opt = {}) ⇒ Object
52
53
54
|
# File 'lib/hibp/http_client.rb', line 52
def do_post(path, params=nil, opt={})
do_request(:post, path, {:body => params}.merge(opt))
end
|
#do_put(path, params = nil, opt = {}) ⇒ Object
56
57
58
|
# File 'lib/hibp/http_client.rb', line 56
def do_put(path, params=nil, opt={})
do_request(:put, path, {:body => params}.merge(opt))
end
|