Class: Memoir::Client

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

Constant Summary collapse

API_QUERY_URL =
'/api/query'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, logger = nil, options = {}) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
# File 'lib/memoir/client.rb', line 6

def initialize(host, port, logger = nil, options = {})
  @host = host
  @port = port
  @timeout = options[:timeout] || 10
  @logger = logger
  prepare_connection
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



2
3
4
# File 'lib/memoir/client.rb', line 2

def connection
  @connection
end

#hostObject

Returns the value of attribute host.



2
3
4
# File 'lib/memoir/client.rb', line 2

def host
  @host
end

#loggerObject

Returns the value of attribute logger.



2
3
4
# File 'lib/memoir/client.rb', line 2

def logger
  @logger
end

#portObject

Returns the value of attribute port.



2
3
4
# File 'lib/memoir/client.rb', line 2

def port
  @port
end

#timeoutObject

Returns the value of attribute timeout.



2
3
4
# File 'lib/memoir/client.rb', line 2

def timeout
  @timeout
end

Instance Method Details

#dry_run(request) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/memoir/client.rb', line 32

def dry_run(request)
  if logger
    logger.info request.to_json
  else
    puts request.to_json
  end
end

#run(request) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/memoir/client.rb', line 24

def run(request)
  response = connection.post API_QUERY_URL, request.to_h do |req|
    req.params['arrays'] = true if request.arrays
  end

  Memoir::Response.new response
end