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.



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

def initialize(configuration:, debug: false)
  @http = Net::Hippie::Client.new(headers: HEADERS, verify_mode: debug ? OpenSSL::SSL::VERIFY_NONE : nil)
  @configuration = configuration
  @port = configuration[:port]
  @scheme = configuration[:scheme]
  @host = configuration[:host]
  @bearer_token = configuration[:bearer_token]
  @client_id = configuration[:client_id]
  @client_secret = configuration[:client_secret]
end

Instance Attribute Details

#bearer_tokenObject (readonly)

Returns the value of attribute bearer_token.



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

def bearer_token
  @bearer_token
end

#client_idObject (readonly)

Returns the value of attribute client_id.



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

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



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

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



24
25
26
# File 'lib/ats/amp4e/api.rb', line 24

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

#eventsObject



28
29
30
# File 'lib/ats/amp4e/api.rb', line 28

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

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



40
41
42
43
44
# File 'lib/ats/amp4e/api.rb', line 40

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



32
33
34
# File 'lib/ats/amp4e/api.rb', line 32

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

#policiesObject



36
37
38
# File 'lib/ats/amp4e/api.rb', line 36

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