Class: Delphix::Client

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/delphix/client.rb

Class Method Summary collapse

Methods included from Utils

#request_id, #utc_httpdate

Class Method Details

.internal_request(request, timeout) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/delphix/client.rb', line 48

def self.internal_request(request, timeout)
  HTTP_HEADERS.each { |key, value| request.add_header(key, value) }
  response = nil

  begin
    case request.method
    when :get
      response = RestClient::Request.execute(
        method: :get,
        url:     request.url,
        headers: request.headers,
        timeout: timeout
      )
    when :post
      response = RestClient::Request.execute(
        method: :post,
        url:     request.url,
        payload: request.body,
        headers: request.headers,
        timeout: timeout
      )
    when :delete
      response = RestClient::Request.execute(
        method: :delete,
        url:     request.url,
        payload: request.body,
        headers: request.headers,
        timeout: timeout
      )
    end
  rescue RestClient::RequestTimeout
    raise 'Request Timeout'
  rescue RestClient::Exception => e
    response = e.response
  end

  Delphix::Response.new(response)
end

.request(method, url, headers, body, timeout, &callback) ⇒ Object

Parameters:

  • method (Symnol)

    A valid HTTP verb ‘:get`, `:post`, or `:delete`.

  • url (String)

    The address or uri to send request.

  • body (String, Hash, Object)

    The request Body.

  • callback (Proc)

    Asychronous callback method to be invoked upon result.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/delphix/client.rb', line 36

def self.request(method, url, headers, body, timeout, &callback)
  request = Delphix::Request.new(method, url, headers, body)

  if callback
    Thread.new do
      callback.call(internal_request(request, timeout))
    end
  else
    internal_request(request, timeout)
  end
end