Class: GoApiClient::Api::Agent

Inherits:
AbstractApi show all
Defined in:
lib/go_api_client/api/agent.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Agent

Returns a new instance of Agent.



7
8
9
10
11
12
13
14
# File 'lib/go_api_client/api/agent.rb', line 7

def initialize(attributes = {})
  super(attributes)
  @agent_uri = "#{@base_uri}/api/agents"
  @agent_headers = {
    'Content-Type' => 'application/json',
    'Accept'       => 'application/vnd.go.cd.v1+json'
  }
end

Instance Method Details

#agents(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/go_api_client/api/agent.rb', line 16

def agents(options={})
  options = ({:uuid => nil}).merge(options)
  uri = options[:uuid] ? "#{@agent_uri}/#{options[:uuid]}" : @agent_uri

  response = JSON.parse(@http_fetcher.get!(uri, {:headers=>@agent_headers}))
  if response['_embedded']
    response['_embedded']['agents'].map do |agent_hash|
      agent_hash.delete('_links')
      GoApiClient::Domain::Agent.new(agent_hash)
    end
  else
    response.delete('_links')
    GoApiClient::Domain::Agent.new(response)
  end
end

#delete(uuid) ⇒ Object



55
56
57
58
59
# File 'lib/go_api_client/api/agent.rb', line 55

def delete(uuid)
  uri = "#{@agent_uri}/#{uuid}"
  @http_fetcher.delete!(uri, {:headers=>@agent_headers})
  true
end

#disable(uuid) ⇒ Object



51
52
53
# File 'lib/go_api_client/api/agent.rb', line 51

def disable(uuid)
  update(uuid, {:enabled => false})
end

#enable(uuid) ⇒ Object



47
48
49
# File 'lib/go_api_client/api/agent.rb', line 47

def enable(uuid)
  update(uuid, {:enabled => true})
end

#update(uuid, options = {}) ⇒ Object

API available since v15.2.0

Possible options:

  • hostname String The new hostname.

  • resources String | Array A comma separated strings of resources, or an array of string resources.

  • enabled Boolean Whether an agent should be enabled. In case of agents awaiting approval, setting this will approve the agents.



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

def update(uuid, options={})
  uri = "#{@agent_uri}/#{uuid}"
  response = JSON.parse(@http_fetcher.patch!(uri, {:headers=>@agent_headers, :params=>options}))
  response.delete('_links')
  GoApiClient::Domain::Agent.new(response)
end