Class: Huntress::Client
Overview
The Client class serves as a wrapper for the Hudu REST API, providing methods to interact with various Hudu resources.
This class dynamically defines methods to fetch, create, update, and manipulate Hudu resources such as companies, articles, assets, and more.
Class Method Summary collapse
-
.api_endpoint(method, singular_method = nil, path = method) ⇒ Object
Dynamically defines methods for interacting with Hudu API resources.
Instance Method Summary collapse
- #account(options = {}) ⇒ Object
- #actor(options = {}) ⇒ Object
-
#api_url(path) ⇒ String
Constructs the full API URL for a given path.
- #remediation(incident_report_id, remediation, options = {}) ⇒ Object
- #remediations(incident_report_id, options = {}) ⇒ Object
Methods inherited from API
Methods included from Authentication
Constructor Details
This class inherits a constructor from Huntress::API
Class Method Details
.api_endpoint(method, singular_method = nil, path = method) ⇒ Object
Dynamically defines methods for interacting with Hudu API resources.
Depending on the arguments, this will define methods to:
-
Fetch all records for a resource
-
Fetch a specific record by ID
-
Update a record
-
Create a new record
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/huntress/client.rb', line 39 def self.api_endpoint(method, singular_method = nil, path = method) if singular_method # Define method to fetch all records and one by id send(:define_method, method) do |params = {}| r = get_paged(api_url(path), params) end # Define method to fetch a single record by ID send(:define_method, singular_method) do |id, params = {}| r = get(api_url("#{path}/#{id}"), params) end else # Define simple method to fetch data send(:define_method, method) do |params = {}| get(api_url(path), params) end end end |
Instance Method Details
#account(options = {}) ⇒ Object
57 58 59 |
# File 'lib/huntress/client.rb', line 57 def account( = {}) get(api_url('account'), ) end |
#actor(options = {}) ⇒ Object
61 62 63 |
# File 'lib/huntress/client.rb', line 61 def actor( = {}) get(api_url('actor'), ) end |
#api_url(path) ⇒ String
Constructs the full API URL for a given path.
87 88 89 |
# File 'lib/huntress/client.rb', line 87 def api_url(path) "/v1/#{path}" end |
#remediation(incident_report_id, remediation, options = {}) ⇒ Object
65 66 67 |
# File 'lib/huntress/client.rb', line 65 def remediation(incident_report_id, remediation, = {}) get_paged(api_url("incident_reports/#{incident_report_id}/remediations/#{remediation}"), ) end |
#remediations(incident_report_id, options = {}) ⇒ Object
69 70 71 72 |
# File 'lib/huntress/client.rb', line 69 def remediations(incident_report_id, = {}) #get_paged(api_url("incident_reports/#{incident_report_id}/remediations"), options) remediation(incident_report_id, nil, ) end |