Class: VistarClient::Connection Private

Inherits:
Object
  • Object
show all
Defined in:
lib/vistar_client/connection.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Manages HTTP connections to the Vistar Media API.

This class encapsulates Faraday connection configuration including:

  • JSON request/response handling

  • Automatic retry logic for transient failures

  • Custom error handling middleware

  • Request/response logging (when VISTAR_DEBUG is set)

  • Timeout configuration

  • Authentication headers

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, api_base_url:, timeout:) ⇒ Connection

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new HTTP connection manager.

Parameters:

  • api_key (String)

    the API key for authentication

  • api_base_url (String)

    the base URL for the API

  • timeout (Integer)

    the timeout for HTTP requests in seconds



34
35
36
37
38
# File 'lib/vistar_client/connection.rb', line 34

def initialize(api_key:, api_base_url:, timeout:)
  @api_key = api_key
  @api_base_url = api_base_url
  @timeout = timeout
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Delegate method_missing to the underlying Faraday connection to maintain backward compatibility with tests.

Parameters:

  • method (Symbol)

    the method name

Returns:

  • (Object)

    the result of the delegated method call

Raises:

  • (NoMethodError)

    if the method is not supported



74
75
76
77
78
79
80
# File 'lib/vistar_client/connection.rb', line 74

def method_missing(method, ...)
  if get.respond_to?(method)
    get.public_send(method, ...)
  else
    super
  end
end

Instance Attribute Details

#api_base_urlString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the base URL for the API.

Returns:

  • (String)

    the base URL for the API



24
25
26
# File 'lib/vistar_client/connection.rb', line 24

def api_base_url
  @api_base_url
end

#api_keyString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the API key for authentication.

Returns:

  • (String)

    the API key for authentication



21
22
23
# File 'lib/vistar_client/connection.rb', line 21

def api_key
  @api_key
end

#timeoutInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the timeout for HTTP requests in seconds.

Returns:

  • (Integer)

    the timeout for HTTP requests in seconds



27
28
29
# File 'lib/vistar_client/connection.rb', line 27

def timeout
  @timeout
end

Instance Method Details

#getFaraday::Connection Also known as: to_faraday

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get or create a Faraday connection instance.

The connection is cached and reused for subsequent requests.

Returns:

  • (Faraday::Connection)

    a configured Faraday connection



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

def get
  @get ||= build_connection
end

#get_request(path, params = {}) ⇒ Faraday::Response

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Make a GET request.

Parameters:

  • path (String)

    the API endpoint path

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

    the query parameters

Returns:

  • (Faraday::Response)

    the HTTP response



64
65
66
# File 'lib/vistar_client/connection.rb', line 64

def get_request(path, params = {})
  get.get(path, params)
end

#post(path, payload) ⇒ Faraday::Response

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Make a POST request.

Parameters:

  • path (String)

    the API endpoint path

  • payload (Hash)

    the request body

Returns:

  • (Faraday::Response)

    the HTTP response



55
56
57
# File 'lib/vistar_client/connection.rb', line 55

def post(path, payload)
  get.post(path, payload)
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if the connection responds to a method.

Parameters:

  • method (Symbol)

    the method name

  • include_private (Boolean) (defaults to: false)

    whether to include private methods

Returns:

  • (Boolean)

    whether the connection responds to the method



87
88
89
# File 'lib/vistar_client/connection.rb', line 87

def respond_to_missing?(method, include_private = false)
  get.respond_to?(method, include_private) || super
end