Class: Turn::Term

Inherits:
Object
  • Object
show all
Defined in:
lib/turn/term.rb

Instance Method Summary collapse

Constructor Details

#initialize(hostname, port) ⇒ Term

Returns a new instance of Term.


7
8
9
10
# File 'lib/turn/term.rb', line 7

def initialize(hostname, port)
  @hostname = hostname
  @port = port
end

Instance Method Details

#dump_bucket_map(dc) ⇒ Object


12
13
14
15
16
17
18
# File 'lib/turn/term.rb', line 12

def dump_bucket_map(dc)
  hash = get('dump profile bucket map', dc: dc)

  fail hash['errors'] unless hash['errors'].empty?

  hash['info']
end

#dump_public_metrics(prefix) ⇒ Object


20
21
22
23
24
25
26
27
28
29
# File 'lib/turn/term.rb', line 20

def dump_public_metrics(prefix)
  metrics = {}

  hash = get('dump public metrics', prefix: prefix)
  hash['rows'].each do |metric|
    metrics[metric.first] = metric.last.to_i
  end

  metrics
end

#get(command, query) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/turn/term.rb', line 31

def get(command, query)
  q = { command: command, 'response-formatter' => 'json' }
  uri = URI("http://#{@hostname}:#{@port}/execute")
  uri.query = URI.encode_www_form(q.merge(query))
  json = RestClient.get(uri.to_s)
  hash = JSON.parse(json)

  fail unless hash['errors'].empty? && hash['warnings'].empty?

  hash
end