Class: Parse::Embeddings::ImageFetch::FetchedImage

Inherits:
Struct
  • Object
show all
Defined in:
lib/parse/embeddings/image_fetch.rb

Overview

Value object for a fetched-and-verified image. mime_type is the SNIFFED type (never the server-reported Content-Type). The provider adapters consume this via #to_data_uri.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bytesObject

Returns the value of attribute bytes

Returns:

  • (Object)

    the current value of bytes



68
69
70
# File 'lib/parse/embeddings/image_fetch.rb', line 68

def bytes
  @bytes
end

#mime_typeObject

Returns the value of attribute mime_type

Returns:

  • (Object)

    the current value of mime_type



68
69
70
# File 'lib/parse/embeddings/image_fetch.rb', line 68

def mime_type
  @mime_type
end

#urlObject

Returns the value of attribute url

Returns:

  • (Object)

    the current value of url



68
69
70
# File 'lib/parse/embeddings/image_fetch.rb', line 68

def url
  @url
end

Instance Method Details

#inspectObject Also known as: to_s

Keep multi-MB image payloads out of exception messages and logs.



75
76
77
78
# File 'lib/parse/embeddings/image_fetch.rb', line 75

def inspect
  "#<Parse::Embeddings::ImageFetch::FetchedImage mime_type=#{mime_type.inspect} " \
  "bytes=#{bytes.respond_to?(:bytesize) ? bytes.bytesize : 0} url=#{url.inspect}>"
end

#to_data_uriString

Returns data:<mime>;base64,<payload> for provider wire bodies.

Returns:

  • (String)

    data:<mime>;base64,<payload> for provider wire bodies.



70
71
72
# File 'lib/parse/embeddings/image_fetch.rb', line 70

def to_data_uri
  "data:#{mime_type};base64,#{Base64.strict_encode64(bytes)}"
end