cuadra-ai-sdk 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +28 -0
  3. data/README.md +99 -0
  4. data/lib/cuadra_ai/api_helper.rb +10 -0
  5. data/lib/cuadra_ai/client.rb +91 -0
  6. data/lib/cuadra_ai/configuration.rb +105 -0
  7. data/lib/cuadra_ai/controllers/base_controller.rb +67 -0
  8. data/lib/cuadra_ai/controllers/chat_controller.rb +41 -0
  9. data/lib/cuadra_ai/controllers/embeds_controller.rb +41 -0
  10. data/lib/cuadra_ai/controllers/models_controller.rb +172 -0
  11. data/lib/cuadra_ai/controllers/oauth_authorization_controller.rb +87 -0
  12. data/lib/cuadra_ai/controllers/usage_controller.rb +70 -0
  13. data/lib/cuadra_ai/exceptions/api_exception.rb +21 -0
  14. data/lib/cuadra_ai/exceptions/error_response_exception.rb +57 -0
  15. data/lib/cuadra_ai/exceptions/oauth_provider_exception.rb +64 -0
  16. data/lib/cuadra_ai/http/api_response.rb +19 -0
  17. data/lib/cuadra_ai/http/auth/oauth_2.rb +139 -0
  18. data/lib/cuadra_ai/http/http_call_back.rb +10 -0
  19. data/lib/cuadra_ai/http/http_method_enum.rb +10 -0
  20. data/lib/cuadra_ai/http/http_request.rb +10 -0
  21. data/lib/cuadra_ai/http/http_response.rb +10 -0
  22. data/lib/cuadra_ai/logging/configuration/api_logging_configuration.rb +114 -0
  23. data/lib/cuadra_ai/logging/sdk_logger.rb +17 -0
  24. data/lib/cuadra_ai/models/base_model.rb +110 -0
  25. data/lib/cuadra_ai/models/chat.rb +102 -0
  26. data/lib/cuadra_ai/models/chat_response_ex.rb +106 -0
  27. data/lib/cuadra_ai/models/content_ex.rb +86 -0
  28. data/lib/cuadra_ai/models/embed.rb +100 -0
  29. data/lib/cuadra_ai/models/embed_response_ex.rb +85 -0
  30. data/lib/cuadra_ai/models/inline_data_ex.rb +87 -0
  31. data/lib/cuadra_ai/models/model_ex.rb +169 -0
  32. data/lib/cuadra_ai/models/oauth_provider_error.rb +45 -0
  33. data/lib/cuadra_ai/models/oauth_token.rb +96 -0
  34. data/lib/cuadra_ai/models/paginated_response_ex_list_model_ex.rb +104 -0
  35. data/lib/cuadra_ai/models/tokens_ex.rb +86 -0
  36. data/lib/cuadra_ai/models/total_usage_ex.rb +86 -0
  37. data/lib/cuadra_ai/models/usage_calculation_ex.rb +77 -0
  38. data/lib/cuadra_ai/models/usage_ex.rb +86 -0
  39. data/lib/cuadra_ai/utilities/date_time_helper.rb +11 -0
  40. data/lib/cuadra_ai/utilities/file_wrapper.rb +28 -0
  41. data/lib/cuadra_ai.rb +63 -0
  42. metadata +126 -0
@@ -0,0 +1,87 @@
1
+ # cuadra_ai
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module CuadraAi
7
+ # OauthAuthorizationController
8
+ class OauthAuthorizationController < BaseController
9
+ # Create a new OAuth 2 token.
10
+ # @param [String] authorization Required parameter: Authorization header in
11
+ # Basic auth format
12
+ # @param [String] code Required parameter: Authorization Code
13
+ # @param [String] redirect_uri Required parameter: Redirect Uri
14
+ # @param [Hash] _field_parameters Additional optional form parameters are
15
+ # supported by this endpoint.
16
+ # @return [ApiResponse] Complete http response with raw body and status code.
17
+ def request_token(authorization,
18
+ code,
19
+ redirect_uri,
20
+ _field_parameters: nil)
21
+ @api_call
22
+ .request(new_request_builder(HttpMethodEnum::POST,
23
+ '/token',
24
+ Server::AUTH_SERVER)
25
+ .form_param(new_parameter('authorization_code', key: 'grant_type'))
26
+ .header_param(new_parameter(authorization, key: 'Authorization')
27
+ .is_required(true))
28
+ .form_param(new_parameter(code, key: 'code')
29
+ .is_required(true))
30
+ .form_param(new_parameter(redirect_uri, key: 'redirect_uri')
31
+ .is_required(true))
32
+ .header_param(new_parameter('application/x-www-form-urlencoded', key: 'content-type'))
33
+ .header_param(new_parameter('application/json', key: 'accept'))
34
+ .additional_form_params(_field_parameters))
35
+ .response(new_response_handler
36
+ .deserializer(APIHelper.method(:custom_type_deserializer))
37
+ .deserialize_into(OauthToken.method(:from_hash))
38
+ .is_api_response(true)
39
+ .local_error('400',
40
+ 'OAuth 2 provider returned an error.',
41
+ OauthProviderException)
42
+ .local_error('401',
43
+ 'OAuth 2 provider says client authentication failed.',
44
+ OauthProviderException))
45
+ .execute
46
+ end
47
+
48
+ # Obtain a new access token using a refresh token
49
+ # @param [String] authorization Required parameter: Authorization header in
50
+ # Basic auth format
51
+ # @param [String] refresh_token Required parameter: Refresh token
52
+ # @param [String] scope Optional parameter: Requested scopes as a
53
+ # space-delimited list.
54
+ # @param [Hash] _field_parameters Additional optional form parameters are
55
+ # supported by this endpoint.
56
+ # @return [ApiResponse] Complete http response with raw body and status code.
57
+ def refresh_token(authorization,
58
+ refresh_token,
59
+ scope: nil,
60
+ _field_parameters: nil)
61
+ @api_call
62
+ .request(new_request_builder(HttpMethodEnum::POST,
63
+ '/token',
64
+ Server::AUTH_SERVER)
65
+ .form_param(new_parameter('refresh_token', key: 'grant_type'))
66
+ .header_param(new_parameter(authorization, key: 'Authorization')
67
+ .is_required(true))
68
+ .form_param(new_parameter(refresh_token, key: 'refresh_token')
69
+ .is_required(true))
70
+ .form_param(new_parameter(scope, key: 'scope'))
71
+ .header_param(new_parameter('application/x-www-form-urlencoded', key: 'content-type'))
72
+ .header_param(new_parameter('application/json', key: 'accept'))
73
+ .additional_form_params(_field_parameters))
74
+ .response(new_response_handler
75
+ .deserializer(APIHelper.method(:custom_type_deserializer))
76
+ .deserialize_into(OauthToken.method(:from_hash))
77
+ .is_api_response(true)
78
+ .local_error('400',
79
+ 'OAuth 2 provider returned an error.',
80
+ OauthProviderException)
81
+ .local_error('401',
82
+ 'OAuth 2 provider says client authentication failed.',
83
+ OauthProviderException))
84
+ .execute
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,70 @@
1
+ # cuadra_ai
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module CuadraAi
7
+ # UsageController
8
+ class UsageController < BaseController
9
+ # This endpoint allows you to calculate the usage, so you get an idea of the
10
+ # amount of tokens that will be consumed.
11
+ # @param [Chat] body Required parameter: TODO: type description here
12
+ # @return [ApiResponse] Complete http response with raw body and status code.
13
+ def calculate_tokens(body)
14
+ @api_call
15
+ .request(new_request_builder(HttpMethodEnum::POST,
16
+ '/usage/tokenize',
17
+ Server::DEFAULT)
18
+ .header_param(new_parameter('application/json', key: 'Content-Type'))
19
+ .body_param(new_parameter(body)
20
+ .is_required(true))
21
+ .header_param(new_parameter('application/json', key: 'accept'))
22
+ .body_serializer(proc do |param| param.to_json unless param.nil? end)
23
+ .auth(Single.new('OAuth2')))
24
+ .response(new_response_handler
25
+ .deserializer(APIHelper.method(:custom_type_deserializer))
26
+ .deserialize_into(UsageCalculationEx.method(:from_hash))
27
+ .is_api_response(true)
28
+ .local_error('400',
29
+ 'Bad request, read again our documentation or contact support'\
30
+ ' for guidance.',
31
+ ErrorResponseException)
32
+ .local_error('401',
33
+ 'Not authorized, check our OAuth2 doc.',
34
+ ErrorResponseException)
35
+ .local_error('500',
36
+ 'Internal error, if this error persist, please contact support'\
37
+ '.',
38
+ ErrorResponseException))
39
+ .execute
40
+ end
41
+
42
+ # This endpoint calculates the amount of tokens used by the user in the
43
+ # given month.
44
+ # @return [ApiResponse] Complete http response with raw body and status code.
45
+ def total_usage
46
+ @api_call
47
+ .request(new_request_builder(HttpMethodEnum::GET,
48
+ '/usage/totals',
49
+ Server::DEFAULT)
50
+ .header_param(new_parameter('application/json', key: 'accept'))
51
+ .auth(Single.new('OAuth2')))
52
+ .response(new_response_handler
53
+ .deserializer(APIHelper.method(:custom_type_deserializer))
54
+ .deserialize_into(TotalUsageEx.method(:from_hash))
55
+ .is_api_response(true)
56
+ .local_error('400',
57
+ 'Bad request, read again our documentation or contact support'\
58
+ ' for guidance.',
59
+ ErrorResponseException)
60
+ .local_error('401',
61
+ 'Not authorized, check our OAuth2 doc.',
62
+ ErrorResponseException)
63
+ .local_error('500',
64
+ 'Internal error, if this error persist, please contact support'\
65
+ '.',
66
+ ErrorResponseException))
67
+ .execute
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,21 @@
1
+ # cuadra_ai
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module CuadraAi
7
+ # Class for exceptions when there is a network error, status code error, etc.
8
+ class APIException < CoreLibrary::ApiException
9
+ # Provides a human-readable string representation of the object.
10
+ def to_s
11
+ class_name = self.class.name.split('::').last
12
+ "<#{class_name} status_code: #{@response_code}, reason: #{@reason}>"
13
+ end
14
+
15
+ # Provides a debugging-friendly string with detailed object information.
16
+ def inspect
17
+ class_name = self.class.name.split('::').last
18
+ "<#{class_name} status_code: #{@response_code.inspect}, reason: #{@reason.inspect}>"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,57 @@
1
+ # cuadra_ai
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module CuadraAi
7
+ # Standard error response format for Cuadra AI
8
+ class ErrorResponseException < APIException
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
12
+ # A message describing the error
13
+ # @return [String]
14
+ attr_accessor :message
15
+
16
+ # HTTP status code
17
+ # @return [Integer]
18
+ attr_accessor :status
19
+
20
+ # Optional: Field-specific validation errors
21
+ # @return [Hash[String, String]]
22
+ attr_accessor :field_errors
23
+
24
+ # The constructor.
25
+ # @param [String] reason The reason for raising an exception.
26
+ # @param [HttpResponse] response The HttpReponse of the API call.
27
+ def initialize(reason, response)
28
+ super(reason, response)
29
+ hash = APIHelper.json_deserialize(@response.raw_body)
30
+ unbox(hash)
31
+ end
32
+
33
+ # Populates this object by extracting properties from a hash.
34
+ # @param [Hash] hash The deserialized response sent by the server in the
35
+ # response body.
36
+ def unbox(hash)
37
+ return nil unless hash
38
+
39
+ @message = hash.key?('message') ? hash['message'] : SKIP
40
+ @status = hash.key?('status') ? hash['status'] : SKIP
41
+ @field_errors = hash.key?('field_errors') ? hash['field_errors'] : SKIP
42
+ end
43
+
44
+ # Provides a human-readable string representation of the object.
45
+ def to_s
46
+ class_name = self.class.name.split('::').last
47
+ "<#{class_name} message: #{@message}, status: #{@status}, field_errors: #{@field_errors}>"
48
+ end
49
+
50
+ # Provides a debugging-friendly string with detailed object information.
51
+ def inspect
52
+ class_name = self.class.name.split('::').last
53
+ "<#{class_name} message: #{@message.inspect}, status: #{@status.inspect}, field_errors:"\
54
+ " #{@field_errors.inspect}>"
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,64 @@
1
+ # cuadra_ai
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module CuadraAi
7
+ # OAuth 2 Authorization endpoint exception.
8
+ class OauthProviderException < APIException
9
+ SKIP = Object.new
10
+ private_constant :SKIP
11
+
12
+ # Gets or sets error code.
13
+ # @return [OauthProviderError]
14
+ attr_accessor :error
15
+
16
+ # Gets or sets human-readable text providing additional information on
17
+ # error.
18
+ # Used to assist the client developer in understanding the error that
19
+ # occurred.
20
+ # @return [String]
21
+ attr_accessor :error_description
22
+
23
+ # Gets or sets a URI identifying a human-readable web page with information
24
+ # about the error, used to provide the client developer with additional
25
+ # information about the error.
26
+ # @return [String]
27
+ attr_accessor :error_uri
28
+
29
+ # The constructor.
30
+ # @param [String] reason The reason for raising an exception.
31
+ # @param [HttpResponse] response The HttpReponse of the API call.
32
+ def initialize(reason, response)
33
+ super(reason, response)
34
+ hash = APIHelper.json_deserialize(@response.raw_body)
35
+ unbox(hash)
36
+ end
37
+
38
+ # Populates this object by extracting properties from a hash.
39
+ # @param [Hash] hash The deserialized response sent by the server in the
40
+ # response body.
41
+ def unbox(hash)
42
+ return nil unless hash
43
+
44
+ @error = hash.key?('error') ? hash['error'] : nil
45
+ @error_description =
46
+ hash.key?('error_description') ? hash['error_description'] : SKIP
47
+ @error_uri = hash.key?('error_uri') ? hash['error_uri'] : SKIP
48
+ end
49
+
50
+ # Provides a human-readable string representation of the object.
51
+ def to_s
52
+ class_name = self.class.name.split('::').last
53
+ "<#{class_name} error: #{@error}, error_description: #{@error_description}, error_uri:"\
54
+ " #{@error_uri}>"
55
+ end
56
+
57
+ # Provides a debugging-friendly string with detailed object information.
58
+ def inspect
59
+ class_name = self.class.name.split('::').last
60
+ "<#{class_name} error: #{@error.inspect}, error_description: #{@error_description.inspect},"\
61
+ " error_uri: #{@error_uri.inspect}>"
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,19 @@
1
+ # cuadra_ai
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module CuadraAi
7
+ # Http response received.
8
+ class ApiResponse < CoreLibrary::ApiResponse
9
+ # The constructor
10
+ # @param [HttpResponse] http_response The original, raw response from the api.
11
+ # @param [Object] data The data field specified for the response.
12
+ # @param [Array<String>] errors Any errors returned by the server.
13
+ def initialize(http_response,
14
+ data: nil,
15
+ errors: nil)
16
+ super
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,139 @@
1
+ # cuadra_ai
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module CuadraAi
7
+ # Utility class for OAuth 2 authorization and token management.
8
+ class Oauth2 < CoreLibrary::HeaderAuth
9
+ include CoreLibrary
10
+ # Display error message on occurrence of authentication failure.
11
+ # @returns [String] The oAuth error message.
12
+ def error_message
13
+ 'AuthorizationCodeAuth: OAuthToken is undefined or expired.'
14
+ end
15
+
16
+ # Initialization constructor.
17
+ def initialize(authorization_code_auth_credentials, config)
18
+ auth_params = {}
19
+ @_oauth_client_id = authorization_code_auth_credentials.oauth_client_id unless
20
+ authorization_code_auth_credentials.nil? || authorization_code_auth_credentials.oauth_client_id.nil?
21
+ @_oauth_client_secret = authorization_code_auth_credentials.oauth_client_secret unless
22
+ authorization_code_auth_credentials.nil? || authorization_code_auth_credentials.oauth_client_secret.nil?
23
+ @_oauth_redirect_uri = authorization_code_auth_credentials.oauth_redirect_uri unless
24
+ authorization_code_auth_credentials.nil? || authorization_code_auth_credentials.oauth_redirect_uri.nil?
25
+ @_oauth_token = authorization_code_auth_credentials.oauth_token unless
26
+ authorization_code_auth_credentials.nil? || authorization_code_auth_credentials.oauth_token.nil?
27
+ @_config = config
28
+ @_o_auth_api = OauthAuthorizationController.new(config)
29
+ auth_params[:Authorization] = "Bearer #{@_oauth_token.access_token}" unless @_oauth_token.nil?
30
+
31
+ super auth_params
32
+ end
33
+
34
+ # Validates the oAuth token.
35
+ # @return [Boolean] true if the token is present and not expired.
36
+ def valid
37
+ !@_oauth_token.nil? && !token_expired?(@_oauth_token)
38
+ end
39
+
40
+ # Builds and returns an authorization URL.
41
+ # The user is expected to obtain an authorization code from this URL and then call the
42
+ # fetch token function with that authorization code.
43
+ # @param [String] state An opaque state string.
44
+ # @param [Hash] additional_params Any additional query parameters to be added to the URL.
45
+ # @return [String] The authorization URL.
46
+ def get_authorization_url(state: nil, additional_params: nil)
47
+ auth_url = @_config.get_base_uri_executor.call(Server::AUTH_SERVER)
48
+ auth_url += '/authorize'
49
+ query_params = {
50
+ 'response_type' => 'code',
51
+ 'client_id' => @_oauth_client_id,
52
+ 'redirect_uri' => @_oauth_redirect_uri
53
+ }
54
+ query_params['scope'] = Array(@_o_auth_scopes).compact.join(' ') if @_o_auth_scopes
55
+ query_params['state'] = state if state
56
+ query_params.merge!(additional_params) if additional_params
57
+ auth_url = APIHelper.append_url_with_query_parameters(auth_url,
58
+ query_params)
59
+ APIHelper.clean_url(auth_url)
60
+ end
61
+
62
+ # Builds the basic auth header for endpoints in the OAuth Authorization Controller.
63
+ # @return [String] The value of the Authentication header.
64
+ def build_basic_auth_header
65
+ "Basic #{AuthHelper.get_base64_encoded_value(@_oauth_client_id, @_oauth_client_secret)}"
66
+ end
67
+
68
+ # Fetches the token.
69
+ # @param [String] auth_code The authentication code.
70
+ # @param [Hash] additional_params Any additional form parameters.
71
+ # @return [OAuthToken] The oAuth token instance.
72
+ def fetch_token(auth_code, additional_params: nil)
73
+ token = @_o_auth_api.request_token(
74
+ build_basic_auth_header,
75
+ auth_code,
76
+ @_oauth_redirect_uri,
77
+ _field_parameters: additional_params
78
+ ).data
79
+ if token.respond_to?('expires_in') && !token.expires_in.nil?
80
+ token.expiry = AuthHelper.get_token_expiry(token.expires_in, Time.now.utc.to_i)
81
+ end
82
+ token
83
+ end
84
+
85
+ # Checks if OAuth token has expired.
86
+ # @param [OAuthToken] token The oAuth token instance.
87
+ # @return [Boolean] true if the token is present and not expired.
88
+ def token_expired?(token)
89
+ token.respond_to?('expiry') && AuthHelper.token_expired?(token.expiry)
90
+ end
91
+
92
+ # Refreshes OAuth token.
93
+ # @param [Hash] additional_params Any additional form parameters.
94
+ # @return [OAuthToken] The oAuth token instance.
95
+ def refresh_token(additional_params: nil)
96
+ token = @_o_auth_api.refresh_token(
97
+ build_basic_auth_header,
98
+ @_oauth_token.refresh_token,
99
+ _field_parameters: additional_params
100
+ ).data
101
+ if token.respond_to?('expires_in') && !token.expires_in.nil?
102
+ token.expiry = AuthHelper.get_token_expiry(token.expires_in, Time.now.utc.to_i)
103
+ end
104
+ token
105
+ end
106
+ end
107
+
108
+ # Data class for AuthorizationCodeAuthCredentials.
109
+ class AuthorizationCodeAuthCredentials
110
+ attr_reader :oauth_client_id, :oauth_client_secret, :oauth_redirect_uri,
111
+ :oauth_token
112
+
113
+ def initialize(oauth_client_id:, oauth_client_secret:, oauth_redirect_uri:,
114
+ oauth_token: nil)
115
+ raise ArgumentError, 'oauth_client_id cannot be nil' if oauth_client_id.nil?
116
+ raise ArgumentError, 'oauth_client_secret cannot be nil' if oauth_client_secret.nil?
117
+ raise ArgumentError, 'oauth_redirect_uri cannot be nil' if oauth_redirect_uri.nil?
118
+
119
+ @oauth_client_id = oauth_client_id
120
+ @oauth_client_secret = oauth_client_secret
121
+ @oauth_redirect_uri = oauth_redirect_uri
122
+ @oauth_token = oauth_token
123
+ end
124
+
125
+ def clone_with(oauth_client_id: nil, oauth_client_secret: nil,
126
+ oauth_redirect_uri: nil, oauth_token: nil)
127
+ oauth_client_id ||= self.oauth_client_id
128
+ oauth_client_secret ||= self.oauth_client_secret
129
+ oauth_redirect_uri ||= self.oauth_redirect_uri
130
+ oauth_token ||= self.oauth_token
131
+
132
+ AuthorizationCodeAuthCredentials.new(
133
+ oauth_client_id: oauth_client_id,
134
+ oauth_client_secret: oauth_client_secret,
135
+ oauth_redirect_uri: oauth_redirect_uri, oauth_token: oauth_token
136
+ )
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,10 @@
1
+ # cuadra_ai
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module CuadraAi
7
+ # HttpCallBack allows defining callables for pre and post API calls.
8
+ class HttpCallBack < CoreLibrary::HttpCallback
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # cuadra_ai
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module CuadraAi
7
+ # HTTP Methods Enumeration.
8
+ class HttpMethodEnum < CoreLibrary::HttpMethod
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # cuadra_ai
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module CuadraAi
7
+ # Represents a single Http Request.
8
+ class HttpRequest < CoreLibrary::HttpRequest
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # cuadra_ai
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module CuadraAi
7
+ # Http response received.
8
+ class HttpResponse < CoreLibrary::HttpResponse
9
+ end
10
+ end
@@ -0,0 +1,114 @@
1
+ # cuadra_ai
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module CuadraAi
7
+ # Initializes a new instance of RequestLoggingConfiguration.
8
+ class RequestLoggingConfiguration < CoreLibrary::ApiRequestLoggingConfiguration
9
+ # @param log_body [Boolean] Indicates whether the message body should be logged. Default is false.
10
+ # @param log_headers [Boolean] Indicates whether the message headers should be logged. Default is false.
11
+ # @param headers_to_exclude [Array<String>] Array of headers not displayed in logging. Default is an empty array.
12
+ # @param headers_to_include [Array<String>] Array of headers to be displayed in logging. Default is an empty array.
13
+ # @param headers_to_unmask [Array<String>] Array of headers which values are non-sensitive to display in logging.
14
+ # Default is an empty array.
15
+ def initialize(log_body: false, log_headers: false, headers_to_include: nil,
16
+ headers_to_exclude: nil, headers_to_unmask: nil,
17
+ include_query_in_path: false)
18
+ super(
19
+ log_body,
20
+ log_headers,
21
+ headers_to_exclude,
22
+ headers_to_include,
23
+ headers_to_unmask,
24
+ include_query_in_path
25
+ )
26
+ end
27
+
28
+ def clone_with(log_body: nil, log_headers: nil, headers_to_include: nil,
29
+ headers_to_exclude: nil, headers_to_unmask: nil, include_query_in_path: nil)
30
+ log_body ||= self.log_body
31
+ log_headers ||= self.log_headers
32
+ headers_to_include ||= self.headers_to_include
33
+ headers_to_exclude ||= self.headers_to_exclude
34
+ headers_to_unmask ||= self.headers_to_unmask
35
+ include_query_in_path ||= self.include_query_in_path
36
+
37
+ RequestLoggingConfiguration.class.new(log_body: log_body, log_headers: log_headers,
38
+ headers_to_include: headers_to_include,
39
+ headers_to_exclude: headers_to_exclude,
40
+ headers_to_unmask: headers_to_unmask,
41
+ include_query_in_path: include_query_in_path)
42
+ end
43
+ end
44
+
45
+ # Initializes a new instance of ResponseLoggingConfiguration.
46
+ class ResponseLoggingConfiguration < CoreLibrary::ApiResponseLoggingConfiguration
47
+ # @param log_body [Boolean] Indicates whether the message body should be logged. Default is false.
48
+ # @param log_headers [Boolean] Indicates whether the message headers should be logged. Default is false.
49
+ # @param headers_to_exclude [Array<String>] Array of headers not displayed in logging. Default is an empty array.
50
+ # @param headers_to_include [Array<String>] Array of headers to be displayed in logging. Default is an empty array.
51
+ # @param headers_to_unmask [Array<String>] Array of headers which values are non-sensitive to display in logging.
52
+ # Default is an empty array.
53
+ def initialize(log_body: false, log_headers: false, headers_to_include: nil,
54
+ headers_to_exclude: nil, headers_to_unmask: nil)
55
+ super(
56
+ log_body,
57
+ log_headers,
58
+ headers_to_exclude,
59
+ headers_to_include,
60
+ headers_to_unmask
61
+ )
62
+ end
63
+
64
+ def clone_with(log_body: nil, log_headers: nil, headers_to_include: nil,
65
+ headers_to_exclude: nil, headers_to_unmask: nil)
66
+ log_body ||= self.log_body
67
+ log_headers ||= self.log_headers
68
+ headers_to_include ||= self.headers_to_include
69
+ headers_to_exclude ||= self.headers_to_exclude
70
+ headers_to_unmask ||= self.headers_to_unmask
71
+
72
+ ResponseLoggingConfiguration.new(log_body: log_body, log_headers: log_headers,
73
+ headers_to_include: headers_to_include,
74
+ headers_to_exclude: headers_to_exclude,
75
+ headers_to_unmask: headers_to_unmask)
76
+ end
77
+ end
78
+
79
+ # Initializes a new instance of LoggingConfiguration.
80
+ class LoggingConfiguration < CoreLibrary::ApiLoggingConfiguration
81
+ # @param logger [LoggerInterface] The logger to use for logging messages.
82
+ # @param log_level [LogLevel] The log level to determine which messages should be logged.
83
+ # @param request_logging_config [RequestLoggingConfiguration] Options for logging HTTP requests.
84
+ # @param response_logging_config [ResponseLoggingConfiguration] Options for logging HTTP responses.
85
+ # @param mask_sensitive_headers [Boolean] Indicates whether sensitive headers should be masked in logged messages.
86
+ def initialize(logger: nil, log_level: nil, mask_sensitive_headers: true,
87
+ request_logging_config: nil,
88
+ response_logging_config: nil)
89
+ request_logging_config ||= RequestLoggingConfiguration.new
90
+ response_logging_config ||= ResponseLoggingConfiguration.new
91
+ super(
92
+ logger,
93
+ log_level,
94
+ request_logging_config,
95
+ response_logging_config,
96
+ mask_sensitive_headers
97
+ )
98
+ end
99
+
100
+ def clone_with(logger: nil, log_level: nil, mask_sensitive_headers: nil,
101
+ request_logging_config: nil, response_logging_config: nil)
102
+ logger ||= self.logger
103
+ log_level ||= self.log_level
104
+ mask_sensitive_headers = self.mask_sensitive_headers ||= mask_sensitive_headers
105
+ request_logging_config ||= self.request_logging_config.clone
106
+ response_logging_config ||= self.response_logging_config.clone
107
+
108
+ LoggingConfiguration.new(logger: logger, log_level: log_level,
109
+ mask_sensitive_headers: mask_sensitive_headers,
110
+ request_logging_config: request_logging_config,
111
+ response_logging_config: response_logging_config)
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,17 @@
1
+ # cuadra_ai
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module CuadraAi
7
+ # Represents the generic logger facade
8
+ class AbstractLogger < Logger
9
+ # Logs a message with a specified log level and additional parameters.
10
+ # @param level [Symbol] The log level of the message.
11
+ # @param message [String] The message to log.
12
+ # @param params [Hash] Additional parameters to include in the log message.
13
+ def log(level, message, params)
14
+ raise NotImplementedError, 'This method needs to be implemented in a child class.'
15
+ end
16
+ end
17
+ end