Class: Baiwang::Request
- Inherits:
-
Object
- Object
- Baiwang::Request
- Defined in:
- lib/baiwang/request.rb
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#ssl_context ⇒ Object
readonly
Returns the value of attribute ssl_context.
Instance Method Summary collapse
-
#initialize(skip_verify_ssl = true) ⇒ Request
constructor
A new instance of Request.
- #post(method, token, post_body, post_header = {}) ⇒ Object
Constructor Details
#initialize(skip_verify_ssl = true) ⇒ Request
Returns a new instance of Request.
11 12 13 14 15 |
# File 'lib/baiwang/request.rb', line 11 def initialize(skip_verify_ssl = true) @http = HTTP.timeout(**Baiwang.) @ssl_context = OpenSSL::SSL::SSLContext.new @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE if skip_verify_ssl end |
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
9 10 11 |
# File 'lib/baiwang/request.rb', line 9 def http @http end |
#ssl_context ⇒ Object (readonly)
Returns the value of attribute ssl_context.
9 10 11 |
# File 'lib/baiwang/request.rb', line 9 def ssl_context @ssl_context end |
Instance Method Details
#post(method, token, post_body, post_header = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/baiwang/request.rb', line 17 def post(method, token, post_body, post_header = {}) par = basic_params(method, token) par.merge!({sign: sign_pb(par, post_body)}) path = "/router/rest?#{build_sorted_params(par)}" request(path, post_header) do |url, header| params = header.delete(:params) header['Content-Type'] = 'application/json' http.headers(header).post(url, params: params, json: post_body, ssl_context: ssl_context) end end |