Class: TrophyApiClient::StreakResponse

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(length:, frequency:, streak_history: OMIT, rank: OMIT, started: OMIT, period_start: OMIT, period_end: OMIT, expires: OMIT, additional_properties: nil) ⇒ TrophyApiClient::StreakResponse

Parameters:

  • streak_history (Array<TrophyApiClient::StreakResponseStreakHistoryItem>) (defaults to: OMIT)

    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.

  • rank (Integer) (defaults to: OMIT)

    The user’s rank across all users. Null if the user has no active streak.

  • length (Integer)

    The length of the user’s current streak.

  • frequency (TrophyApiClient::StreakFrequency)

    The frequency of the streak.

  • started (String) (defaults to: OMIT)

    The date the streak started.

  • period_start (String) (defaults to: OMIT)

    The start date of the current streak period.

  • period_end (String) (defaults to: OMIT)

    The end date of the current streak period.

  • expires (String) (defaults to: OMIT)

    The date the streak will expire if the user does not increment a metric.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/trophy_api_client/types/streak_response.rb', line 47

def initialize(length:, frequency:, streak_history: OMIT, rank: OMIT, started: OMIT, period_start: OMIT,
               period_end: OMIT, expires: 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
  @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
  }.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



29
30
31
# File 'lib/trophy_api_client/types/streak_response.rb', line 29

def additional_properties
  @additional_properties
end

#expiresString (readonly)

Returns The date the streak will expire if the user does not increment a metric.

Returns:

  • (String)

    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

#frequencyTrophyApiClient::StreakFrequency (readonly)

Returns The frequency of the streak.

Returns:



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

def frequency
  @frequency
end

#lengthInteger (readonly)

Returns The length of the user’s current streak.

Returns:

  • (Integer)

    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

#period_endString (readonly)

Returns The end date of the current streak period.

Returns:

  • (String)

    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_startString (readonly)

Returns The start date of the current streak period.

Returns:

  • (String)

    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

#rankInteger (readonly)

Returns The user’s rank across all users. Null if the user has no active streak.

Returns:

  • (Integer)

    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

#startedString (readonly)

Returns The date the streak started.

Returns:

  • (String)

    The date the streak started.



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

def started
  @started
end

#streak_historyArray<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.

Returns:



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

Parameters:

  • json_object (String)

Returns:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/trophy_api_client/types/streak_response.rb', line 76

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"]
  new(
    streak_history: streak_history,
    rank: rank,
    length: length,
    frequency: frequency,
    started: started,
    period_start: period_start,
    period_end: period_end,
    expires: expires,
    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)


116
117
118
119
120
121
122
123
124
125
# File 'lib/trophy_api_client/types/streak_response.rb', line 116

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.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of StreakResponse to a JSON object

Returns:

  • (String)


106
107
108
# File 'lib/trophy_api_client/types/streak_response.rb', line 106

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