Class: Polyseerio::Client

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

Overview

The Polyseer.io client.

Constant Summary collapse

INITIALIZE_DEFAULTS =
{
  agent_class: Agent::Agent,
  request: nil
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cid, options = {}) ⇒ Client

Returns a new instance of Client.



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

def initialize(cid, options = {})
  options = Helper.defaults(options, INITIALIZE_DEFAULTS)

  if options[:request].nil?
    raise ArgumentError, 'Cannot create an instance of Client without' \
      'passing a request instance.'
  end

  if options.key? :resources
    options[:resources].each(&Helper.attach_to_instance!(self))
  end

  @cid = cid
  @agent = nil
  @instance = nil
  @request = options[:request]
  @agent_class = options[:agent_class]
end

Instance Attribute Details

#agentObject

Returns the value of attribute agent.



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

def agent
  @agent
end

#cidObject

Returns the value of attribute cid.



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

def cid
  @cid
end

#instanceObject

Returns the value of attribute instance.



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

def instance
  @instance
end

Instance Method Details

#start_agent(*args) ⇒ Object

Start an agent using this client.



35
36
37
38
39
40
41
# File 'lib/client.rb', line 35

def start_agent(*args)
  raise 'Agent has already started.' unless @agent.nil?

  @agent = @agent_class.new(self)

  @agent.start(*args)
end