Class: ATS::ThreatGrid::API

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

Constant Summary collapse

HEADERS =
{
  'Content-Type' => '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.



11
12
13
14
15
16
17
18
# File 'lib/ats/threat_grid/api.rb', line 11

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]
  @api_key = configuration[:api_key]
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



9
10
11
# File 'lib/ats/threat_grid/api.rb', line 9

def api_key
  @api_key
end

#hostObject (readonly)

Returns the value of attribute host.



9
10
11
# File 'lib/ats/threat_grid/api.rb', line 9

def host
  @host
end

#httpObject (readonly)

Returns the value of attribute http.



9
10
11
# File 'lib/ats/threat_grid/api.rb', line 9

def http
  @http
end

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/ats/threat_grid/api.rb', line 9

def port
  @port
end

#schemeObject (readonly)

Returns the value of attribute scheme.



9
10
11
# File 'lib/ats/threat_grid/api.rb', line 9

def scheme
  @scheme
end

Instance Method Details

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



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

def get(url, params: {}, version: 3)
  http.get(build_uri(url, version: version), body: default_payload.merge(params)) do |request, response|
    JSON.parse(response.body, symbolize_names: true)[:data]
  end
end

#organizationsObject



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

def organizations
  ATS::ThreatGrid::Organizations.new(self)
end

#samplesObject



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

def samples
  ATS::ThreatGrid::Samples.new(self)
end

#searchObject



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

def search
  ATS::ThreatGrid::Search.new(self)
end

#usersObject



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

def users
  ATS::ThreatGrid::Users.new(self)
end

#whoamiObject



20
21
22
# File 'lib/ats/threat_grid/api.rb', line 20

def whoami
  get("session/whoami")
end