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, time_unit: OMIT, time_interval: OMIT, additional_properties: nil) ⇒ TrophyApiClient::PointsTrigger

Parameters:

  • (defaults to: OMIT)

    The ID of the trigger

  • (defaults to: OMIT)

    The type of trigger

  • (defaults to: OMIT)

    The points awarded by this trigger.

  • (defaults to: OMIT)

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

  • (defaults to: OMIT)

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

  • (defaults to: OMIT)

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

  • (defaults to: OMIT)

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

  • (defaults to: OMIT)

    If the trigger has type ‘time’, the unit of time after which to award points

  • (defaults to: OMIT)

    If the trigger has type ‘time’, the numer of units of timeUnit after which to award points

  • (defaults to: nil)

    Additional properties unmapped to the current class definition



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/trophy_api_client/types/points_trigger.rb', line 53

def initialize(id: OMIT, type: OMIT, points: OMIT, metric_name: OMIT, metric_threshold: OMIT,
               streak_length_threshold: OMIT, achievement_name: OMIT, time_unit: OMIT, time_interval: 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
  @time_unit = time_unit if time_unit != OMIT
  @time_interval = time_interval if time_interval != 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,
    "timeUnit": time_unit,
    "timeInterval": time_interval
  }.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:

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



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

def achievement_name
  @achievement_name
end

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • Additional properties unmapped to the current class definition



32
33
34
# File 'lib/trophy_api_client/types/points_trigger.rb', line 32

def additional_properties
  @additional_properties
end

#idString (readonly)

Returns The ID of the trigger.

Returns:

  • The ID of the trigger



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

def id
  @id
end

#metric_nameString (readonly)

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

Returns:

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



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

def metric_name
  @metric_name
end

#metric_thresholdInteger (readonly)

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

Returns:

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



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

def metric_threshold
  @metric_threshold
end

#pointsInteger (readonly)

Returns The points awarded by this trigger.

Returns:

  • The points awarded by this trigger.



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

def points
  @points
end

#streak_length_thresholdInteger (readonly)

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

Returns:

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



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

def streak_length_threshold
  @streak_length_threshold
end

#time_intervalInteger (readonly)

Returns If the trigger has type ‘time’, the numer of units of timeUnit after which to award points.

Returns:

  • If the trigger has type ‘time’, the numer of units of timeUnit after which to award points



30
31
32
# File 'lib/trophy_api_client/types/points_trigger.rb', line 30

def time_interval
  @time_interval
end

#time_unitTrophyApiClient::PointsTriggerTimeUnit (readonly)

Returns If the trigger has type ‘time’, the unit of time after which to award points.

Returns:

  • If the trigger has type ‘time’, the unit of time after which to award points



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

def time_unit
  @time_unit
end

#typeTrophyApiClient::PointsTriggerType (readonly)

Returns The type of trigger.

Returns:

  • The type of trigger



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

def type
  @type
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::PointsTrigger

Deserialize a JSON object to an instance of PointsTrigger

Parameters:

Returns:



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/trophy_api_client/types/points_trigger.rb', line 84

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"]
  time_unit = parsed_json["timeUnit"]
  time_interval = parsed_json["timeInterval"]
  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,
    time_unit: time_unit,
    time_interval: time_interval,
    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:

Returns:



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/trophy_api_client/types/points_trigger.rb', line 123

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?(Integer) != 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?(Integer) != false || raise("Passed value for field obj.metric_threshold is not the expected type, validation failed.")
  obj.streak_length_threshold&.is_a?(Integer) != 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.")
  obj.time_unit&.is_a?(TrophyApiClient::PointsTriggerTimeUnit) != false || raise("Passed value for field obj.time_unit is not the expected type, validation failed.")
  obj.time_interval&.is_a?(Integer) != false || raise("Passed value for field obj.time_interval 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:



113
114
115
# File 'lib/trophy_api_client/types/points_trigger.rb', line 113

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