Module: Tiktok::Open::Sdk::Helpers::Validators::TokenValidator

Included in:
OpenApi::Post::Publish, OpenApi::User
Defined in:
lib/tiktok/open/sdk/helpers/validators/token_validator.rb

Overview

Provides token validation methods for TikTok Open SDK.

Constant Summary collapse

TOKEN_REGEX =

Regular expression to validate tokens. Ensures the token consists of at least 10 printable characters.

/\A[[:print:]]{10,}\z/

Instance Method Summary collapse

Instance Method Details

#valid_token?(token) ⇒ Boolean

Checks if the given token is a valid string of at least 10 printable characters.

Parameters:

  • token (String)

    The token to check.

Returns:

  • (Boolean)

    true if the token is valid, false otherwise.



18
19
20
# File 'lib/tiktok/open/sdk/helpers/validators/token_validator.rb', line 18

def valid_token?(token)
  token.is_a?(String) && !token.empty? && TOKEN_REGEX.match?(token)
end

#validate_token!(token) ⇒ void

This method returns an undefined value.

Validates the given token and raises an error if it is invalid.

Parameters:

  • token (String)

    The token to validate.

Raises:



27
28
29
30
31
32
# File 'lib/tiktok/open/sdk/helpers/validators/token_validator.rb', line 27

def validate_token!(token)
  return if valid_token?(token)

  raise ::Tiktok::Open::Sdk::RequestValidationError,
        'Invalid token format: must be at least 10 printable characters.'
end