Class: UU::OS::REST::BinaryValue

Inherits:
DTO
  • Object
show all
Defined in:
uu_os_framework-0.29.16/lib/uu/os/rest/binary_value.rb

Overview

Binary data wrapper used for uploading small data to server and handling binary data response.

Direct Known Subclasses

UDS::Bucket::BlobCreate

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from DTO

#to_json

Constructor Details

- (BinaryValue) initialize(init_data = nil, init_as_retval = false)

Creates new instance of BinaryValue.

Parameters:

  • init_data (Object) (defaults to: nil)

    Data used for instantiation. Accepted values:

    • String with JSON serialized DTO or plain data

    • Hash containing BinaryValue attributes

    • Instance of another BinaryValue

    • Instance of File, Tempfile, IO or StringIO

  • init_as_retval (TrueClass, FalseClass) (defaults to: false)

    If set to true, BinaryValue is initialized as command return value. That means that parameter init_data of type String is either handled as BinaryValue serialized in JSON or Base64 encoded binary data. If set to false (default value), BinaryValue is initialized as user created command input value. That means that parameter init_data of type String is handled as raw data to be sent as binary value.



63
64
65
66
67
68
69
70
71
72
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/binary_value.rb', line 63

def initialize(init_data = nil, init_as_retval = false)
  @serialize_as_stream_handler = true
  @init_as_retval = init_as_retval
  if (@init_as_retval) || (!init_data.kind_of?String) 
    super(init_data)
  else
    super(nil)
    self.data = init_data
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class UU::OS::REST::DTO

Instance Attribute Details

- (String) content_type

Data content type. If not set, value will be determined from given data source or default application/octet-stream will be used for uploading. In case of download, value might be empty (depends on server providing necessary data).

Parameters:

  • (String)

Returns:

  • (String)


40
41
42
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/binary_value.rb', line 40

def content_type
  @content_type
end

- (IO) data

Data payload. Setter accepts values of type File, Tempfile, IO, StringIO or String. Getter always returns "IO" object - something which responds to "read" method. Be careful, reading of raw binary data does not implicitly handle encoding. Result might need to be explicitly converted using "force_encoding" method.

Parameters:

  • (File, Tempfile, IO, StringIO, String)

Returns:

  • (IO)


18
19
20
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/binary_value.rb', line 18

def data
  @data
end

- (String) encoding

Data encoding (used for text-based content types). If not set, value will be determined from given data source or default system value will be used for uploading. In case of download, value might be empty (depends on server providing necessary data).

Parameters:

  • (String)

Returns:

  • (String)


48
49
50
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/binary_value.rb', line 48

def encoding
  @encoding
end

- (String) name

Data name. If not set and given data is instance of File, file base name will be used by default for uploading. In case of download, value might be empty (depends on server providing necessary data).

Parameters:

  • (String)

Returns:

  • (String)


32
33
34
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/binary_value.rb', line 32

def name
  @name
end

- (Numeric) size

Data size. If not set, value will be computed from given data object for uploading. In case of download, value might be empty (depends on server providing necessary data).

Parameters:

  • (Numeric)

Returns:

  • (Numeric)


25
26
27
# File 'uu_os_framework-0.29.16/lib/uu/os/rest/binary_value.rb', line 25

def size
  @size
end