Class: AnalyticsClient::Builder
- Inherits:
-
Object
- Object
- AnalyticsClient::Builder
- 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
-
#build ⇒ AnalyticsClient
Builds and returns the configured AnalyticsClient instance.
-
#initialize ⇒ Builder
constructor
Initializes a new builder with default (nil) values.
-
#with_access_token(token) ⇒ Builder
Sets a direct access token on the client, bypassing OAuth.
-
#with_data_center(dc) ⇒ Builder
Sets the Zoho Analytics data center for this client.
-
#with_oauth(oauth_hash) ⇒ Builder
Sets the OAuth credentials hash for authentication.
-
#with_proxy(proxy_details) ⇒ Builder
Sets the proxy configuration details.
-
#with_token_store_path(path) ⇒ Builder
Sets the path for encrypted token storage.
Constructor Details
#initialize ⇒ Builder
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
#build ⇒ AnalyticsClient
Builds and returns the configured AnalyticsClient instance. Validates mandatory presence of data center before building.
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.
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.
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.
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.
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.
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 |