Module: Tiktok::Open::Sdk::Helpers::Validators::SourceInfoValidator

Included in:
PostPublishValidator
Defined in:
lib/tiktok/open/sdk/helpers/validators/source_info_validator.rb

Overview

Validates source information for TikTok video publishing.

This module provides validation methods for video source parameters including source type (PULL_FROM_URL or FILE_UPLOAD) and their respective required fields.

Examples:

Including the validator in a class

class VideoPublisher
  include Tiktok::Open::Sdk::Helpers::Validators::SourceInfoValidator

  def publish(source_info)
    validate_source_info!(source_info)
    # proceed with publishing
  end
end

Validating PULL_FROM_URL source

source_info = {
  source: 'PULL_FROM_URL',
  video_url: 'https://example.com/video.mp4'
}
validate_source_info!(source_info)

Validating FILE_UPLOAD source

source_info = {
  source: 'FILE_UPLOAD',
  video_size: 10_485_760,
  chunk_size: 1_048_576,
  total_chunk_count: 10
}
validate_source_info!(source_info)

Constant Summary collapse

SOURCE_OPTIONS =

Valid source options for video uploads

%w[
  PULL_FROM_URL
  FILE_UPLOAD
].freeze

Instance Method Summary collapse

Instance Method Details

#validate_source_info!(source_info) ⇒ void

This method returns an undefined value.

Validates source information and raises an error if invalid.

Examples:

Valid PULL_FROM_URL source

validate_source_info!(source: 'PULL_FROM_URL', video_url: 'https://example.com/video.mp4')

Valid FILE_UPLOAD source

validate_source_info!(source: 'FILE_UPLOAD', video_size: 10_485_760)

Invalid source type

validate_source_info!(source: 'INVALID')
# => raises RequestValidationError with source error

Parameters:

  • source_info (Hash, nil)

    The source information to validate

Options Hash (source_info):

  • :source (String)

    Required. Must be 'PULL_FROM_URL' or 'FILE_UPLOAD'

  • :video_url (String)

    Required for PULL_FROM_URL. Non-empty video URL

  • :video_size (Integer)

    Required for FILE_UPLOAD. Positive integer

  • :chunk_size (Integer)

    Optional for FILE_UPLOAD. Positive integer

  • :total_chunk_count (Integer)

    Optional for FILE_UPLOAD. Positive integer

Raises:



66
67
68
69
70
71
72
# File 'lib/tiktok/open/sdk/helpers/validators/source_info_validator.rb', line 66

def validate_source_info!(source_info)
  errors = {}

  validate_source_info(source_info, errors)

  raise_validation_errors!(errors)
end