Class: TrophyApiClient::CreateMetricRequestItem

Inherits:
Object
  • Object
show all
Defined in:
lib/trophy_api_client/types/create_metric_request_item.rb

Overview

A metric to create.

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, key:, unit_type: OMIT, units: OMIT, additional_properties: nil) ⇒ TrophyApiClient::CreateMetricRequestItem

Parameters:

  • name (String)

    The metric name.

  • key (String)

    The metric key. Only alphanumeric characters, hyphens, and underscores are permitted.

  • unit_type (TrophyApiClient::CreateMetricRequestItemUnitType) (defaults to: OMIT)

    The metric unit type. Defaults to ‘number`.

  • units (String) (defaults to: OMIT)

    For ‘unitType: currency`, this must be a supported `MetricCurrency` code such as `USD`. For `number`, this is an optional freeform unit label.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



36
37
38
39
40
41
42
43
44
45
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 36

def initialize(name:, key:, unit_type: OMIT, units: OMIT, additional_properties: nil)
  @name = name
  @key = key
  @unit_type = unit_type if unit_type != OMIT
  @units = units if units != OMIT
  @additional_properties = additional_properties
  @_field_set = { "name": name, "key": key, "unitType": unit_type, "units": units }.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



21
22
23
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 21

def additional_properties
  @additional_properties
end

#keyString (readonly)

Returns The metric key. Only alphanumeric characters, hyphens, and underscores are permitted.

Returns:

  • (String)

    The metric key. Only alphanumeric characters, hyphens, and underscores are permitted.



14
15
16
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 14

def key
  @key
end

#nameString (readonly)

Returns The metric name.

Returns:

  • (String)

    The metric name.



11
12
13
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 11

def name
  @name
end

#unit_typeTrophyApiClient::CreateMetricRequestItemUnitType (readonly)

Returns The metric unit type. Defaults to ‘number`.

Returns:



16
17
18
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 16

def unit_type
  @unit_type
end

#unitsString (readonly)

Returns For ‘unitType: currency`, this must be a supported `MetricCurrency` code such as `USD`. For `number`, this is an optional freeform unit label.

Returns:

  • (String)

    For ‘unitType: currency`, this must be a supported `MetricCurrency` code such as `USD`. For `number`, this is an optional freeform unit label.



19
20
21
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 19

def units
  @units
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::CreateMetricRequestItem

Deserialize a JSON object to an instance of CreateMetricRequestItem

Parameters:

  • json_object (String)

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 51

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  name = parsed_json["name"]
  key = parsed_json["key"]
  unit_type = parsed_json["unitType"]
  units = parsed_json["units"]
  new(
    name: name,
    key: key,
    unit_type: unit_type,
    units: units,
    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)


80
81
82
83
84
85
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 80

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.key.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
  obj.unit_type&.is_a?(TrophyApiClient::CreateMetricRequestItemUnitType) != false || raise("Passed value for field obj.unit_type is not the expected type, validation failed.")
  obj.units&.is_a?(String) != false || raise("Passed value for field obj.units is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of CreateMetricRequestItem to a JSON object

Returns:

  • (String)


70
71
72
# File 'lib/trophy_api_client/types/create_metric_request_item.rb', line 70

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