Class: Baiwang::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/baiwang/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.http_timeout_options)
  @ssl_context = OpenSSL::SSL::SSLContext.new
  @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE if skip_verify_ssl
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



9
10
11
# File 'lib/baiwang/request.rb', line 9

def http
  @http
end

#ssl_contextObject (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