Class: TrophyApiClient::LeaderboardEvent

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

Overview

A leaderboard event representing a change in a user’s rank or value.

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timestamp: OMIT, previous_rank: OMIT, rank: OMIT, previous_value: OMIT, value: OMIT, additional_properties: nil) ⇒ TrophyApiClient::LeaderboardEvent



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/trophy_api_client/types/leaderboard_event.rb', line 39

def initialize(timestamp: OMIT, previous_rank: OMIT, rank: OMIT, previous_value: OMIT, value: OMIT,
               additional_properties: nil)
  @timestamp = timestamp if timestamp != OMIT
  @previous_rank = previous_rank if previous_rank != OMIT
  @rank = rank if rank != OMIT
  @previous_value = previous_value if previous_value != OMIT
  @value = value if value != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "timestamp": timestamp,
    "previousRank": previous_rank,
    "rank": rank,
    "previousValue": previous_value,
    "value": value
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)



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

def additional_properties
  @additional_properties
end

#previous_rankInteger (readonly)



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

def previous_rank
  @previous_rank
end

#previous_valueInteger (readonly)



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

def previous_value
  @previous_value
end

#rankInteger (readonly)



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

def rank
  @rank
end

#timestampDateTime (readonly)



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

def timestamp
  @timestamp
end

#valueInteger (readonly)



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

def value
  @value
end

Class Method Details

.from_json(json_object:) ⇒ TrophyApiClient::LeaderboardEvent

Deserialize a JSON object to an instance of LeaderboardEvent



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/trophy_api_client/types/leaderboard_event.rb', line 62

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  timestamp = (DateTime.parse(parsed_json["timestamp"]) unless parsed_json["timestamp"].nil?)
  previous_rank = parsed_json["previousRank"]
  rank = parsed_json["rank"]
  previous_value = parsed_json["previousValue"]
  value = parsed_json["value"]
  new(
    timestamp: timestamp,
    previous_rank: previous_rank,
    rank: rank,
    previous_value: previous_value,
    value: value,
    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.


93
94
95
96
97
98
99
# File 'lib/trophy_api_client/types/leaderboard_event.rb', line 93

def self.validate_raw(obj:)
  obj.timestamp&.is_a?(DateTime) != false || raise("Passed value for field obj.timestamp is not the expected type, validation failed.")
  obj.previous_rank&.is_a?(Integer) != false || raise("Passed value for field obj.previous_rank 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.previous_value&.is_a?(Integer) != false || raise("Passed value for field obj.previous_value is not the expected type, validation failed.")
  obj.value&.is_a?(Integer) != false || raise("Passed value for field obj.value is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of LeaderboardEvent to a JSON object



83
84
85
# File 'lib/trophy_api_client/types/leaderboard_event.rb', line 83

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