Class: EventQL::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



5
6
7
# File 'lib/eventql_client.rb', line 5

def initialize(opts = {})
  @opts = opts
end

Instance Method Details

#get_auth_tokenObject



46
47
48
# File 'lib/eventql_client.rb', line 46

def get_auth_token
  return @opts[:auth_token]
end

#get_databaseObject



42
43
44
# File 'lib/eventql_client.rb', line 42

def get_database
  return @opts[:database]
end

#get_hostObject



34
35
36
# File 'lib/eventql_client.rb', line 34

def get_host
  return @opts[:host]
end

#get_portObject



38
39
40
# File 'lib/eventql_client.rb', line 38

def get_port
  return @opts[:port]
end

#has_auth_token?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/eventql_client.rb', line 50

def has_auth_token?
  return !@opts[:auth_token].nil?
end

#insert!(data, opts = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/eventql_client.rb', line 13

def insert!(data, opts = {})
  request = Net::HTTP::Post.new("/api/v1/tables/insert")
  request.add_field("Content-Type", "application/json")

  if has_auth_token?
    request.add_field("Authorization", "Token #{get_auth_token}")
  end

  request.body = data.to_json
  puts request.body

  http = Net::HTTP.new(get_host, get_port)
  response = http.request(request)

  if response.code.to_i == 201
    return true
  else
    raise "HTTP ERROR (#{response.code}): #{response.body[0..128]}"
  end
end

#query(query_str, opts = {}) ⇒ Object



9
10
11
# File 'lib/eventql_client.rb', line 9

def query(query_str, opts = {})
  EventQL::Query.new(self, query_str, opts)
end