Class: ATS::ThreatGrid::API
- Inherits:
-
Object
- Object
- ATS::ThreatGrid::API
- 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
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
Instance Method Summary collapse
- #get(url, params: {}, version: 3) ⇒ Object
-
#initialize(configuration:, debug: false) ⇒ API
constructor
A new instance of API.
- #organizations ⇒ Object
- #samples ⇒ Object
- #search ⇒ Object
- #users ⇒ Object
- #whoami ⇒ Object
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_key ⇒ Object (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 |
#host ⇒ Object (readonly)
Returns the value of attribute host.
9 10 11 |
# File 'lib/ats/threat_grid/api.rb', line 9 def host @host end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
9 10 11 |
# File 'lib/ats/threat_grid/api.rb', line 9 def http @http end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
9 10 11 |
# File 'lib/ats/threat_grid/api.rb', line 9 def port @port end |
#scheme ⇒ Object (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 |
#organizations ⇒ Object
28 29 30 |
# File 'lib/ats/threat_grid/api.rb', line 28 def organizations ATS::ThreatGrid::Organizations.new(self) end |
#samples ⇒ Object
32 33 34 |
# File 'lib/ats/threat_grid/api.rb', line 32 def samples ATS::ThreatGrid::Samples.new(self) end |
#search ⇒ Object
36 37 38 |
# File 'lib/ats/threat_grid/api.rb', line 36 def search ATS::ThreatGrid::Search.new(self) end |
#users ⇒ Object
24 25 26 |
# File 'lib/ats/threat_grid/api.rb', line 24 def users ATS::ThreatGrid::Users.new(self) end |
#whoami ⇒ Object
20 21 22 |
# File 'lib/ats/threat_grid/api.rb', line 20 def whoami get("session/whoami") end |