Class: AnalyticsClient::Builder

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

Overview

BUILDER

Builder class for configuring and creating an AnalyticsClient instance. Enables fluent method chaining for setting client configuration options such as data center, OAuth credentials, proxy settings, token store path, and direct access token. Enforces mandatory data center presence on build.

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Initializes a new builder with default (nil) values



38
39
40
41
42
43
44
45
# File 'lib/zoho_analytics_client.rb', line 38

def initialize
  @data_center = nil           # Zoho Analytics data center code (e.g., "US", "EU")
  @oauth = nil                 # OAuth credentials hash (clientId, clientSecret, refreshToken)
  @proxy_details = nil         # Optional proxy configuration hash (host, port, username, password)
  @token_store_path = nil      # Optional filesystem path for encrypted token storage
  @access_token = nil          # Optional direct access token override
  @use_direct_access_token = false  # Flag indicating usage of direct access token (bypass OAuth)
end

Instance Method Details

#buildAnalyticsClient

Builds and returns the configured AnalyticsClient instance. Validates mandatory presence of data center before building.

Returns:

Raises:

  • (ArgumentError)

    if data center is not set or empty



111
112
113
114
115
116
117
# File 'lib/zoho_analytics_client.rb', line 111

def build
  raise ArgumentError, "Data center is mandatory. Use with_data_center(dc) before build." if @data_center.nil? || @data_center.empty?

  client = AnalyticsClient.allocate
  client.send(:setup_from_builder, self)
  client
end

#with_access_token(token) ⇒ Builder

Sets a direct access token on the client, bypassing OAuth. Using this token disables automatic token refresh logic.

Parameters:

  • token (String)

    The direct access token string

Returns:

  • (Builder)

    Returns self for method chaining



100
101
102
103
104
# File 'lib/zoho_analytics_client.rb', line 100

def with_access_token(token)
  @access_token = token
  @use_direct_access_token = true
  self
end

#with_data_center(dc) ⇒ Builder

Sets the Zoho Analytics data center for this client.

Parameters:

  • dc (String)

    Data center code, mandatory (e.g., “US”, “EU”)

Returns:

  • (Builder)

    Returns self for method chaining

Raises:

  • (ArgumentError)

    if dc is nil or empty



52
53
54
55
56
# File 'lib/zoho_analytics_client.rb', line 52

def with_data_center(dc)
  raise ArgumentError, "data_center cannot be empty" if dc.nil? || dc.strip.empty?
  @data_center = dc.strip.upcase
  self
end

#with_oauth(oauth_hash) ⇒ Builder

Sets the OAuth credentials hash for authentication.

Parameters:

  • oauth_hash (Hash)

    OAuth credentials with keys:

    • “clientId”

    • “clientSecret”

    • “refreshToken”

Returns:

  • (Builder)

    Returns self for method chaining



65
66
67
68
# File 'lib/zoho_analytics_client.rb', line 65

def with_oauth(oauth_hash)
  @oauth = oauth_hash
  self
end

#with_proxy(proxy_details) ⇒ Builder

Sets the proxy configuration details.

Parameters:

  • proxy_details (Hash)

    Proxy settings with keys:

    • :host, :port, :username, :password

Returns:

  • (Builder)

    Returns self for method chaining



75
76
77
78
# File 'lib/zoho_analytics_client.rb', line 75

def with_proxy(proxy_details)
  @proxy_details = proxy_details
  self
end

#with_token_store_path(path) ⇒ Builder

Sets the path for encrypted token storage. Raises an error if the directory does not exist.

Parameters:

  • path (String)

    Filesystem directory to store encrypted tokens

Returns:

  • (Builder)

    Returns self for method chaining

Raises:

  • (ArgumentError)

    if the specified directory does not exist



86
87
88
89
90
91
92
# File 'lib/zoho_analytics_client.rb', line 86

def with_token_store_path(path)
  unless Dir.exist?(path)
    raise ArgumentError, "Token store directory does not exist: #{path}"
  end
  @token_store_path = path
  self
end