Class: K3cloud::Http
- Inherits:
-
Object
- Object
- K3cloud::Http
- Defined in:
- lib/k3cloud/http.rb
Overview
HTTP Client
Defined Under Namespace
Classes: RetryableError
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#connect_timeout ⇒ Object
Returns the value of attribute connect_timeout.
-
#header ⇒ Object
Returns the value of attribute header.
-
#request_timeout ⇒ Object
Returns the value of attribute request_timeout.
-
#retry_count ⇒ Object
readonly
Returns the value of attribute retry_count.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
-
#url ⇒ Object
Returns the value of attribute url.
-
#verify_ssl ⇒ Object
Returns the value of attribute verify_ssl.
Instance Method Summary collapse
-
#initialize(url:, header:, body:, connect_timeout: Configuration::DEFAULT_CONNECT_TIMEOUT, request_timeout: Configuration::DEFAULT_REQUEST_TIMEOUT, verify_ssl: true, retry_max: 0, retry_interval: 1, retry_backoff: 2) ⇒ Http
constructor
retry_max/interval/backoff: 失败重试参数,仅对超时与 5xx 生效。.
- #post ⇒ Object
Constructor Details
#initialize(url:, header:, body:, connect_timeout: Configuration::DEFAULT_CONNECT_TIMEOUT, request_timeout: Configuration::DEFAULT_REQUEST_TIMEOUT, verify_ssl: true, retry_max: 0, retry_interval: 1, retry_backoff: 2) ⇒ Http
retry_max/interval/backoff: 失败重试参数,仅对超时与 5xx 生效。
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/k3cloud/http.rb', line 16 def initialize( url:, header:, body:, connect_timeout: Configuration::DEFAULT_CONNECT_TIMEOUT, request_timeout: Configuration::DEFAULT_REQUEST_TIMEOUT, verify_ssl: true, retry_max: 0, retry_interval: 1, retry_backoff: 2 ) @url = url @header = header || {} @body = body @connect_timeout = connect_timeout @request_timeout = request_timeout @verify_ssl = verify_ssl @retry_max = retry_max.to_i @retry_interval = retry_interval.to_f @retry_backoff = retry_backoff.to_f @retry_count = 0 end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
12 13 14 |
# File 'lib/k3cloud/http.rb', line 12 def body @body end |
#connect_timeout ⇒ Object
Returns the value of attribute connect_timeout.
12 13 14 |
# File 'lib/k3cloud/http.rb', line 12 def connect_timeout @connect_timeout end |
#header ⇒ Object
Returns the value of attribute header.
12 13 14 |
# File 'lib/k3cloud/http.rb', line 12 def header @header end |
#request_timeout ⇒ Object
Returns the value of attribute request_timeout.
12 13 14 |
# File 'lib/k3cloud/http.rb', line 12 def request_timeout @request_timeout end |
#retry_count ⇒ Object (readonly)
Returns the value of attribute retry_count.
13 14 15 |
# File 'lib/k3cloud/http.rb', line 13 def retry_count @retry_count end |
#status_code ⇒ Object
Returns the value of attribute status_code.
12 13 14 |
# File 'lib/k3cloud/http.rb', line 12 def status_code @status_code end |
#url ⇒ Object
Returns the value of attribute url.
12 13 14 |
# File 'lib/k3cloud/http.rb', line 12 def url @url end |
#verify_ssl ⇒ Object
Returns the value of attribute verify_ssl.
12 13 14 |
# File 'lib/k3cloud/http.rb', line 12 def verify_ssl @verify_ssl end |
Instance Method Details
#post ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/k3cloud/http.rb', line 34 def post uri = URI.parse(@url) http = build_http(uri) request = build_request(uri) body_str = perform_with_retry(http, request) log_trace(body_str) body_str end |