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.
@@ -0,0 +1,247 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../requests"
4
+ require_relative "../types/metric_response"
5
+ require "json"
6
+ require_relative "../types/achievement_response"
7
+ require "async"
8
+
9
+ module TrophyApiClient
10
+ class UsersClient
11
+ # @return [TrophyApiClient::RequestClient]
12
+ attr_reader :request_client
13
+
14
+ # @param request_client [TrophyApiClient::RequestClient]
15
+ # @return [TrophyApiClient::UsersClient]
16
+ def initialize(request_client:)
17
+ @request_client = request_client
18
+ end
19
+
20
+ # Get a single user's progress against all active metrics.
21
+ #
22
+ # @param user_id [String] ID of the user
23
+ # @param request_options [TrophyApiClient::RequestOptions]
24
+ # @return [Array<TrophyApiClient::MetricResponse>]
25
+ # @example
26
+ # api = TrophyApiClient::Client.new(
27
+ # base_url: "https://api.example.com",
28
+ # environment: TrophyApiClient::Environment::DEFAULT,
29
+ # api_key: "YOUR_API_KEY"
30
+ # )
31
+ # api.users.allmetrics(user_id: "userId")
32
+ def allmetrics(user_id:, request_options: nil)
33
+ response = @request_client.conn.get do |req|
34
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
35
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
36
+ req.headers = {
37
+ **(req.headers || {}),
38
+ **@request_client.get_headers,
39
+ **(request_options&.additional_headers || {})
40
+ }.compact
41
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
42
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
43
+ end
44
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
45
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
46
+ end
47
+ req.url "#{@request_client.get_url(request_options: request_options)}/users/#{user_id}/metrics"
48
+ end
49
+ parsed_json = JSON.parse(response.body)
50
+ parsed_json&.map do |item|
51
+ item = item.to_json
52
+ TrophyApiClient::MetricResponse.from_json(json_object: item)
53
+ end
54
+ end
55
+
56
+ # Get a user's progress against a single active metric.
57
+ #
58
+ # @param user_id [String] ID of the user.
59
+ # @param key [String] Unique key of the metric.
60
+ # @param request_options [TrophyApiClient::RequestOptions]
61
+ # @return [TrophyApiClient::MetricResponse]
62
+ # @example
63
+ # api = TrophyApiClient::Client.new(
64
+ # base_url: "https://api.example.com",
65
+ # environment: TrophyApiClient::Environment::DEFAULT,
66
+ # api_key: "YOUR_API_KEY"
67
+ # )
68
+ # api.users.singlemetric(user_id: "userId", key: "key")
69
+ def singlemetric(user_id:, key:, request_options: nil)
70
+ response = @request_client.conn.get do |req|
71
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
72
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
73
+ req.headers = {
74
+ **(req.headers || {}),
75
+ **@request_client.get_headers,
76
+ **(request_options&.additional_headers || {})
77
+ }.compact
78
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
79
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
80
+ end
81
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
82
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
83
+ end
84
+ req.url "#{@request_client.get_url(request_options: request_options)}/users/#{user_id}/metrics/#{key}"
85
+ end
86
+ TrophyApiClient::MetricResponse.from_json(json_object: response.body)
87
+ end
88
+
89
+ # Get all of a user's completed achievements.
90
+ #
91
+ # @param user_id [String] ID of the user.
92
+ # @param request_options [TrophyApiClient::RequestOptions]
93
+ # @return [Array<TrophyApiClient::AchievementResponse>]
94
+ # @example
95
+ # api = TrophyApiClient::Client.new(
96
+ # base_url: "https://api.example.com",
97
+ # environment: TrophyApiClient::Environment::DEFAULT,
98
+ # api_key: "YOUR_API_KEY"
99
+ # )
100
+ # api.users.allachievements(user_id: "userId")
101
+ def allachievements(user_id:, request_options: nil)
102
+ response = @request_client.conn.get do |req|
103
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
104
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
105
+ req.headers = {
106
+ **(req.headers || {}),
107
+ **@request_client.get_headers,
108
+ **(request_options&.additional_headers || {})
109
+ }.compact
110
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
111
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
112
+ end
113
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
114
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
115
+ end
116
+ req.url "#{@request_client.get_url(request_options: request_options)}/users/#{user_id}/achievements"
117
+ end
118
+ parsed_json = JSON.parse(response.body)
119
+ parsed_json&.map do |item|
120
+ item = item.to_json
121
+ TrophyApiClient::AchievementResponse.from_json(json_object: item)
122
+ end
123
+ end
124
+ end
125
+
126
+ class AsyncUsersClient
127
+ # @return [TrophyApiClient::AsyncRequestClient]
128
+ attr_reader :request_client
129
+
130
+ # @param request_client [TrophyApiClient::AsyncRequestClient]
131
+ # @return [TrophyApiClient::AsyncUsersClient]
132
+ def initialize(request_client:)
133
+ @request_client = request_client
134
+ end
135
+
136
+ # Get a single user's progress against all active metrics.
137
+ #
138
+ # @param user_id [String] ID of the user
139
+ # @param request_options [TrophyApiClient::RequestOptions]
140
+ # @return [Array<TrophyApiClient::MetricResponse>]
141
+ # @example
142
+ # api = TrophyApiClient::Client.new(
143
+ # base_url: "https://api.example.com",
144
+ # environment: TrophyApiClient::Environment::DEFAULT,
145
+ # api_key: "YOUR_API_KEY"
146
+ # )
147
+ # api.users.allmetrics(user_id: "userId")
148
+ def allmetrics(user_id:, request_options: nil)
149
+ Async do
150
+ response = @request_client.conn.get do |req|
151
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
152
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
153
+ req.headers = {
154
+ **(req.headers || {}),
155
+ **@request_client.get_headers,
156
+ **(request_options&.additional_headers || {})
157
+ }.compact
158
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
159
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
160
+ end
161
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
162
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
163
+ end
164
+ req.url "#{@request_client.get_url(request_options: request_options)}/users/#{user_id}/metrics"
165
+ end
166
+ parsed_json = JSON.parse(response.body)
167
+ parsed_json&.map do |item|
168
+ item = item.to_json
169
+ TrophyApiClient::MetricResponse.from_json(json_object: item)
170
+ end
171
+ end
172
+ end
173
+
174
+ # Get a user's progress against a single active metric.
175
+ #
176
+ # @param user_id [String] ID of the user.
177
+ # @param key [String] Unique key of the metric.
178
+ # @param request_options [TrophyApiClient::RequestOptions]
179
+ # @return [TrophyApiClient::MetricResponse]
180
+ # @example
181
+ # api = TrophyApiClient::Client.new(
182
+ # base_url: "https://api.example.com",
183
+ # environment: TrophyApiClient::Environment::DEFAULT,
184
+ # api_key: "YOUR_API_KEY"
185
+ # )
186
+ # api.users.singlemetric(user_id: "userId", key: "key")
187
+ def singlemetric(user_id:, key:, request_options: nil)
188
+ Async do
189
+ response = @request_client.conn.get do |req|
190
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
191
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
192
+ req.headers = {
193
+ **(req.headers || {}),
194
+ **@request_client.get_headers,
195
+ **(request_options&.additional_headers || {})
196
+ }.compact
197
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
198
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
199
+ end
200
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
201
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
202
+ end
203
+ req.url "#{@request_client.get_url(request_options: request_options)}/users/#{user_id}/metrics/#{key}"
204
+ end
205
+ TrophyApiClient::MetricResponse.from_json(json_object: response.body)
206
+ end
207
+ end
208
+
209
+ # Get all of a user's completed achievements.
210
+ #
211
+ # @param user_id [String] ID of the user.
212
+ # @param request_options [TrophyApiClient::RequestOptions]
213
+ # @return [Array<TrophyApiClient::AchievementResponse>]
214
+ # @example
215
+ # api = TrophyApiClient::Client.new(
216
+ # base_url: "https://api.example.com",
217
+ # environment: TrophyApiClient::Environment::DEFAULT,
218
+ # api_key: "YOUR_API_KEY"
219
+ # )
220
+ # api.users.allachievements(user_id: "userId")
221
+ def allachievements(user_id:, request_options: nil)
222
+ Async do
223
+ response = @request_client.conn.get do |req|
224
+ req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
225
+ req.headers["X-API-KEY"] = request_options.api_key unless request_options&.api_key.nil?
226
+ req.headers = {
227
+ **(req.headers || {}),
228
+ **@request_client.get_headers,
229
+ **(request_options&.additional_headers || {})
230
+ }.compact
231
+ unless request_options.nil? || request_options&.additional_query_parameters.nil?
232
+ req.params = { **(request_options&.additional_query_parameters || {}) }.compact
233
+ end
234
+ unless request_options.nil? || request_options&.additional_body_parameters.nil?
235
+ req.body = { **(request_options&.additional_body_parameters || {}) }.compact
236
+ end
237
+ req.url "#{@request_client.get_url(request_options: request_options)}/users/#{user_id}/achievements"
238
+ end
239
+ parsed_json = JSON.parse(response.body)
240
+ parsed_json&.map do |item|
241
+ item = item.to_json
242
+ TrophyApiClient::AchievementResponse.from_json(json_object: item)
243
+ end
244
+ end
245
+ end
246
+ end
247
+ end
@@ -0,0 +1,3 @@
1
+ module MyGem
2
+ VERSION = "0.1.9"
3
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "environment"
4
+ require_relative "types_export"
5
+ require_relative "requests"
6
+ require_relative "trophy_api_client/achievements/client"
7
+ require_relative "trophy_api_client/metrics/client"
8
+ require_relative "trophy_api_client/users/client"
9
+
10
+ module TrophyApiClient
11
+ class Client
12
+ # @return [TrophyApiClient::AchievementsClient]
13
+ attr_reader :achievements
14
+ # @return [TrophyApiClient::MetricsClient]
15
+ attr_reader :metrics
16
+ # @return [TrophyApiClient::UsersClient]
17
+ attr_reader :users
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::Client]
25
+ def initialize(api_key:, base_url: nil, environment: TrophyApiClient::Environment::DEFAULT, max_retries: nil,
26
+ timeout_in_seconds: nil)
27
+ @request_client = TrophyApiClient::RequestClient.new(
28
+ base_url: base_url,
29
+ environment: environment,
30
+ max_retries: max_retries,
31
+ timeout_in_seconds: timeout_in_seconds,
32
+ api_key: api_key
33
+ )
34
+ @achievements = TrophyApiClient::AchievementsClient.new(request_client: @request_client)
35
+ @metrics = TrophyApiClient::MetricsClient.new(request_client: @request_client)
36
+ @users = TrophyApiClient::UsersClient.new(request_client: @request_client)
37
+ end
38
+ end
39
+
40
+ class AsyncClient
41
+ # @return [TrophyApiClient::AsyncAchievementsClient]
42
+ attr_reader :achievements
43
+ # @return [TrophyApiClient::AsyncMetricsClient]
44
+ attr_reader :metrics
45
+ # @return [TrophyApiClient::AsyncUsersClient]
46
+ attr_reader :users
47
+
48
+ # @param base_url [String]
49
+ # @param environment [TrophyApiClient::Environment]
50
+ # @param max_retries [Long] The number of times to retry a failed request, defaults to 2.
51
+ # @param timeout_in_seconds [Long]
52
+ # @param api_key [String]
53
+ # @return [TrophyApiClient::AsyncClient]
54
+ def initialize(api_key:, base_url: nil, environment: TrophyApiClient::Environment::DEFAULT, max_retries: nil,
55
+ timeout_in_seconds: nil)
56
+ @async_request_client = TrophyApiClient::AsyncRequestClient.new(
57
+ base_url: base_url,
58
+ environment: environment,
59
+ max_retries: max_retries,
60
+ timeout_in_seconds: timeout_in_seconds,
61
+ api_key: api_key
62
+ )
63
+ @achievements = TrophyApiClient::AsyncAchievementsClient.new(request_client: @async_request_client)
64
+ @metrics = TrophyApiClient::AsyncMetricsClient.new(request_client: @async_request_client)
65
+ @users = TrophyApiClient::AsyncUsersClient.new(request_client: @async_request_client)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "trophy_api_client/types/metric_status"
4
+ require_relative "trophy_api_client/types/streak_frequency"
5
+ require_relative "trophy_api_client/types/streak_response"
6
+ require_relative "trophy_api_client/types/achievement_response"
7
+ require_relative "trophy_api_client/types/metric_response"
8
+ require_relative "trophy_api_client/types/event_request_user"
9
+ require_relative "trophy_api_client/types/error_body"
10
+ require_relative "trophy_api_client/types/achievement_completion_response"
11
+ require_relative "trophy_api_client/types/event_response_metrics_item"
12
+ require_relative "trophy_api_client/types/event_response"
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trophy_api_client
3
+ version: !ruby/object:Gem::Version
4
+ version: '0'
5
+ platform: ruby
6
+ authors:
7
+ - ''
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-02-09 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: async-http-faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0.0'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0.0'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '1.0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: faraday
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '1.10'
39
+ - - "<"
40
+ - !ruby/object:Gem::Version
41
+ version: '3.0'
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '1.10'
49
+ - - "<"
50
+ - !ruby/object:Gem::Version
51
+ version: '3.0'
52
+ - !ruby/object:Gem::Dependency
53
+ name: faraday-net_http
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '1.0'
59
+ - - "<"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - - "<"
70
+ - !ruby/object:Gem::Version
71
+ version: '4.0'
72
+ - !ruby/object:Gem::Dependency
73
+ name: faraday-retry
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '1.0'
79
+ - - "<"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '1.0'
89
+ - - "<"
90
+ - !ruby/object:Gem::Version
91
+ version: '3.0'
92
+ description: ''
93
+ email: ''
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - lib/environment.rb
99
+ - lib/gemconfig.rb
100
+ - lib/requests.rb
101
+ - lib/trophy_api_client.rb
102
+ - lib/trophy_api_client/achievements/client.rb
103
+ - lib/trophy_api_client/metrics/client.rb
104
+ - lib/trophy_api_client/types/achievement_completion_response.rb
105
+ - lib/trophy_api_client/types/achievement_response.rb
106
+ - lib/trophy_api_client/types/error_body.rb
107
+ - lib/trophy_api_client/types/event_request_user.rb
108
+ - lib/trophy_api_client/types/event_response.rb
109
+ - lib/trophy_api_client/types/event_response_metrics_item.rb
110
+ - lib/trophy_api_client/types/metric_response.rb
111
+ - lib/trophy_api_client/types/metric_status.rb
112
+ - lib/trophy_api_client/types/streak_frequency.rb
113
+ - lib/trophy_api_client/types/streak_response.rb
114
+ - lib/trophy_api_client/users/client.rb
115
+ - lib/trophy_api_client/version.rb
116
+ - lib/types_export.rb
117
+ homepage: https://github.com/REPO/URL
118
+ licenses: []
119
+ metadata:
120
+ homepage_uri: https://github.com/REPO/URL
121
+ source_code_uri: https://github.com/REPO/URL
122
+ changelog_uri: https://github.com/REPO/URL/blob/master/CHANGELOG.md
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 2.7.0
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubygems_version: 3.6.2
138
+ specification_version: 4
139
+ summary: ''
140
+ test_files: []