class CloudscrapeClient::Executions::Result::File

Constants

EXPECTED_FORMAT
FILE_KEYWORD
ParseError
REGEX

regex101.com/r/zS8xF6/1

UnknownContentType

Attributes

value[R]

Public Class Methods

new(value) click to toggle source
# File lib/cloudscrape_client/executions/result/file.rb, line 25
def initialize(value)
  @value = value
end

Public Instance Methods

content_type() click to toggle source

ContentType list www.freeformatter.com/mime-types-list.html

# File lib/cloudscrape_client/executions/result/file.rb, line 38
def content_type
  @content_type ||= MIME::Types[raw_content_type].first.tap do |result|
    raise UnknownContentType, raw_content_type if result.nil?
  end
end
extension() click to toggle source
# File lib/cloudscrape_client/executions/result/file.rb, line 48
def extension
  content_type.preferred_extension
end
file_name() click to toggle source
# File lib/cloudscrape_client/executions/result/file.rb, line 44
def file_name
  "#{id}-#{provider_id}.#{extension}"
end
id() click to toggle source
# File lib/cloudscrape_client/executions/result/file.rb, line 29
def id
  @id ||= find("id")
end
provider_id() click to toggle source
# File lib/cloudscrape_client/executions/result/file.rb, line 33
def provider_id
  @provider_id ||= find("providerId")
end

Private Instance Methods

find(key) click to toggle source
# File lib/cloudscrape_client/executions/result/file.rb, line 60
def find(key)
  value.match(REGEX)[key]
rescue NoMethodError
  raise ParseError, "Expected: #{EXPECTED_FORMAT}, Got: #{value}"
end
raw_content_type() click to toggle source
# File lib/cloudscrape_client/executions/result/file.rb, line 56
def raw_content_type
  @raw_content_type ||= find("contentType")
end