Class: AgentClient::Agent

Inherits:
Object
  • Object
show all
Extended by:
Request
Includes:
Request
Defined in:
lib/agent_client/agent.rb

Overview

Represents a Stratumn agent

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Request

get, post

Constructor Details

#initialize(url, agent_info, store_info) ⇒ Agent

Returns a new instance of Agent.



24
25
26
27
28
# File 'lib/agent_client/agent.rb', line 24

def initialize(url, agent_info, store_info)
  self.url = url
  self.agent_info = agent_info
  self.store_info = store_info
end

Instance Attribute Details

#agent_infoObject

Returns the value of attribute agent_info.



14
15
16
# File 'lib/agent_client/agent.rb', line 14

def agent_info
  @agent_info
end

#store_infoObject

Returns the value of attribute store_info.



14
15
16
# File 'lib/agent_client/agent.rb', line 14

def store_info
  @store_info
end

#urlObject

Returns the value of attribute url.



14
15
16
# File 'lib/agent_client/agent.rb', line 14

def url
  @url
end

Class Method Details

.load(url) ⇒ Object



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

def self.load(url)
  attributes = get(url)

  new(url,
      attributes['agentInfo'],
      attributes['storeInfo'])
end

Instance Method Details

#create_map(*args) ⇒ Object



30
31
32
33
34
# File 'lib/agent_client/agent.rb', line 30

def create_map(*args)
  result = post(url + '/segments', json: args)

  Segment.new(self, result)
end

#find_segments(options = {}) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/agent_client/agent.rb', line 40

def find_segments(options = {})
  result = get(url + '/segments?' + URI.encode_www_form(options))

  result.map do |link|
    Segment.new(self, link)
  end
end

#get_map_ids(options = {}) ⇒ Object



36
37
38
# File 'lib/agent_client/agent.rb', line 36

def get_map_ids(options = {})
  get(url + '/maps?' + URI.encode_www_form(options))
end

#get_segment(link_hash) ⇒ Object



48
49
50
51
52
# File 'lib/agent_client/agent.rb', line 48

def get_segment(link_hash)
  result = get(url + '/segments/' + link_hash)

  Segment.new(self, result)
end