Class: Skykick::API

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

Overview

The ‘Skykick::API` class manages the core configuration and settings for the API client. It allows customization of options like endpoint, user agent, and pagination handling. This class copies configuration settings from the Skykick singleton and provides methods to retrieve the client configuration.

Direct Known Subclasses

Client

Instance Method Summary collapse

Methods included from Authentication

#auth_token

Methods included from Connection

#setup_headers, #setup_logger_filtering

Constructor Details

#initialize(options = {}) ⇒ Skykick::API

Initializes a new ‘Skykick::API` instance with the given options. The options are merged with the global Skykick settings to allow both global and per-instance customization.

Examples:

Create a new API instance with custom options:

api = Skykick::API.new(endpoint: "https://custom-api.endpoint.com", user_agent: "MyApp UA/1.0")

Parameters:

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

    A hash of configuration options. These options can override the global Skykick configuration.



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

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

  # Set each configuration key dynamically using the merged options.
  WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
    send("#{key}=", options[key])
  end
end

Instance Method Details

#configHash

Retrieves the current API configuration as a hash.

Examples:

Retrieve the current API configuration:

api = Skykick::API.new
api.config  # => { :endpoint => "https://apis.skykick.com", :user_agent => "Skykick API/1.0", ... }

Returns:

  • (Hash)

    A hash containing the current configuration settings. The keys in the hash are the same as ‘VALID_OPTIONS_KEYS`.



43
44
45
46
47
48
49
50
# File 'lib/skykick/api.rb', line 43

def config
  conf = {}
  # Iterate over each valid configuration key and retrieve its current value.
  WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
    conf[key] = send key
  end
  conf
end