Class: TrophyApiClient::PointsTrigger

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: OMIT, type: OMIT, points: OMIT, metric_name: OMIT, metric_threshold: OMIT, streak_length_threshold: OMIT, achievement_name: OMIT, additional_properties: nil) ⇒ TrophyApiClient::PointsTrigger

Parameters:

  • id (String) (defaults to: OMIT)

    The ID of the trigger

  • type (TrophyApiClient::PointsTriggerType) (defaults to: OMIT)

    The type of trigger

  • points (Float) (defaults to: OMIT)

    The points awarded by this trigger.

  • metric_name (String) (defaults to: OMIT)

    If the trigger has type ‘metric’, the name of the metric

  • metric_threshold (Float) (defaults to: OMIT)

    If the trigger has type ‘metric’, the threshold of the metric that triggers the points

  • streak_length_threshold (Float) (defaults to: OMIT)

    If the trigger has type ‘streak’, the threshold of the streak that triggers the points

  • achievement_name (String) (defaults to: OMIT)

    If the trigger has type ‘achievement’, the name of the achievement

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/trophy_api_client/types/points_trigger.rb', line 44

def initialize(id: OMIT, type: OMIT, points: OMIT, metric_name: OMIT, metric_threshold: OMIT,
               streak_length_threshold: OMIT, achievement_name: OMIT, additional_properties: nil)
  @id = id if id != OMIT
  @type = type if type != OMIT
  @points = points if points != OMIT
  @metric_name = metric_name if metric_name != OMIT
  @metric_threshold = metric_threshold if metric_threshold != OMIT
  @streak_length_threshold = streak_length_threshold if streak_length_threshold != OMIT
  @achievement_name = achievement_name if achievement_name != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "id": id,
    "type": type,
    "points": points,
    "metricName": metric_name,
    "metricThreshold": metric_threshold,
    "streakLengthThreshold": streak_length_threshold,
    "achievementName": achievement_name
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#achievement_nameString (readonly)

Returns If the trigger has type ‘achievement’, the name of the achievement.

Returns:

  • (String)

    If the trigger has type ‘achievement’, the name of the achievement



24
25
26
# File 'lib/trophy_api_client/types/points_trigger.rb', line 24

def achievement_name
  @achievement_name
end

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



26
27
28
# File 'lib/trophy_api_client/types/points_trigger.rb', line 26

def additional_properties
  @additional_properties
end

#idString (readonly)

Returns The ID of the trigger.

Returns:

  • (String)

    The ID of the trigger



10
11
12
# File 'lib/trophy_api_client/types/points_trigger.rb', line 10

def id
  @id
end

#metric_nameString (readonly)

Returns If the trigger has type ‘metric’, the name of the metric.

Returns:

  • (String)

    If the trigger has type ‘metric’, the name of the metric



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

def metric_name
  @metric_name
end

#metric_thresholdFloat (readonly)

Returns If the trigger has type ‘metric’, the threshold of the metric that triggers the points.

Returns:

  • (Float)

    If the trigger has type ‘metric’, the threshold of the metric that triggers the points



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

def metric_threshold
  @metric_threshold
end

#pointsFloat (readonly)

Returns The points awarded by this trigger.

Returns:

  • (Float)

    The points awarded by this trigger.



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

def points
  @points
end

#streak_length_thresholdFloat (readonly)

Returns If the trigger has type ‘streak’, the threshold of the streak that triggers the points.

Returns:

  • (Float)

    If the trigger has type ‘streak’, the threshold of the streak that triggers the points



22
23
24
# File 'lib/trophy_api_client/types/points_trigger.rb', line 22

def streak_length_threshold
  @streak_length_threshold
end

#typeTrophyApiClient::PointsTriggerType (readonly)

Returns The type of trigger.

Returns:



12
13
14
# File 'lib/trophy_api_client/types/points_trigger.rb', line 12

def type
  @type
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::PointsTrigger

Deserialize a JSON object to an instance of PointsTrigger

Parameters:

  • json_object (String)

Returns:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/trophy_api_client/types/points_trigger.rb', line 71

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  id = parsed_json["id"]
  type = parsed_json["type"]
  points = parsed_json["points"]
  metric_name = parsed_json["metricName"]
  metric_threshold = parsed_json["metricThreshold"]
  streak_length_threshold = parsed_json["streakLengthThreshold"]
  achievement_name = parsed_json["achievementName"]
  new(
    id: id,
    type: type,
    points: points,
    metric_name: metric_name,
    metric_threshold: metric_threshold,
    streak_length_threshold: streak_length_threshold,
    achievement_name: achievement_name,
    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)


106
107
108
109
110
111
112
113
114
# File 'lib/trophy_api_client/types/points_trigger.rb', line 106

def self.validate_raw(obj:)
  obj.id&.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  obj.type&.is_a?(TrophyApiClient::PointsTriggerType) != false || raise("Passed value for field obj.type is not the expected type, validation failed.")
  obj.points&.is_a?(Float) != false || raise("Passed value for field obj.points is not the expected type, validation failed.")
  obj.metric_name&.is_a?(String) != false || raise("Passed value for field obj.metric_name is not the expected type, validation failed.")
  obj.metric_threshold&.is_a?(Float) != false || raise("Passed value for field obj.metric_threshold is not the expected type, validation failed.")
  obj.streak_length_threshold&.is_a?(Float) != false || raise("Passed value for field obj.streak_length_threshold is not the expected type, validation failed.")
  obj.achievement_name&.is_a?(String) != false || raise("Passed value for field obj.achievement_name is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of PointsTrigger to a JSON object

Returns:

  • (String)


96
97
98
# File 'lib/trophy_api_client/types/points_trigger.rb', line 96

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