Class: Sophos::Client

Inherits:
API
  • Object
show all
Includes:
Helper, Partner
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

TenantClient

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

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

#config, #initialize

Methods included from Authentication

#auth_token

Methods included from Configuration

extended, #options, #reset

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.

Examples:

Access tenant-specific APIs:

tenant_client = client(tenant)
tenant_client.some_tenant_specific_api_call

Parameters:

  • tenant (Hash)

    The tenant object containing API host and tenant ID.

Returns:

  • (TenantClient, nil)

    A configured tenant client, or nil if the tenant is not provided.



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.

Examples:

Create a tenant client and access tenant data:

api_host = tenant.apiHost
tenant_id = tenant.id
tenant_client = tenant_client(api_host, tenant_id)

Parameters:

  • api_host (String)

    The API host for the tenant.

  • tenant_id (String)

    The tenant's unique ID.

Returns:

  • (TenantClient)

    A client configured with the tenant's API endpoint and headers.



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