Method: Etcd::Client#api_execute

Defined in:
lib/etcd/client.rb

#api_execute(path, method, options = {}) ⇒ Object

This method sends api request to etcd server.

This method has following parameters as argument

  • path - etcd server path (etcd server end point)

  • method - the request method used

  • options - any additional parameters used by request method (optional)

rubocop:disable MethodLength, CyclomaticComplexity



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/etcd/client.rb', line 92

def api_execute(path, method, options = {})
  params = options[:params]
  case  method
  when :get
    req = build_http_request(Net::HTTP::Get, path, params)
  when :post
    req = build_http_request(Net::HTTP::Post, path, nil, params)
  when :put
    req = build_http_request(Net::HTTP::Put, path, nil, params)
  when :delete
    req = build_http_request(Net::HTTP::Delete, path, params)
  else
    fail "Unknown http action: #{method}"
  end
  http = Net::HTTP.new(host, port)
  http.read_timeout = options[:timeout] || read_timeout
  setup_https(http)
  req.basic_auth(user_name, password) if [user_name, password].all?
  Log.debug("Invoking: '#{req.class}' against '#{path}")
  res = http.request(req)
  Log.debug("Response code: #{res.code}")
  Log.debug("Response body: #{res.body}")
  process_http_request(res)
end