Class: TrophyApiClient::StreakResponse
- Inherits:
-
Object
- Object
- TrophyApiClient::StreakResponse
- Defined in:
- lib/trophy_api_client/types/streak_response.rb
Overview
An object representing the user’s streak.
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#expires ⇒ String
readonly
The date the streak will expire if the user does not increment a metric.
-
#freeze_auto_earn_amount ⇒ Integer
readonly
The amount of streak freezes the user will earn per interval.
-
#freeze_auto_earn_interval ⇒ Integer
readonly
The interval at which the user will earn streak freezes, in days.
-
#freezes ⇒ Integer
readonly
The number of available streak freezes.
-
#frequency ⇒ TrophyApiClient::StreakFrequency
readonly
The frequency of the streak.
-
#length ⇒ Integer
readonly
The length of the user’s current streak.
-
#max_freezes ⇒ Integer
readonly
The maximum number of streak freezes a user can have.
-
#period_end ⇒ String
readonly
The end date of the current streak period.
-
#period_start ⇒ String
readonly
The start date of the current streak period.
-
#rank ⇒ Integer
readonly
The user’s rank across all users.
-
#started ⇒ String
readonly
The date the streak started.
-
#streak_history ⇒ Array<TrophyApiClient::StreakResponseStreakHistoryItem>
readonly
A list of the user’s past streak periods up through the current period.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ TrophyApiClient::StreakResponse
Deserialize a JSON object to an instance of StreakResponse.
-
.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.
Instance Method Summary collapse
- #initialize(length:, frequency:, streak_history: OMIT, rank: OMIT, started: OMIT, period_start: OMIT, period_end: OMIT, expires: OMIT, freezes: OMIT, max_freezes: OMIT, freeze_auto_earn_interval: OMIT, freeze_auto_earn_amount: OMIT, additional_properties: nil) ⇒ TrophyApiClient::StreakResponse constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of StreakResponse to a JSON object.
Constructor Details
#initialize(length:, frequency:, streak_history: OMIT, rank: OMIT, started: OMIT, period_start: OMIT, period_end: OMIT, expires: OMIT, freezes: OMIT, max_freezes: OMIT, freeze_auto_earn_interval: OMIT, freeze_auto_earn_amount: OMIT, additional_properties: nil) ⇒ TrophyApiClient::StreakResponse
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 67 def initialize(length:, frequency:, streak_history: OMIT, rank: OMIT, started: OMIT, period_start: OMIT, period_end: OMIT, expires: OMIT, freezes: OMIT, max_freezes: OMIT, freeze_auto_earn_interval: OMIT, freeze_auto_earn_amount: OMIT, additional_properties: nil) @streak_history = streak_history if streak_history != OMIT @rank = rank if rank != OMIT @length = length @frequency = frequency @started = started if started != OMIT @period_start = period_start if period_start != OMIT @period_end = period_end if period_end != OMIT @expires = expires if expires != OMIT @freezes = freezes if freezes != OMIT @max_freezes = max_freezes if max_freezes != OMIT @freeze_auto_earn_interval = freeze_auto_earn_interval if freeze_auto_earn_interval != OMIT @freeze_auto_earn_amount = freeze_auto_earn_amount if freeze_auto_earn_amount != OMIT @additional_properties = additional_properties @_field_set = { "streakHistory": streak_history, "rank": rank, "length": length, "frequency": frequency, "started": started, "periodStart": period_start, "periodEnd": period_end, "expires": expires, "freezes": freezes, "maxFreezes": max_freezes, "freezeAutoEarnInterval": freeze_auto_earn_interval, "freezeAutoEarnAmount": freeze_auto_earn_amount }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
41 42 43 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 41 def additional_properties @additional_properties end |
#expires ⇒ String (readonly)
Returns The date the streak will expire if the user does not increment a metric.
27 28 29 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 27 def expires @expires end |
#freeze_auto_earn_amount ⇒ Integer (readonly)
Returns The amount of streak freezes the user will earn per interval. Only present if the organization has enabled streak freeze auto-earn.
39 40 41 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 39 def freeze_auto_earn_amount @freeze_auto_earn_amount end |
#freeze_auto_earn_interval ⇒ Integer (readonly)
Returns The interval at which the user will earn streak freezes, in days. Only present if the organization has enabled streak freeze auto-earn.
36 37 38 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 36 def freeze_auto_earn_interval @freeze_auto_earn_interval end |
#freezes ⇒ Integer (readonly)
Returns The number of available streak freezes. Only present if the organization has enabled streak freezes.
30 31 32 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 30 def freezes @freezes end |
#frequency ⇒ TrophyApiClient::StreakFrequency (readonly)
Returns The frequency of the streak.
19 20 21 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 19 def frequency @frequency end |
#length ⇒ Integer (readonly)
Returns The length of the user’s current streak.
17 18 19 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 17 def length @length end |
#max_freezes ⇒ Integer (readonly)
Returns The maximum number of streak freezes a user can have. Only present if the organization has enabled streak freezes.
33 34 35 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 33 def max_freezes @max_freezes end |
#period_end ⇒ String (readonly)
Returns The end date of the current streak period.
25 26 27 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 25 def period_end @period_end end |
#period_start ⇒ String (readonly)
Returns The start date of the current streak period.
23 24 25 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 23 def period_start @period_start end |
#rank ⇒ Integer (readonly)
Returns The user’s rank across all users. Null if the user has no active streak.
15 16 17 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 15 def rank @rank end |
#started ⇒ String (readonly)
Returns The date the streak started.
21 22 23 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 21 def started @started end |
#streak_history ⇒ Array<TrophyApiClient::StreakResponseStreakHistoryItem> (readonly)
Returns A list of the user’s past streak periods up through the current period. Each period includes the start and end dates and the length of the streak.
13 14 15 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 13 def streak_history @streak_history end |
Class Method Details
.from_json(json_object:) ⇒ TrophyApiClient::StreakResponse
Deserialize a JSON object to an instance of StreakResponse
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 104 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) streak_history = parsed_json["streakHistory"]&.map do |item| item = item.to_json TrophyApiClient::StreakResponseStreakHistoryItem.from_json(json_object: item) end rank = parsed_json["rank"] length = parsed_json["length"] frequency = parsed_json["frequency"] started = parsed_json["started"] period_start = parsed_json["periodStart"] period_end = parsed_json["periodEnd"] expires = parsed_json["expires"] freezes = parsed_json["freezes"] max_freezes = parsed_json["maxFreezes"] freeze_auto_earn_interval = parsed_json["freezeAutoEarnInterval"] freeze_auto_earn_amount = parsed_json["freezeAutoEarnAmount"] new( streak_history: streak_history, rank: rank, length: length, frequency: frequency, started: started, period_start: period_start, period_end: period_end, expires: expires, freezes: freezes, max_freezes: max_freezes, freeze_auto_earn_interval: freeze_auto_earn_interval, freeze_auto_earn_amount: freeze_auto_earn_amount, 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.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 152 def self.validate_raw(obj:) obj.streak_history&.is_a?(Array) != false || raise("Passed value for field obj.streak_history is not the expected type, validation failed.") obj.rank&.is_a?(Integer) != false || raise("Passed value for field obj.rank is not the expected type, validation failed.") obj.length.is_a?(Integer) != false || raise("Passed value for field obj.length is not the expected type, validation failed.") obj.frequency.is_a?(TrophyApiClient::StreakFrequency) != false || raise("Passed value for field obj.frequency is not the expected type, validation failed.") obj.started&.is_a?(String) != false || raise("Passed value for field obj.started is not the expected type, validation failed.") obj.period_start&.is_a?(String) != false || raise("Passed value for field obj.period_start is not the expected type, validation failed.") obj.period_end&.is_a?(String) != false || raise("Passed value for field obj.period_end is not the expected type, validation failed.") obj.expires&.is_a?(String) != false || raise("Passed value for field obj.expires is not the expected type, validation failed.") obj.freezes&.is_a?(Integer) != false || raise("Passed value for field obj.freezes is not the expected type, validation failed.") obj.max_freezes&.is_a?(Integer) != false || raise("Passed value for field obj.max_freezes is not the expected type, validation failed.") obj.freeze_auto_earn_interval&.is_a?(Integer) != false || raise("Passed value for field obj.freeze_auto_earn_interval is not the expected type, validation failed.") obj.freeze_auto_earn_amount&.is_a?(Integer) != false || raise("Passed value for field obj.freeze_auto_earn_amount is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ String
Serialize an instance of StreakResponse to a JSON object
142 143 144 |
# File 'lib/trophy_api_client/types/streak_response.rb', line 142 def to_json(*_args) @_field_set&.to_json end |