Class: Kameleoon::Network::SyncNetProvider

Inherits:
NetProvider
  • Object
show all
Defined in:
lib/kameleoon/network/net_provider.rb

Instance Method Summary collapse

Instance Method Details

#make_request(request) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/kameleoon/network/net_provider.rb', line 30

def make_request(request)
  resp = nil
  case request.method
  when Method::GET
    req = Net::HTTP::Get.new(request.url)
  when Method::POST
    req = Net::HTTP::Post.new(request.url)
    req.body = request.data
  else
    return unknown_method_response(request.method, request)
  end
  timeout = request.timeout.to_f / 1000.0
  headers = collect_headers(request)
  headers.each { |k, v| req[k] = v }
  uri = URI(request.url)
  Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, open_timeout: timeout,
                                          read_timeout: timeout, ssl_timeout: timeout) do |http|
    resp = http.request(req)
  end
  body = resp.body
  body = nil if body&.empty?
  Response.new(nil, resp.code.to_i, body, request)
rescue StandardError => e
  Response.new(e, nil, nil, request)
end