Class: CoreLibrary::Parameter
- Inherits:
-
Object
- Object
- CoreLibrary::Parameter
- Defined in:
- lib/apimatic-core/types/parameter.rb
Overview
This data class represents the parameter to be sent in the request.
Instance Method Summary collapse
-
#default_content_type(default_content_type) ⇒ Parameter
The setter for the default content type of the multipart request.
-
#get_default_content_type ⇒ String
The getter for the default content type of the multipart request.
-
#get_key ⇒ String
The getter for the parameter key.
-
#get_value ⇒ Object
The getter for the parameter’s actual/converted value where applicable.
-
#initialize ⇒ Parameter
constructor
Initializes a new instance of Parameter.
-
#is_required(is_required) ⇒ Parameter
The setter for the flag if the parameter is required.
-
#key(key) ⇒ Parameter
The setter for the parameter key.
-
#need_to_encode ⇒ Boolean
The getter for the flag if the parameter value is to be encoded.
-
#should_encode(should_encode) ⇒ Parameter
The setter for the flag if the parameter value is to be encoded.
-
#validate ⇒ Object
Validates the parameter value to be sent in the request.
-
#validator(validator) ⇒ Parameter
Setter for the validator.
-
#value(value) ⇒ Parameter
The setter for the parameter value.
-
#value_convertor(value_convertor) ⇒ Parameter
The setter for the function of converting value for form params.
Constructor Details
#initialize ⇒ Parameter
Initializes a new instance of Parameter.
5 6 7 8 9 10 11 12 13 |
# File 'lib/apimatic-core/types/parameter.rb', line 5 def initialize @key = nil @value = nil @is_required = false @should_encode = false @default_content_type = nil @value_convertor = nil @validator = nil end |
Instance Method Details
#default_content_type(default_content_type) ⇒ Parameter
The setter for the default content type of the multipart request.
80 81 82 83 |
# File 'lib/apimatic-core/types/parameter.rb', line 80 def default_content_type(default_content_type) @default_content_type = default_content_type self end |
#get_default_content_type ⇒ String
The getter for the default content type of the multipart request.
87 88 89 |
# File 'lib/apimatic-core/types/parameter.rb', line 87 def get_default_content_type @default_content_type end |
#get_key ⇒ String
The getter for the parameter key.
25 26 27 |
# File 'lib/apimatic-core/types/parameter.rb', line 25 def get_key @key end |
#get_value ⇒ Object
The getter for the parameter’s actual/converted value where applicable.
39 40 41 42 43 |
# File 'lib/apimatic-core/types/parameter.rb', line 39 def get_value return @value_convertor.call(@value) unless @value_convertor.nil? @value end |
#is_required(is_required) ⇒ Parameter
The setter for the flag if the parameter is required. rubocop:disable Naming/PredicateName
49 50 51 52 |
# File 'lib/apimatic-core/types/parameter.rb', line 49 def is_required(is_required) @is_required = is_required self end |
#key(key) ⇒ Parameter
The setter for the parameter key.
18 19 20 21 |
# File 'lib/apimatic-core/types/parameter.rb', line 18 def key(key) @key = key self end |
#need_to_encode ⇒ Boolean
The getter for the flag if the parameter value is to be encoded.
73 74 75 |
# File 'lib/apimatic-core/types/parameter.rb', line 73 def need_to_encode @should_encode end |
#should_encode(should_encode) ⇒ Parameter
The setter for the flag if the parameter value is to be encoded.
58 59 60 61 |
# File 'lib/apimatic-core/types/parameter.rb', line 58 def should_encode(should_encode) @should_encode = should_encode self end |
#validate ⇒ Object
Validates the parameter value to be sent in the request.
101 102 103 104 105 106 107 108 |
# File 'lib/apimatic-core/types/parameter.rb', line 101 def validate raise ArgumentError, "Required parameter #{@key} cannot be nil." if @is_required && @value.nil? return if @validator.nil? validated_type = @validator.call(@value) @value_convertor = proc { |value| validated_type.serialize(value) } if validated_type.is_valid end |
#validator(validator) ⇒ Parameter
Setter for the validator.
94 95 96 97 |
# File 'lib/apimatic-core/types/parameter.rb', line 94 def validator(validator) @validator = validator self end |
#value(value) ⇒ Parameter
The setter for the parameter value.
32 33 34 35 |
# File 'lib/apimatic-core/types/parameter.rb', line 32 def value(value) @value = value self end |
#value_convertor(value_convertor) ⇒ Parameter
The setter for the function of converting value for form params.
66 67 68 69 |
# File 'lib/apimatic-core/types/parameter.rb', line 66 def value_convertor(value_convertor) @value_convertor = value_convertor self end |