Class: TrophyApiClient::StreakAchievementResponse

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

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(trigger:, streak_length:, id:, name:, badge_url: OMIT, key: OMIT, achieved_at: OMIT, additional_properties: nil) ⇒ TrophyApiClient::StreakAchievementResponse

Parameters:

  • trigger (String)

    The trigger of the achievement, in this case always ‘streak’.

  • streak_length (Integer)

    The length of the streak required to complete the achievement.

  • id (String)

    The unique ID of the achievement.

  • name (String)

    The name of this achievement.

  • badge_url (String) (defaults to: OMIT)

    The URL of the badge image for the achievement, if one has been uploaded.

  • key (String) (defaults to: OMIT)

    The key used to reference this achievement in the API.

  • achieved_at (DateTime) (defaults to: OMIT)

    The date and time the achievement was completed, in ISO 8601 format.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/trophy_api_client/types/streak_achievement_response.rb', line 40

def initialize(trigger:, streak_length:, id:, name:, badge_url: OMIT, key: OMIT, achieved_at: OMIT,
               additional_properties: nil)
  @trigger = trigger
  @streak_length = streak_length
  @id = id
  @name = name
  @badge_url = badge_url if badge_url != OMIT
  @key = key if key != OMIT
  @achieved_at = achieved_at if achieved_at != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "trigger": trigger,
    "streakLength": streak_length,
    "id": id,
    "name": name,
    "badgeUrl": badge_url,
    "key": key,
    "achievedAt": achieved_at
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#achieved_atDateTime (readonly)

Returns The date and time the achievement was completed, in ISO 8601 format.

Returns:

  • (DateTime)

    The date and time the achievement was completed, in ISO 8601 format.



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

def achieved_at
  @achieved_at
end

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



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

def additional_properties
  @additional_properties
end

#badge_urlString (readonly)

Returns The URL of the badge image for the achievement, if one has been uploaded.

Returns:

  • (String)

    The URL of the badge image for the achievement, if one has been uploaded.



18
19
20
# File 'lib/trophy_api_client/types/streak_achievement_response.rb', line 18

def badge_url
  @badge_url
end

#idString (readonly)

Returns The unique ID of the achievement.

Returns:

  • (String)

    The unique ID of the achievement.



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

def id
  @id
end

#keyString (readonly)

Returns The key used to reference this achievement in the API.

Returns:

  • (String)

    The key used to reference this achievement in the API.



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

def key
  @key
end

#nameString (readonly)

Returns The name of this achievement.

Returns:

  • (String)

    The name of this achievement.



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

def name
  @name
end

#streak_lengthInteger (readonly)

Returns The length of the streak required to complete the achievement.

Returns:

  • (Integer)

    The length of the streak required to complete the achievement.



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

def streak_length
  @streak_length
end

#triggerString (readonly)

Returns The trigger of the achievement, in this case always ‘streak’.

Returns:

  • (String)

    The trigger of the achievement, in this case always ‘streak’.



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

def trigger
  @trigger
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::StreakAchievementResponse

Deserialize a JSON object to an instance of StreakAchievementResponse

Parameters:

  • json_object (String)

Returns:



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/trophy_api_client/types/streak_achievement_response.rb', line 67

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  trigger = parsed_json["trigger"]
  streak_length = parsed_json["streakLength"]
  id = parsed_json["id"]
  name = parsed_json["name"]
  badge_url = parsed_json["badgeUrl"]
  key = parsed_json["key"]
  achieved_at = (DateTime.parse(parsed_json["achievedAt"]) unless parsed_json["achievedAt"].nil?)
  new(
    trigger: trigger,
    streak_length: streak_length,
    id: id,
    name: name,
    badge_url: badge_url,
    key: key,
    achieved_at: achieved_at,
    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)


102
103
104
105
106
107
108
109
110
# File 'lib/trophy_api_client/types/streak_achievement_response.rb', line 102

def self.validate_raw(obj:)
  obj.trigger.is_a?(String) != false || raise("Passed value for field obj.trigger is not the expected type, validation failed.")
  obj.streak_length.is_a?(Integer) != false || raise("Passed value for field obj.streak_length is not the expected type, validation failed.")
  obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
  obj.badge_url&.is_a?(String) != false || raise("Passed value for field obj.badge_url 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.achieved_at&.is_a?(DateTime) != false || raise("Passed value for field obj.achieved_at is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of StreakAchievementResponse to a JSON object

Returns:

  • (String)


92
93
94
# File 'lib/trophy_api_client/types/streak_achievement_response.rb', line 92

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