Class: Sophos::API

Inherits:
Object
  • Object
show all
Includes:
Authentication, Configuration, WrAPI::Connection, WrAPI::Request
Defined in:
lib/sophos/api.rb

Overview

Handles API configuration, connections, and authentication. This class manages settings such as API keys, tokens, and endpoint configurations, and includes necessary modules for making authenticated API calls.

Direct Known Subclasses

Client

Constant Summary

Constants included from Configuration

Configuration::DEFAULT_ENDPOINT, Configuration::DEFAULT_ID_ENDPOINT, Configuration::DEFAULT_PAGE_SIZE, Configuration::DEFAULT_PAGINATION, Configuration::DEFAULT_RATE_LIMIT, Configuration::DEFAULT_RATE_PERIOD, Configuration::DEFAULT_USER_AGENT, Configuration::VALID_OPTIONS_KEYS

Instance Method Summary collapse

Methods included from Authentication

#auth_token

Methods included from Configuration

extended, #options, #reset

Constructor Details

#initialize(options = {}) ⇒ API

Initializes a new API instance and applies configuration settings.

Examples:

Initialize a new API instance with custom options:

api = Sophos::API.new(client_id: 'your_client_id', client_secret: 'your_client_secret')

Parameters:

  • options (Hash) (defaults to: {})

    A hash of options to configure the API. These options are merged with global configuration settings.



24
25
26
27
28
29
30
31
32
# File 'lib/sophos/api.rb', line 24

def initialize(options = {})
  # Merge provided options with the global Sophos configuration
  options = Sophos.options.merge(options)

  # Set instance variables for each valid configuration key
  Configuration::VALID_OPTIONS_KEYS.each do |key|
    send("#{key}=", options[key])
  end
end

Instance Method Details

#configHash

Returns the current API configuration as a hash.

Examples:

Retrieve the current API configuration:

api = Sophos::API.new
api.config  # => { client_id: 'abc', client_secret: 'xyz' }

Returns:

  • (Hash)

    A hash of the current API configuration.



42
43
44
45
46
47
48
# File 'lib/sophos/api.rb', line 42

def config
  conf = {}
  Configuration::VALID_OPTIONS_KEYS.each do |key|
    conf[key] = send(key)
  end
  conf
end