Class: Lark::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(skip_verify_ssl = true) ⇒ Request

Returns a new instance of Request.



7
8
9
10
11
12
# File 'lib/lark/request.rb', line 7

def initialize(skip_verify_ssl = true)
  @http = HTTP.timeout(**Lark.http_timeout_options)
  @ssl_context = OpenSSL::SSL::SSLContext.new
  #@ssl_context.ssl_version = :TLSv1_2
  @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE if skip_verify_ssl
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



5
6
7
# File 'lib/lark/request.rb', line 5

def http
  @http
end

#ssl_contextObject (readonly)

Returns the value of attribute ssl_context.



5
6
7
# File 'lib/lark/request.rb', line 5

def ssl_context
  @ssl_context
end

Instance Method Details

#get(path, get_header = {}) ⇒ Object Also known as: delete



14
15
16
17
18
19
# File 'lib/lark/request.rb', line 14

def get(path, get_header = {})
  request(path, get_header) do |url, header|
    params = header.delete(:params)
    http.headers(header).get(url, params: params, ssl_context: ssl_context)
  end
end

#post(path, post_body, post_header = {}) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/lark/request.rb', line 22

def post(path, post_body, post_header = {})
  request(path, post_header) do |url, header|
    Lark.logger.info "payload: #{post_body}"
    params = header.delete(:params)
    http.headers(header).post(url, params: params, json: post_body, ssl_context: ssl_context)
  end
end

#post_file(path, file, post_header = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lark/request.rb', line 30

def post_file(path, file, post_header = {})
  request(path, post_header) do |url, header|
    params = header.delete(:params)
    http.headers(header).post(
      url,
      params: params,
      form: {
        media: HTTP::FormData::File.new(file),
        hack: 'X'
      }, # Existing here for http-form_data 1.0.1 handle single param improperly
      ssl_context: ssl_context
    )
  end
end