Class: JPSClient::HttpClient
- Inherits:
-
Object
- Object
- JPSClient::HttpClient
- Defined in:
- lib/jpsclient/http/http_client.rb
Overview
JPS 专用 HTTP 客户端 - 优化版
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#default_timeout ⇒ Object
Returns the value of attribute default_timeout.
-
#max_retry_times ⇒ Object
Returns the value of attribute max_retry_times.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#delete(path, params: nil, timeout: nil) ⇒ Object
DELETE 请求.
-
#get(path, params: nil, timeout: nil) ⇒ Object
GET 请求.
-
#initialize(base_url: nil, token: nil, default_timeout: nil, max_retry_times: 3) ⇒ HttpClient
constructor
A new instance of HttpClient.
-
#post(path, body: nil, timeout: nil) ⇒ Object
POST 请求.
-
#put(path, body: nil, timeout: nil) ⇒ Object
PUT 请求.
-
#update_token(new_token) ⇒ Object
更新 token.
Constructor Details
#initialize(base_url: nil, token: nil, default_timeout: nil, max_retry_times: 3) ⇒ HttpClient
Returns a new instance of HttpClient.
84 85 86 87 88 89 90 |
# File 'lib/jpsclient/http/http_client.rb', line 84 def initialize(base_url: nil, token: nil, default_timeout: nil, max_retry_times: 3) @base_url = base_url @token = token @default_timeout = default_timeout || 60 @max_retry_times = max_retry_times || 3 @connection = nil end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
75 76 77 |
# File 'lib/jpsclient/http/http_client.rb', line 75 def base_url @base_url end |
#default_timeout ⇒ Object
Returns the value of attribute default_timeout.
77 78 79 |
# File 'lib/jpsclient/http/http_client.rb', line 77 def default_timeout @default_timeout end |
#max_retry_times ⇒ Object
Returns the value of attribute max_retry_times.
78 79 80 |
# File 'lib/jpsclient/http/http_client.rb', line 78 def max_retry_times @max_retry_times end |
#token ⇒ Object
Returns the value of attribute token.
76 77 78 |
# File 'lib/jpsclient/http/http_client.rb', line 76 def token @token end |
Instance Method Details
#delete(path, params: nil, timeout: nil) ⇒ Object
DELETE 请求
110 111 112 |
# File 'lib/jpsclient/http/http_client.rb', line 110 def delete(path, params: nil, timeout: nil) request(:delete, path, params: params, timeout: timeout) end |
#get(path, params: nil, timeout: nil) ⇒ Object
GET 请求
94 95 96 |
# File 'lib/jpsclient/http/http_client.rb', line 94 def get(path, params: nil, timeout: nil) request(:get, path, params: params, timeout: timeout) end |
#post(path, body: nil, timeout: nil) ⇒ Object
POST 请求
100 101 102 |
# File 'lib/jpsclient/http/http_client.rb', line 100 def post(path, body: nil, timeout: nil) request(:post, path, body: body, timeout: timeout) end |
#put(path, body: nil, timeout: nil) ⇒ Object
PUT 请求
105 106 107 |
# File 'lib/jpsclient/http/http_client.rb', line 105 def put(path, body: nil, timeout: nil) request(:put, path, body: body, timeout: timeout) end |
#update_token(new_token) ⇒ Object
更新 token
115 116 117 |
# File 'lib/jpsclient/http/http_client.rb', line 115 def update_token(new_token) @token = new_token end |