Class: Etcd::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/etcd/response.rb

Overview

manage http responses

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts, headers = {}) ⇒ Response

Returns a new instance of Response.



16
17
18
19
20
21
22
# File 'lib/etcd/response.rb', line 16

def initialize(opts, headers = {})
  @action = opts['action']
  @node = Node.new(opts['node'])
  @etcd_index = headers[:etcd_index]
  @raft_index = headers[:raft_index]
  @raft_term = headers[:raft_term]
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



12
13
14
# File 'lib/etcd/response.rb', line 12

def action
  @action
end

#etcd_indexObject (readonly)

Returns the value of attribute etcd_index.



12
13
14
# File 'lib/etcd/response.rb', line 12

def etcd_index
  @etcd_index
end

#nodeObject (readonly)

Returns the value of attribute node.



12
13
14
# File 'lib/etcd/response.rb', line 12

def node
  @node
end

#raft_indexObject (readonly)

Returns the value of attribute raft_index.



12
13
14
# File 'lib/etcd/response.rb', line 12

def raft_index
  @raft_index
end

#raft_termObject (readonly)

Returns the value of attribute raft_term.



12
13
14
# File 'lib/etcd/response.rb', line 12

def raft_term
  @raft_term
end

Class Method Details

.from_http_response(response) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/etcd/response.rb', line 24

def self.from_http_response(response)
  data = JSON.parse(response.body)
  headers = {}
  headers[:etcd_index] = response['X-Etcd-Index'].to_i
  headers[:raft_index] = response['X-Raft-Index'].to_i
  headers[:raft_term] = response['X-Raft-Term'].to_i
  Response.new(data, headers)
end