Class: TrophyApiClient::AchievementResponse
- Inherits:
-
Object
- Object
- TrophyApiClient::AchievementResponse
- Defined in:
- lib/trophy_api_client/types/achievement_response.rb
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#achieved_at ⇒ DateTime
readonly
The date and time the achievement was completed, in ISO 8601 format.
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#badge_url ⇒ String
readonly
The URL of the badge image for the achievement, if one has been uploaded.
-
#id ⇒ String
readonly
The unique ID of the achievement.
-
#key ⇒ String
readonly
The key used to reference this achievement in the API (only applicable if trigger = ‘api’).
-
#metric_id ⇒ String
readonly
The ID of the metric associated with this achievement (only applicable if trigger = ‘metric’).
-
#metric_name ⇒ String
readonly
The name of the metric associated with this achievement (only applicable if trigger = ‘metric’).
-
#metric_value ⇒ Float
readonly
The value of the metric required to complete the achievement (only applicable if trigger = ‘metric’).
-
#name ⇒ String
readonly
The name of this achievement.
-
#streak_length ⇒ Integer
readonly
The length of the streak required to complete the achievement (only applicable if trigger = ‘streak’).
-
#trigger ⇒ String
readonly
The trigger of the achievement, either ‘metric’, ‘streak’, or ‘api’.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ TrophyApiClient::AchievementResponse
Deserialize a JSON object to an instance of AchievementResponse.
-
.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(id:, name:, trigger:, badge_url: OMIT, achieved_at: OMIT, key: OMIT, streak_length: OMIT, metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, additional_properties: nil) ⇒ TrophyApiClient::AchievementResponse constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of AchievementResponse to a JSON object.
Constructor Details
#initialize(id:, name:, trigger:, badge_url: OMIT, achieved_at: OMIT, key: OMIT, streak_length: OMIT, metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, additional_properties: nil) ⇒ TrophyApiClient::AchievementResponse
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 59 def initialize(id:, name:, trigger:, badge_url: OMIT, achieved_at: OMIT, key: OMIT, streak_length: OMIT, metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, additional_properties: nil) @id = id @name = name @trigger = trigger @badge_url = badge_url if badge_url != OMIT @achieved_at = achieved_at if achieved_at != OMIT @key = key if key != OMIT @streak_length = streak_length if streak_length != OMIT @metric_id = metric_id if metric_id != OMIT @metric_value = metric_value if metric_value != OMIT @metric_name = metric_name if metric_name != OMIT @additional_properties = additional_properties @_field_set = { "id": id, "name": name, "trigger": trigger, "badgeUrl": badge_url, "achievedAt": achieved_at, "key": key, "streakLength": streak_length, "metricId": metric_id, "metricValue": metric_value, "metricName": metric_name }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#achieved_at ⇒ DateTime (readonly)
Returns The date and time the achievement was completed, in ISO 8601 format.
18 19 20 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 18 def achieved_at @achieved_at end |
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
35 36 37 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 35 def additional_properties @additional_properties end |
#badge_url ⇒ String (readonly)
Returns The URL of the badge image for the achievement, if one has been uploaded.
16 17 18 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 16 def badge_url @badge_url end |
#id ⇒ String (readonly)
Returns The unique ID of the achievement.
10 11 12 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 10 def id @id end |
#key ⇒ String (readonly)
Returns The key used to reference this achievement in the API (only applicable if trigger = ‘api’).
21 22 23 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 21 def key @key end |
#metric_id ⇒ String (readonly)
Returns The ID of the metric associated with this achievement (only applicable if trigger = ‘metric’).
27 28 29 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 27 def metric_id @metric_id end |
#metric_name ⇒ String (readonly)
Returns The name of the metric associated with this achievement (only applicable if trigger = ‘metric’).
33 34 35 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 33 def metric_name @metric_name end |
#metric_value ⇒ Float (readonly)
Returns The value of the metric required to complete the achievement (only applicable if trigger = ‘metric’).
30 31 32 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 30 def metric_value @metric_value end |
#name ⇒ String (readonly)
Returns The name of this achievement.
12 13 14 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 12 def name @name end |
#streak_length ⇒ Integer (readonly)
Returns The length of the streak required to complete the achievement (only applicable if trigger = ‘streak’).
24 25 26 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 24 def streak_length @streak_length end |
#trigger ⇒ String (readonly)
Returns The trigger of the achievement, either ‘metric’, ‘streak’, or ‘api’.
14 15 16 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 14 def trigger @trigger end |
Class Method Details
.from_json(json_object:) ⇒ TrophyApiClient::AchievementResponse
Deserialize a JSON object to an instance of AchievementResponse
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 92 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) id = parsed_json["id"] name = parsed_json["name"] trigger = parsed_json["trigger"] badge_url = parsed_json["badgeUrl"] achieved_at = (DateTime.parse(parsed_json["achievedAt"]) unless parsed_json["achievedAt"].nil?) key = parsed_json["key"] streak_length = parsed_json["streakLength"] metric_id = parsed_json["metricId"] metric_value = parsed_json["metricValue"] metric_name = parsed_json["metricName"] new( id: id, name: name, trigger: trigger, badge_url: badge_url, achieved_at: achieved_at, key: key, streak_length: streak_length, metric_id: metric_id, metric_value: metric_value, metric_name: metric_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.
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 133 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.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.") obj.trigger.is_a?(String) != false || raise("Passed value for field obj.trigger 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.achieved_at&.is_a?(DateTime) != false || raise("Passed value for field obj.achieved_at 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.streak_length&.is_a?(Integer) != false || raise("Passed value for field obj.streak_length is not the expected type, validation failed.") obj.metric_id&.is_a?(String) != false || raise("Passed value for field obj.metric_id is not the expected type, validation failed.") obj.metric_value&.is_a?(Float) != false || raise("Passed value for field obj.metric_value 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.") end |
Instance Method Details
#to_json(*_args) ⇒ String
Serialize an instance of AchievementResponse to a JSON object
123 124 125 |
# File 'lib/trophy_api_client/types/achievement_response.rb', line 123 def to_json(*_args) @_field_set&.to_json end |