Class: VistarClient::Client

Inherits:
Object
  • Object
show all
Includes:
API::AdServing, API::CreativeCaching, API::UnifiedServing
Defined in:
lib/vistar_client/client.rb

Overview

The main client class for interacting with the Vistar Media API.

This class serves as the primary entry point for all API operations. It delegates to specialized API modules for different endpoint groups.

Examples:

Initialize a client

client = VistarClient::Client.new(
  api_key: 'your-api-key',
  network_id: 'your-network-id'
)

With custom configuration

client = VistarClient::Client.new(
  api_key: 'your-api-key',
  network_id: 'your-network-id',
  api_base_url: 'https://api.vistarmedia.com',
  timeout: 30
)

Constant Summary collapse

DEFAULT_API_BASE_URL =

Default API base URL for Vistar Media

'https://api.vistarmedia.com'
DEFAULT_TIMEOUT =

Default timeout for HTTP requests in seconds

10

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from API::UnifiedServing

#get_loop, #submit_loop_tracking

Methods included from API::CreativeCaching

#get_asset

Methods included from API::AdServing

#request_ad, #submit_proof_of_play

Constructor Details

#initialize(api_key:, network_id:, api_base_url: DEFAULT_API_BASE_URL, timeout: DEFAULT_TIMEOUT) ⇒ Client

Initialize a new Vistar Media API client.

Examples:

client = VistarClient::Client.new(
  api_key: 'your-api-key',
  network_id: 'your-network-id'
)

Parameters:

  • api_key (String)

    the API key for authentication (required)

  • network_id (String)

    the network ID (required)

  • api_base_url (String) (defaults to: DEFAULT_API_BASE_URL)

    the base URL for the API (optional, defaults to production)

  • timeout (Integer) (defaults to: DEFAULT_TIMEOUT)

    the timeout for HTTP requests in seconds (optional, defaults to 10)

Raises:

  • (ArgumentError)

    if api_key or network_id is missing or empty



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/vistar_client/client.rb', line 64

def initialize(api_key:, network_id:, api_base_url: DEFAULT_API_BASE_URL, timeout: DEFAULT_TIMEOUT)
  validate_credentials!(api_key, network_id)

  @api_key = api_key
  @network_id = network_id
  @api_base_url = api_base_url
  @timeout = timeout

  @connection = Connection.new(
    api_key: api_key,
    api_base_url: api_base_url,
    timeout: timeout
  )
end

Instance Attribute Details

#api_base_urlString (readonly)

Returns the base URL for the API.

Returns:

  • (String)

    the base URL for the API



45
46
47
# File 'lib/vistar_client/client.rb', line 45

def api_base_url
  @api_base_url
end

#api_keyString (readonly)

Returns the API key for authentication.

Returns:

  • (String)

    the API key for authentication



39
40
41
# File 'lib/vistar_client/client.rb', line 39

def api_key
  @api_key
end

#network_idString (readonly)

Returns the network ID.

Returns:

  • (String)

    the network ID



42
43
44
# File 'lib/vistar_client/client.rb', line 42

def network_id
  @network_id
end

#timeoutInteger (readonly)

Returns the timeout for HTTP requests in seconds.

Returns:

  • (Integer)

    the timeout for HTTP requests in seconds



48
49
50
# File 'lib/vistar_client/client.rb', line 48

def timeout
  @timeout
end