Class: Sophos::Client
- Defined in:
- lib/sophos/client.rb,
lib/sophos/client/common.rb,
lib/sophos/client/helper.rb,
lib/sophos/client/partner.rb,
lib/sophos/client/endpoint.rb
Overview
This module provides helper methods to dynamically define API calls for the Sophos Client.
It supports paginated and non-paginated API methods, and allows generating
URLs for different API types (common, endpoint, partner).
Example:
# Define paginated API methods for fetching alerts:
Helper::def_api_call(:alerts, Helper::common_url(:alerts), :alert)
# Generated methods:
client.alerts # Fetches paginated alerts
client.alert(12345) # Fetches a specific alert by ID (singular)
Direct Known Subclasses
Defined Under Namespace
Modules: Common, Endpoint, Helper, Partner
Constant Summary
Constants included from Configuration
Sophos::Configuration::DEFAULT_ENDPOINT, Sophos::Configuration::DEFAULT_ID_ENDPOINT, Sophos::Configuration::DEFAULT_PAGE_SIZE, Sophos::Configuration::DEFAULT_PAGINATION, Sophos::Configuration::DEFAULT_RATE_LIMIT, Sophos::Configuration::DEFAULT_RATE_PERIOD, Sophos::Configuration::DEFAULT_USER_AGENT, Sophos::Configuration::VALID_OPTIONS_KEYS
Instance Method Summary collapse
-
#client(tenant) ⇒ TenantClient?
Returns a tenant-specific client to access the API host for the given tenant.
-
#tenant_client(api_host, tenant_id) ⇒ TenantClient
Returns a configured tenant client to access APIs for a specific tenant ID and API host.
Methods included from Helper
common_url, def_api_call, define_paged_method, define_plain_method, define_singular_and_plural_methods, endpoint_url, partner_url, sanitize, url
Methods included from Partner
#admin_role_assignment, #admin_role_assignments, #billing_usage, #permission_sets
Methods inherited from API
Methods included from Authentication
Methods included from Configuration
Constructor Details
This class inherits a constructor from Sophos::API
Instance Method Details
#client(tenant) ⇒ TenantClient?
Returns a tenant-specific client to access the API host for the given tenant.
22 23 24 |
# File 'lib/sophos/client.rb', line 22 def client(tenant) tenant_client(tenant.apiHost, tenant.id) if tenant end |
#tenant_client(api_host, tenant_id) ⇒ TenantClient
Returns a configured tenant client to access APIs for a specific tenant ID and API host.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sophos/client.rb', line 36 def tenant_client(api_host, tenant_id) TenantClient.new( self.config.merge( { access_token: access_token, endpoint: api_host, tenant_id: tenant_id, connection_options: { headers: { 'X-Tenant-ID': tenant_id } } } ) ) end |