Class: Merge::Accounting::MultipartFormFieldRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/merge_ruby_client/accounting/types/multipart_form_field_request.rb

Overview

# The MultipartFormField Object

### Description
The `MultipartFormField` object is used to represent fields in an HTTP request
using `multipart/form-data`.
### Usage Example
Create a `MultipartFormField` to define a multipart form entry.

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, data:, encoding: OMIT, file_name: OMIT, content_type: OMIT, additional_properties: nil) ⇒ Merge::Accounting::MultipartFormFieldRequest

Parameters:

  • name (String)

    The name of the form field

  • data (String)

    The data for the form field.

  • encoding (Merge::Accounting::EncodingEnum) (defaults to: OMIT)

    The encoding of the value of ‘data`. Defaults to `RAW` if not defined.

    • ‘RAW` - RAW

    • ‘BASE64` - BASE64

    • ‘GZIP_BASE64` - GZIP_BASE64

  • file_name (String) (defaults to: OMIT)

    The file name of the form field, if the field is for a file.

  • content_type (String) (defaults to: OMIT)

    The MIME type of the file, if the field is for a file.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/merge_ruby_client/accounting/types/multipart_form_field_request.rb', line 47

def initialize(name:, data:, encoding: OMIT, file_name: OMIT, content_type: OMIT, additional_properties: nil)
  @name = name
  @data = data
  @encoding = encoding if encoding != OMIT
  @file_name = file_name if file_name != OMIT
  @content_type = content_type if content_type != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "name": name,
    "data": data,
    "encoding": encoding,
    "file_name": file_name,
    "content_type": content_type
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



30
31
32
# File 'lib/merge_ruby_client/accounting/types/multipart_form_field_request.rb', line 30

def additional_properties
  @additional_properties
end

#content_typeString (readonly)

Returns The MIME type of the file, if the field is for a file.

Returns:

  • (String)

    The MIME type of the file, if the field is for a file.



28
29
30
# File 'lib/merge_ruby_client/accounting/types/multipart_form_field_request.rb', line 28

def content_type
  @content_type
end

#dataString (readonly)

Returns The data for the form field.

Returns:

  • (String)

    The data for the form field.



19
20
21
# File 'lib/merge_ruby_client/accounting/types/multipart_form_field_request.rb', line 19

def data
  @data
end

#encodingMerge::Accounting::EncodingEnum (readonly)

Returns The encoding of the value of ‘data`. Defaults to `RAW` if not defined.

  • ‘RAW` - RAW

  • ‘BASE64` - BASE64

  • ‘GZIP_BASE64` - GZIP_BASE64.

Returns:

  • (Merge::Accounting::EncodingEnum)

    The encoding of the value of ‘data`. Defaults to `RAW` if not defined.

    • ‘RAW` - RAW

    • ‘BASE64` - BASE64

    • ‘GZIP_BASE64` - GZIP_BASE64



24
25
26
# File 'lib/merge_ruby_client/accounting/types/multipart_form_field_request.rb', line 24

def encoding
  @encoding
end

#file_nameString (readonly)

Returns The file name of the form field, if the field is for a file.

Returns:

  • (String)

    The file name of the form field, if the field is for a file.



26
27
28
# File 'lib/merge_ruby_client/accounting/types/multipart_form_field_request.rb', line 26

def file_name
  @file_name
end

#nameString (readonly)

Returns The name of the form field.

Returns:

  • (String)

    The name of the form field



17
18
19
# File 'lib/merge_ruby_client/accounting/types/multipart_form_field_request.rb', line 17

def name
  @name
end

Class Method Details

.from_json(json_object:) ⇒ Merge::Accounting::MultipartFormFieldRequest

Deserialize a JSON object to an instance of MultipartFormFieldRequest

Parameters:

  • json_object (String)

Returns:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/merge_ruby_client/accounting/types/multipart_form_field_request.rb', line 69

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  name = parsed_json["name"]
  data = parsed_json["data"]
  encoding = parsed_json["encoding"]
  file_name = parsed_json["file_name"]
  content_type = parsed_json["content_type"]
  new(
    name: name,
    data: data,
    encoding: encoding,
    file_name: file_name,
    content_type: content_type,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given

hash and check each fields type against the current object's property
definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


100
101
102
103
104
105
106
# File 'lib/merge_ruby_client/accounting/types/multipart_form_field_request.rb', line 100

def self.validate_raw(obj:)
  obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
  obj.data.is_a?(String) != false || raise("Passed value for field obj.data is not the expected type, validation failed.")
  obj.encoding&.is_a?(Merge::Accounting::EncodingEnum) != false || raise("Passed value for field obj.encoding is not the expected type, validation failed.")
  obj.file_name&.is_a?(String) != false || raise("Passed value for field obj.file_name is not the expected type, validation failed.")
  obj.content_type&.is_a?(String) != false || raise("Passed value for field obj.content_type is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of MultipartFormFieldRequest to a JSON object

Returns:

  • (String)


90
91
92
# File 'lib/merge_ruby_client/accounting/types/multipart_form_field_request.rb', line 90

def to_json(*_args)
  @_field_set&.to_json
end