Class: ATS::AMP4E::API

Inherits:
Object
  • Object
show all
Defined in:
lib/ats/amp4e/api.rb

Constant Summary collapse

HEADERS =
{
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'User-Agent' => "RubyGems/ATS #{ATS::VERSION}",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration:, debug: false) ⇒ API

Returns a new instance of API.



12
13
14
15
16
17
18
19
20
# File 'lib/ats/amp4e/api.rb', line 12

def initialize(configuration:, debug: false)
  @http = HttpAPI.new(headers: HEADERS, debug: debug)
  @configuration = configuration
  @port = configuration[:port]
  @scheme = configuration[:scheme]
  @host = configuration[:host]
  @client_id = configuration[:client_id]
  @client_secret = configuration[:client_secret]
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



10
11
12
# File 'lib/ats/amp4e/api.rb', line 10

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



10
11
12
# File 'lib/ats/amp4e/api.rb', line 10

def client_secret
  @client_secret
end

#hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/ats/amp4e/api.rb', line 10

def host
  @host
end

#httpObject (readonly)

Returns the value of attribute http.



10
11
12
# File 'lib/ats/amp4e/api.rb', line 10

def http
  @http
end

#portObject (readonly)

Returns the value of attribute port.



10
11
12
# File 'lib/ats/amp4e/api.rb', line 10

def port
  @port
end

#schemeObject (readonly)

Returns the value of attribute scheme.



10
11
12
# File 'lib/ats/amp4e/api.rb', line 10

def scheme
  @scheme
end

Instance Method Details

#computersObject



22
23
24
# File 'lib/ats/amp4e/api.rb', line 22

def computers
  ATS::AMP4E::Computers.new(self)
end

#eventsObject



26
27
28
# File 'lib/ats/amp4e/api.rb', line 26

def events
  ATS::AMP4E::Events.new(self)
end

#get(url, params: {}, version: 1) ⇒ Object



38
39
40
41
42
# File 'lib/ats/amp4e/api.rb', line 38

def get(url, params: {}, version: 1)
  http.get(build_uri(url, version: version), headers: headers, body: params) do |request, response|
    JSON.parse(response.body, symbolize_names: true)
  end
end

#groupsObject



30
31
32
# File 'lib/ats/amp4e/api.rb', line 30

def groups
  ATS::AMP4E::Groups.new(self)
end

#policiesObject



34
35
36
# File 'lib/ats/amp4e/api.rb', line 34

def policies
  ATS::AMP4E::Policies.new(self)
end