Module: X::MediaUploadValidator

Defined in:
lib/x/media_upload_validator.rb

Overview

Validates media upload parameters

Constant Summary collapse

MEDIA_CATEGORIES =

Valid media category values

%w[dm_gif dm_image dm_video subtitles tweet_gif tweet_image tweet_video].freeze

Class Method Summary collapse

Class Method Details

.validate_file_path!(file_path:) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Validate that a file path exists

Examples:

Validate a file path

MediaUploadValidator.validate_file_path!(file_path: "image.png")

Parameters:

  • file_path (String)

    the file path to validate

Raises:

  • (RuntimeError)

    if the file does not exist



18
19
20
# File 'lib/x/media_upload_validator.rb', line 18

def validate_file_path!(file_path:)
  raise "File not found: #{file_path}" unless File.exist?(file_path)
end

.validate_media_category!(media_category:) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Validate that a media category is valid

Examples:

Validate a media category

MediaUploadValidator.validate_media_category!(media_category: "tweet_image")

Parameters:

  • media_category (String)

    the media category to validate

Raises:

  • (ArgumentError)

    if the media category is invalid



30
31
32
33
34
# File 'lib/x/media_upload_validator.rb', line 30

def validate_media_category!(media_category:)
  return if MEDIA_CATEGORIES.include?(media_category.downcase)

  raise ArgumentError, "Invalid media_category: #{media_category}. Valid values: #{MEDIA_CATEGORIES.join(", ")}"
end