trophy_api_client 0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/environment.rb +7 -0
- data/lib/gemconfig.rb +14 -0
- data/lib/requests.rb +163 -0
- data/lib/trophy_api_client/achievements/client.rb +102 -0
- data/lib/trophy_api_client/metrics/client.rb +112 -0
- data/lib/trophy_api_client/types/achievement_completion_response.rb +71 -0
- data/lib/trophy_api_client/types/achievement_response.rb +122 -0
- data/lib/trophy_api_client/types/error_body.rb +55 -0
- data/lib/trophy_api_client/types/event_request_user.rb +82 -0
- data/lib/trophy_api_client/types/event_response.rb +90 -0
- data/lib/trophy_api_client/types/event_response_metrics_item.rb +73 -0
- data/lib/trophy_api_client/types/metric_response.rb +139 -0
- data/lib/trophy_api_client/types/metric_status.rb +9 -0
- data/lib/trophy_api_client/types/streak_frequency.rb +10 -0
- data/lib/trophy_api_client/types/streak_response.rb +66 -0
- data/lib/trophy_api_client/users/client.rb +247 -0
- data/lib/trophy_api_client/version.rb +3 -0
- data/lib/trophy_api_client.rb +68 -0
- data/lib/types_export.rb +12 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '0149173e6a70fddabed85fea62764af9c90d07a0b0144a83a3ad83db1daae650'
|
4
|
+
data.tar.gz: 3757f76091036303ec8a5dae7461e966e790d1c224dab0ed46e013a0620d30a8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5eb33c6cc42390b5ca8a795c2ca76dccf4e28835be36809d5097e3b0b2a175d1e54fdb00708b715656007c60155f572e3d5910b6a74d845c8fce017681fc8e77
|
7
|
+
data.tar.gz: 62a486aeff9d35fabec254359d6abef0b4da11a53ba4c91d5a257b079acd589cea899227bbc4aa8b493b09f918672f8cace09522be77deb94ef08ab4e1abe847
|
data/lib/environment.rb
ADDED
data/lib/gemconfig.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TrophyApiClient
|
4
|
+
module Gemconfig
|
5
|
+
VERSION = ""
|
6
|
+
AUTHORS = [""].freeze
|
7
|
+
EMAIL = ""
|
8
|
+
SUMMARY = ""
|
9
|
+
DESCRIPTION = ""
|
10
|
+
HOMEPAGE = "https://github.com/REPO/URL"
|
11
|
+
SOURCE_CODE_URI = "https://github.com/REPO/URL"
|
12
|
+
CHANGELOG_URI = "https://github.com/REPO/URL/blob/master/CHANGELOG.md"
|
13
|
+
end
|
14
|
+
end
|
data/lib/requests.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "environment"
|
4
|
+
require "faraday"
|
5
|
+
require "faraday/retry"
|
6
|
+
require "async/http/faraday"
|
7
|
+
|
8
|
+
module TrophyApiClient
|
9
|
+
class RequestClient
|
10
|
+
# @return [Faraday]
|
11
|
+
attr_reader :conn
|
12
|
+
# @return [String]
|
13
|
+
attr_reader :base_url
|
14
|
+
# @return [String]
|
15
|
+
attr_reader :api_key
|
16
|
+
# @return [String]
|
17
|
+
attr_reader :default_environment
|
18
|
+
|
19
|
+
# @param base_url [String]
|
20
|
+
# @param environment [TrophyApiClient::Environment]
|
21
|
+
# @param max_retries [Long] The number of times to retry a failed request, defaults to 2.
|
22
|
+
# @param timeout_in_seconds [Long]
|
23
|
+
# @param api_key [String]
|
24
|
+
# @return [TrophyApiClient::RequestClient]
|
25
|
+
def initialize(api_key:, base_url: nil, environment: TrophyApiClient::Environment::DEFAULT, max_retries: nil,
|
26
|
+
timeout_in_seconds: nil)
|
27
|
+
@default_environment = environment
|
28
|
+
@base_url = environment || base_url
|
29
|
+
@api_key = api_key
|
30
|
+
@conn = Faraday.new do |faraday|
|
31
|
+
faraday.request :json
|
32
|
+
faraday.response :raise_error, include_request: true
|
33
|
+
faraday.request :retry, { max: max_retries } unless max_retries.nil?
|
34
|
+
faraday.options.timeout = timeout_in_seconds unless timeout_in_seconds.nil?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
39
|
+
# @return [String]
|
40
|
+
def get_url(request_options: nil)
|
41
|
+
request_options&.base_url || @default_environment || @base_url
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Hash{String => String}]
|
45
|
+
def get_headers
|
46
|
+
headers = { "X-Fern-Language": "Ruby", "X-Fern-SDK-Name": "trophy_api_client" }
|
47
|
+
headers["X-API-KEY"] = ((@api_key.is_a? Method) ? @api_key.call : @api_key) unless @api_key.nil?
|
48
|
+
headers
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class AsyncRequestClient
|
53
|
+
# @return [Faraday]
|
54
|
+
attr_reader :conn
|
55
|
+
# @return [String]
|
56
|
+
attr_reader :base_url
|
57
|
+
# @return [String]
|
58
|
+
attr_reader :api_key
|
59
|
+
# @return [String]
|
60
|
+
attr_reader :default_environment
|
61
|
+
|
62
|
+
# @param base_url [String]
|
63
|
+
# @param environment [TrophyApiClient::Environment]
|
64
|
+
# @param max_retries [Long] The number of times to retry a failed request, defaults to 2.
|
65
|
+
# @param timeout_in_seconds [Long]
|
66
|
+
# @param api_key [String]
|
67
|
+
# @return [TrophyApiClient::AsyncRequestClient]
|
68
|
+
def initialize(api_key:, base_url: nil, environment: TrophyApiClient::Environment::DEFAULT, max_retries: nil,
|
69
|
+
timeout_in_seconds: nil)
|
70
|
+
@default_environment = environment
|
71
|
+
@base_url = environment || base_url
|
72
|
+
@api_key = api_key
|
73
|
+
@conn = Faraday.new do |faraday|
|
74
|
+
faraday.request :json
|
75
|
+
faraday.response :raise_error, include_request: true
|
76
|
+
faraday.adapter :async_http
|
77
|
+
faraday.request :retry, { max: max_retries } unless max_retries.nil?
|
78
|
+
faraday.options.timeout = timeout_in_seconds unless timeout_in_seconds.nil?
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
83
|
+
# @return [String]
|
84
|
+
def get_url(request_options: nil)
|
85
|
+
request_options&.base_url || @default_environment || @base_url
|
86
|
+
end
|
87
|
+
|
88
|
+
# @return [Hash{String => String}]
|
89
|
+
def get_headers
|
90
|
+
headers = { "X-Fern-Language": "Ruby", "X-Fern-SDK-Name": "trophy_api_client" }
|
91
|
+
headers["X-API-KEY"] = ((@api_key.is_a? Method) ? @api_key.call : @api_key) unless @api_key.nil?
|
92
|
+
headers
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Additional options for request-specific configuration when calling APIs via the
|
97
|
+
# SDK.
|
98
|
+
class RequestOptions
|
99
|
+
# @return [String]
|
100
|
+
attr_reader :base_url
|
101
|
+
# @return [String]
|
102
|
+
attr_reader :api_key
|
103
|
+
# @return [Hash{String => Object}]
|
104
|
+
attr_reader :additional_headers
|
105
|
+
# @return [Hash{String => Object}]
|
106
|
+
attr_reader :additional_query_parameters
|
107
|
+
# @return [Hash{String => Object}]
|
108
|
+
attr_reader :additional_body_parameters
|
109
|
+
# @return [Long]
|
110
|
+
attr_reader :timeout_in_seconds
|
111
|
+
|
112
|
+
# @param base_url [String]
|
113
|
+
# @param api_key [String]
|
114
|
+
# @param additional_headers [Hash{String => Object}]
|
115
|
+
# @param additional_query_parameters [Hash{String => Object}]
|
116
|
+
# @param additional_body_parameters [Hash{String => Object}]
|
117
|
+
# @param timeout_in_seconds [Long]
|
118
|
+
# @return [TrophyApiClient::RequestOptions]
|
119
|
+
def initialize(base_url: nil, api_key: nil, additional_headers: nil, additional_query_parameters: nil,
|
120
|
+
additional_body_parameters: nil, timeout_in_seconds: nil)
|
121
|
+
@base_url = base_url
|
122
|
+
@api_key = api_key
|
123
|
+
@additional_headers = additional_headers
|
124
|
+
@additional_query_parameters = additional_query_parameters
|
125
|
+
@additional_body_parameters = additional_body_parameters
|
126
|
+
@timeout_in_seconds = timeout_in_seconds
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Additional options for request-specific configuration when calling APIs via the
|
131
|
+
# SDK.
|
132
|
+
class IdempotencyRequestOptions
|
133
|
+
# @return [String]
|
134
|
+
attr_reader :base_url
|
135
|
+
# @return [String]
|
136
|
+
attr_reader :api_key
|
137
|
+
# @return [Hash{String => Object}]
|
138
|
+
attr_reader :additional_headers
|
139
|
+
# @return [Hash{String => Object}]
|
140
|
+
attr_reader :additional_query_parameters
|
141
|
+
# @return [Hash{String => Object}]
|
142
|
+
attr_reader :additional_body_parameters
|
143
|
+
# @return [Long]
|
144
|
+
attr_reader :timeout_in_seconds
|
145
|
+
|
146
|
+
# @param base_url [String]
|
147
|
+
# @param api_key [String]
|
148
|
+
# @param additional_headers [Hash{String => Object}]
|
149
|
+
# @param additional_query_parameters [Hash{String => Object}]
|
150
|
+
# @param additional_body_parameters [Hash{String => Object}]
|
151
|
+
# @param timeout_in_seconds [Long]
|
152
|
+
# @return [TrophyApiClient::IdempotencyRequestOptions]
|
153
|
+
def initialize(base_url: nil, api_key: nil, additional_headers: nil, additional_query_parameters: nil,
|
154
|
+
additional_body_parameters: nil, timeout_in_seconds: nil)
|
155
|
+
@base_url = base_url
|
156
|
+
@api_key = api_key
|
157
|
+
@additional_headers = additional_headers
|
158
|
+
@additional_query_parameters = additional_query_parameters
|
159
|
+
@additional_body_parameters = additional_body_parameters
|
160
|
+
@timeout_in_seconds = timeout_in_seconds
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../requests"
|
4
|
+
require_relative "../types/event_request_user"
|
5
|
+
require_relative "../types/achievement_completion_response"
|
6
|
+
require "async"
|
7
|
+
|
8
|
+
module TrophyApiClient
|
9
|
+
class AchievementsClient
|
10
|
+
# @return [TrophyApiClient::RequestClient]
|
11
|
+
attr_reader :request_client
|
12
|
+
|
13
|
+
# @param request_client [TrophyApiClient::RequestClient]
|
14
|
+
# @return [TrophyApiClient::AchievementsClient]
|
15
|
+
def initialize(request_client:)
|
16
|
+
@request_client = request_client
|
17
|
+
end
|
18
|
+
|
19
|
+
# Mark an achievement as completed for a user.
|
20
|
+
#
|
21
|
+
# @param key [String] Unique reference of the achievement as set when created.
|
22
|
+
# @param user [Hash] The user that completed the achievement.Request of type TrophyApiClient::EventRequestUser, as a Hash
|
23
|
+
# * :id (String)
|
24
|
+
# * :email (String)
|
25
|
+
# * :name (String)
|
26
|
+
# * :tz (String)
|
27
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
28
|
+
# @return [TrophyApiClient::AchievementCompletionResponse]
|
29
|
+
# @example
|
30
|
+
# api = TrophyApiClient::Client.new(
|
31
|
+
# base_url: "https://api.example.com",
|
32
|
+
# environment: TrophyApiClient::Environment::DEFAULT,
|
33
|
+
# api_key: "YOUR_API_KEY"
|
34
|
+
# )
|
35
|
+
# api.achievements.complete(key: "finish-onboarding", user: { id: "18", email: "jk.rowling@harrypotter.com", tz: "Europe/London" })
|
36
|
+
def complete(key:, user:, request_options: nil)
|
37
|
+
response = @request_client.conn.post do |req|
|
38
|
+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
39
|
+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
40
|
+
req.headers = {
|
41
|
+
**(req.headers || {}),
|
42
|
+
**@request_client.get_headers,
|
43
|
+
**(request_options&.additional_headers || {})
|
44
|
+
}.compact
|
45
|
+
unless request_options.nil? || request_options&.additional_query_parameters.nil?
|
46
|
+
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
|
47
|
+
end
|
48
|
+
req.body = { **(request_options&.additional_body_parameters || {}), user: user }.compact
|
49
|
+
req.url "#{@request_client.get_url(request_options: request_options)}/achievements/#{key}/complete"
|
50
|
+
end
|
51
|
+
TrophyApiClient::AchievementCompletionResponse.from_json(json_object: response.body)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class AsyncAchievementsClient
|
56
|
+
# @return [TrophyApiClient::AsyncRequestClient]
|
57
|
+
attr_reader :request_client
|
58
|
+
|
59
|
+
# @param request_client [TrophyApiClient::AsyncRequestClient]
|
60
|
+
# @return [TrophyApiClient::AsyncAchievementsClient]
|
61
|
+
def initialize(request_client:)
|
62
|
+
@request_client = request_client
|
63
|
+
end
|
64
|
+
|
65
|
+
# Mark an achievement as completed for a user.
|
66
|
+
#
|
67
|
+
# @param key [String] Unique reference of the achievement as set when created.
|
68
|
+
# @param user [Hash] The user that completed the achievement.Request of type TrophyApiClient::EventRequestUser, as a Hash
|
69
|
+
# * :id (String)
|
70
|
+
# * :email (String)
|
71
|
+
# * :name (String)
|
72
|
+
# * :tz (String)
|
73
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
74
|
+
# @return [TrophyApiClient::AchievementCompletionResponse]
|
75
|
+
# @example
|
76
|
+
# api = TrophyApiClient::Client.new(
|
77
|
+
# base_url: "https://api.example.com",
|
78
|
+
# environment: TrophyApiClient::Environment::DEFAULT,
|
79
|
+
# api_key: "YOUR_API_KEY"
|
80
|
+
# )
|
81
|
+
# api.achievements.complete(key: "finish-onboarding", user: { id: "18", email: "jk.rowling@harrypotter.com", tz: "Europe/London" })
|
82
|
+
def complete(key:, user:, request_options: nil)
|
83
|
+
Async do
|
84
|
+
response = @request_client.conn.post do |req|
|
85
|
+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
86
|
+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
87
|
+
req.headers = {
|
88
|
+
**(req.headers || {}),
|
89
|
+
**@request_client.get_headers,
|
90
|
+
**(request_options&.additional_headers || {})
|
91
|
+
}.compact
|
92
|
+
unless request_options.nil? || request_options&.additional_query_parameters.nil?
|
93
|
+
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
|
94
|
+
end
|
95
|
+
req.body = { **(request_options&.additional_body_parameters || {}), user: user }.compact
|
96
|
+
req.url "#{@request_client.get_url(request_options: request_options)}/achievements/#{key}/complete"
|
97
|
+
end
|
98
|
+
TrophyApiClient::AchievementCompletionResponse.from_json(json_object: response.body)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../requests"
|
4
|
+
require_relative "../types/event_request_user"
|
5
|
+
require_relative "../types/event_response"
|
6
|
+
require "async"
|
7
|
+
|
8
|
+
module TrophyApiClient
|
9
|
+
class MetricsClient
|
10
|
+
# @return [TrophyApiClient::RequestClient]
|
11
|
+
attr_reader :request_client
|
12
|
+
|
13
|
+
# @param request_client [TrophyApiClient::RequestClient]
|
14
|
+
# @return [TrophyApiClient::MetricsClient]
|
15
|
+
def initialize(request_client:)
|
16
|
+
@request_client = request_client
|
17
|
+
end
|
18
|
+
|
19
|
+
# Increment or decrement the value of a metric for a user.
|
20
|
+
#
|
21
|
+
# @param key [String] Unique reference of the metric as set when created.
|
22
|
+
# @param user [Hash] The user that triggered the event.Request of type TrophyApiClient::EventRequestUser, as a Hash
|
23
|
+
# * :id (String)
|
24
|
+
# * :email (String)
|
25
|
+
# * :name (String)
|
26
|
+
# * :tz (String)
|
27
|
+
# @param value [Float] The value to add to the user's current total for the given metric.
|
28
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
29
|
+
# @return [TrophyApiClient::EventResponse]
|
30
|
+
# @example
|
31
|
+
# api = TrophyApiClient::Client.new(
|
32
|
+
# base_url: "https://api.example.com",
|
33
|
+
# environment: TrophyApiClient::Environment::DEFAULT,
|
34
|
+
# api_key: "YOUR_API_KEY"
|
35
|
+
# )
|
36
|
+
# api.metrics.event(
|
37
|
+
# key: "words-written",
|
38
|
+
# user: { id: "18", email: "jk.rowling@harrypotter.com", tz: "Europe/London" },
|
39
|
+
# value: 750
|
40
|
+
# )
|
41
|
+
def event(key:, user:, value:, request_options: nil)
|
42
|
+
response = @request_client.conn.post do |req|
|
43
|
+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
44
|
+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
45
|
+
req.headers = {
|
46
|
+
**(req.headers || {}),
|
47
|
+
**@request_client.get_headers,
|
48
|
+
**(request_options&.additional_headers || {})
|
49
|
+
}.compact
|
50
|
+
unless request_options.nil? || request_options&.additional_query_parameters.nil?
|
51
|
+
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
|
52
|
+
end
|
53
|
+
req.body = { **(request_options&.additional_body_parameters || {}), user: user, value: value }.compact
|
54
|
+
req.url "#{@request_client.get_url(request_options: request_options)}/metrics/#{key}/event"
|
55
|
+
end
|
56
|
+
TrophyApiClient::EventResponse.from_json(json_object: response.body)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class AsyncMetricsClient
|
61
|
+
# @return [TrophyApiClient::AsyncRequestClient]
|
62
|
+
attr_reader :request_client
|
63
|
+
|
64
|
+
# @param request_client [TrophyApiClient::AsyncRequestClient]
|
65
|
+
# @return [TrophyApiClient::AsyncMetricsClient]
|
66
|
+
def initialize(request_client:)
|
67
|
+
@request_client = request_client
|
68
|
+
end
|
69
|
+
|
70
|
+
# Increment or decrement the value of a metric for a user.
|
71
|
+
#
|
72
|
+
# @param key [String] Unique reference of the metric as set when created.
|
73
|
+
# @param user [Hash] The user that triggered the event.Request of type TrophyApiClient::EventRequestUser, as a Hash
|
74
|
+
# * :id (String)
|
75
|
+
# * :email (String)
|
76
|
+
# * :name (String)
|
77
|
+
# * :tz (String)
|
78
|
+
# @param value [Float] The value to add to the user's current total for the given metric.
|
79
|
+
# @param request_options [TrophyApiClient::RequestOptions]
|
80
|
+
# @return [TrophyApiClient::EventResponse]
|
81
|
+
# @example
|
82
|
+
# api = TrophyApiClient::Client.new(
|
83
|
+
# base_url: "https://api.example.com",
|
84
|
+
# environment: TrophyApiClient::Environment::DEFAULT,
|
85
|
+
# api_key: "YOUR_API_KEY"
|
86
|
+
# )
|
87
|
+
# api.metrics.event(
|
88
|
+
# key: "words-written",
|
89
|
+
# user: { id: "18", email: "jk.rowling@harrypotter.com", tz: "Europe/London" },
|
90
|
+
# value: 750
|
91
|
+
# )
|
92
|
+
def event(key:, user:, value:, request_options: nil)
|
93
|
+
Async do
|
94
|
+
response = @request_client.conn.post do |req|
|
95
|
+
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
|
96
|
+
req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
|
97
|
+
req.headers = {
|
98
|
+
**(req.headers || {}),
|
99
|
+
**@request_client.get_headers,
|
100
|
+
**(request_options&.additional_headers || {})
|
101
|
+
}.compact
|
102
|
+
unless request_options.nil? || request_options&.additional_query_parameters.nil?
|
103
|
+
req.params = { **(request_options&.additional_query_parameters || {}) }.compact
|
104
|
+
end
|
105
|
+
req.body = { **(request_options&.additional_body_parameters || {}), user: user, value: value }.compact
|
106
|
+
req.url "#{@request_client.get_url(request_options: request_options)}/metrics/#{key}/event"
|
107
|
+
end
|
108
|
+
TrophyApiClient::EventResponse.from_json(json_object: response.body)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "achievement_response"
|
4
|
+
require "ostruct"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module TrophyApiClient
|
8
|
+
class AchievementCompletionResponse
|
9
|
+
# @return [String] The unique ID of the completion.
|
10
|
+
attr_reader :completion_id
|
11
|
+
# @return [TrophyApiClient::AchievementResponse]
|
12
|
+
attr_reader :achievement
|
13
|
+
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
14
|
+
attr_reader :additional_properties
|
15
|
+
# @return [Object]
|
16
|
+
attr_reader :_field_set
|
17
|
+
protected :_field_set
|
18
|
+
|
19
|
+
OMIT = Object.new
|
20
|
+
|
21
|
+
# @param completion_id [String] The unique ID of the completion.
|
22
|
+
# @param achievement [TrophyApiClient::AchievementResponse]
|
23
|
+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
24
|
+
# @return [TrophyApiClient::AchievementCompletionResponse]
|
25
|
+
def initialize(completion_id:, achievement:, additional_properties: nil)
|
26
|
+
@completion_id = completion_id
|
27
|
+
@achievement = achievement
|
28
|
+
@additional_properties = additional_properties
|
29
|
+
@_field_set = { "completionId": completion_id, "achievement": achievement }
|
30
|
+
end
|
31
|
+
|
32
|
+
# Deserialize a JSON object to an instance of AchievementCompletionResponse
|
33
|
+
#
|
34
|
+
# @param json_object [String]
|
35
|
+
# @return [TrophyApiClient::AchievementCompletionResponse]
|
36
|
+
def self.from_json(json_object:)
|
37
|
+
struct = JSON.parse(json_object, object_class: OpenStruct)
|
38
|
+
parsed_json = JSON.parse(json_object)
|
39
|
+
completion_id = parsed_json["completionId"]
|
40
|
+
if parsed_json["achievement"].nil?
|
41
|
+
achievement = nil
|
42
|
+
else
|
43
|
+
achievement = parsed_json["achievement"].to_json
|
44
|
+
achievement = TrophyApiClient::AchievementResponse.from_json(json_object: achievement)
|
45
|
+
end
|
46
|
+
new(
|
47
|
+
completion_id: completion_id,
|
48
|
+
achievement: achievement,
|
49
|
+
additional_properties: struct
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Serialize an instance of AchievementCompletionResponse to a JSON object
|
54
|
+
#
|
55
|
+
# @return [String]
|
56
|
+
def to_json(*_args)
|
57
|
+
@_field_set&.to_json
|
58
|
+
end
|
59
|
+
|
60
|
+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
|
61
|
+
# hash and check each fields type against the current object's property
|
62
|
+
# definitions.
|
63
|
+
#
|
64
|
+
# @param obj [Object]
|
65
|
+
# @return [Void]
|
66
|
+
def self.validate_raw(obj:)
|
67
|
+
obj.completion_id.is_a?(String) != false || raise("Passed value for field obj.completion_id is not the expected type, validation failed.")
|
68
|
+
TrophyApiClient::AchievementResponse.validate_raw(obj: obj.achievement)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "date"
|
4
|
+
require "ostruct"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module TrophyApiClient
|
8
|
+
class AchievementResponse
|
9
|
+
# @return [String] The unique ID of the achievement.
|
10
|
+
attr_reader :id
|
11
|
+
# @return [String] The name of this achievement.
|
12
|
+
attr_reader :name
|
13
|
+
# @return [String] The URL of the badge image for the achievement, if one has been uploaded.
|
14
|
+
attr_reader :badge_url
|
15
|
+
# @return [String] The ID of the metric associated with this achievement, if any.
|
16
|
+
attr_reader :metric_id
|
17
|
+
# @return [Float] The value of the metric required to complete the achievement, if this
|
18
|
+
# achievement is associated with a metric.
|
19
|
+
attr_reader :metric_value
|
20
|
+
# @return [String] The name of the metric associated with this achievement, if any.
|
21
|
+
attr_reader :metric_name
|
22
|
+
# @return [String] The key used to reference this achievement in the API.
|
23
|
+
attr_reader :key
|
24
|
+
# @return [DateTime] The date and time the achievement was completed, in ISO 8601 format.
|
25
|
+
attr_reader :achieved_at
|
26
|
+
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
27
|
+
attr_reader :additional_properties
|
28
|
+
# @return [Object]
|
29
|
+
attr_reader :_field_set
|
30
|
+
protected :_field_set
|
31
|
+
|
32
|
+
OMIT = Object.new
|
33
|
+
|
34
|
+
# @param id [String] The unique ID of the achievement.
|
35
|
+
# @param name [String] The name of this achievement.
|
36
|
+
# @param badge_url [String] The URL of the badge image for the achievement, if one has been uploaded.
|
37
|
+
# @param metric_id [String] The ID of the metric associated with this achievement, if any.
|
38
|
+
# @param metric_value [Float] The value of the metric required to complete the achievement, if this
|
39
|
+
# achievement is associated with a metric.
|
40
|
+
# @param metric_name [String] The name of the metric associated with this achievement, if any.
|
41
|
+
# @param key [String] The key used to reference this achievement in the API.
|
42
|
+
# @param achieved_at [DateTime] The date and time the achievement was completed, in ISO 8601 format.
|
43
|
+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
44
|
+
# @return [TrophyApiClient::AchievementResponse]
|
45
|
+
def initialize(id:, name: OMIT, badge_url: OMIT, metric_id: OMIT, metric_value: OMIT, metric_name: OMIT, key: OMIT,
|
46
|
+
achieved_at: OMIT, additional_properties: nil)
|
47
|
+
@id = id
|
48
|
+
@name = name if name != OMIT
|
49
|
+
@badge_url = badge_url if badge_url != OMIT
|
50
|
+
@metric_id = metric_id if metric_id != OMIT
|
51
|
+
@metric_value = metric_value if metric_value != OMIT
|
52
|
+
@metric_name = metric_name if metric_name != OMIT
|
53
|
+
@key = key if key != OMIT
|
54
|
+
@achieved_at = achieved_at if achieved_at != OMIT
|
55
|
+
@additional_properties = additional_properties
|
56
|
+
@_field_set = {
|
57
|
+
"id": id,
|
58
|
+
"name": name,
|
59
|
+
"badgeUrl": badge_url,
|
60
|
+
"metricId": metric_id,
|
61
|
+
"metricValue": metric_value,
|
62
|
+
"metricName": metric_name,
|
63
|
+
"key": key,
|
64
|
+
"achievedAt": achieved_at
|
65
|
+
}.reject do |_k, v|
|
66
|
+
v == OMIT
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Deserialize a JSON object to an instance of AchievementResponse
|
71
|
+
#
|
72
|
+
# @param json_object [String]
|
73
|
+
# @return [TrophyApiClient::AchievementResponse]
|
74
|
+
def self.from_json(json_object:)
|
75
|
+
struct = JSON.parse(json_object, object_class: OpenStruct)
|
76
|
+
parsed_json = JSON.parse(json_object)
|
77
|
+
id = parsed_json["id"]
|
78
|
+
name = parsed_json["name"]
|
79
|
+
badge_url = parsed_json["badgeUrl"]
|
80
|
+
metric_id = parsed_json["metricId"]
|
81
|
+
metric_value = parsed_json["metricValue"]
|
82
|
+
metric_name = parsed_json["metricName"]
|
83
|
+
key = parsed_json["key"]
|
84
|
+
achieved_at = (DateTime.parse(parsed_json["achievedAt"]) unless parsed_json["achievedAt"].nil?)
|
85
|
+
new(
|
86
|
+
id: id,
|
87
|
+
name: name,
|
88
|
+
badge_url: badge_url,
|
89
|
+
metric_id: metric_id,
|
90
|
+
metric_value: metric_value,
|
91
|
+
metric_name: metric_name,
|
92
|
+
key: key,
|
93
|
+
achieved_at: achieved_at,
|
94
|
+
additional_properties: struct
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Serialize an instance of AchievementResponse to a JSON object
|
99
|
+
#
|
100
|
+
# @return [String]
|
101
|
+
def to_json(*_args)
|
102
|
+
@_field_set&.to_json
|
103
|
+
end
|
104
|
+
|
105
|
+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
|
106
|
+
# hash and check each fields type against the current object's property
|
107
|
+
# definitions.
|
108
|
+
#
|
109
|
+
# @param obj [Object]
|
110
|
+
# @return [Void]
|
111
|
+
def self.validate_raw(obj:)
|
112
|
+
obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
|
113
|
+
obj.name&.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
|
114
|
+
obj.badge_url&.is_a?(String) != false || raise("Passed value for field obj.badge_url is not the expected type, validation failed.")
|
115
|
+
obj.metric_id&.is_a?(String) != false || raise("Passed value for field obj.metric_id is not the expected type, validation failed.")
|
116
|
+
obj.metric_value&.is_a?(Float) != false || raise("Passed value for field obj.metric_value is not the expected type, validation failed.")
|
117
|
+
obj.metric_name&.is_a?(String) != false || raise("Passed value for field obj.metric_name is not the expected type, validation failed.")
|
118
|
+
obj.key&.is_a?(String) != false || raise("Passed value for field obj.key is not the expected type, validation failed.")
|
119
|
+
obj.achieved_at&.is_a?(DateTime) != false || raise("Passed value for field obj.achieved_at is not the expected type, validation failed.")
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ostruct"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module TrophyApiClient
|
7
|
+
class ErrorBody
|
8
|
+
# @return [String]
|
9
|
+
attr_reader :error
|
10
|
+
# @return [OpenStruct] Additional properties unmapped to the current class definition
|
11
|
+
attr_reader :additional_properties
|
12
|
+
# @return [Object]
|
13
|
+
attr_reader :_field_set
|
14
|
+
protected :_field_set
|
15
|
+
|
16
|
+
OMIT = Object.new
|
17
|
+
|
18
|
+
# @param error [String]
|
19
|
+
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
|
20
|
+
# @return [TrophyApiClient::ErrorBody]
|
21
|
+
def initialize(error:, additional_properties: nil)
|
22
|
+
@error = error
|
23
|
+
@additional_properties = additional_properties
|
24
|
+
@_field_set = { "error": error }
|
25
|
+
end
|
26
|
+
|
27
|
+
# Deserialize a JSON object to an instance of ErrorBody
|
28
|
+
#
|
29
|
+
# @param json_object [String]
|
30
|
+
# @return [TrophyApiClient::ErrorBody]
|
31
|
+
def self.from_json(json_object:)
|
32
|
+
struct = JSON.parse(json_object, object_class: OpenStruct)
|
33
|
+
parsed_json = JSON.parse(json_object)
|
34
|
+
error = parsed_json["error"]
|
35
|
+
new(error: error, additional_properties: struct)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Serialize an instance of ErrorBody to a JSON object
|
39
|
+
#
|
40
|
+
# @return [String]
|
41
|
+
def to_json(*_args)
|
42
|
+
@_field_set&.to_json
|
43
|
+
end
|
44
|
+
|
45
|
+
# Leveraged for Union-type generation, validate_raw attempts to parse the given
|
46
|
+
# hash and check each fields type against the current object's property
|
47
|
+
# definitions.
|
48
|
+
#
|
49
|
+
# @param obj [Object]
|
50
|
+
# @return [Void]
|
51
|
+
def self.validate_raw(obj:)
|
52
|
+
obj.error.is_a?(String) != false || raise("Passed value for field obj.error is not the expected type, validation failed.")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|