Skip to content

Commit aa5cb7f

Browse files
Automatically update Ruby SDK
1 parent 62e1de4 commit aa5cb7f

10 files changed

Lines changed: 171 additions & 4 deletions

File tree

‎.fern/metadata.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cliVersion": "5.62.0",
33
"generatorName": "fernapi/fern-ruby-sdk",
44
"generatorVersion": "1.13.2",
5-
"originGitCommit": "fc9c2289d356522ad24b9464747364dd97f31a15",
5+
"originGitCommit": "e5e0764c693f384265aea6528e87792857387287",
66
"originGitCommitIsDirty": false,
77
"invokedBy": "ci",
88
"ciProvider": "github"

‎lib/gemconfig.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module TrophyApiClient
44
module Gemconfig
5-
VERSION = "1.18.0"
5+
VERSION = "1.19.0"
66
AUTHORS = ["Trophy Labs, Inc"].freeze
77
EMAIL = ""
88
SUMMARY = "Ruby library for the Trophy API."

‎lib/trophy.rb‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
require_relative "trophy/types/wrapped_activity"
140140
require_relative "trophy/types/wrapped_response"
141141
require_relative "trophy/types/admin_error_body"
142+
require_relative "trophy/types/batch_metric_event_user"
143+
require_relative "trophy/types/batch_metric_event"
144+
require_relative "trophy/types/batch_events_response"
142145
require_relative "trophy/types/admin_issue_severity"
143146
require_relative "trophy/types/admin_issue"
144147
require_relative "trophy/types/create_streak_freezes_response"

‎lib/trophy/admin/metrics/client.rb‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,40 @@ def get(request_options: {}, **params)
194194
raise error_class.new(response.body, code: code)
195195
end
196196
end
197+
198+
# Submit up to 1,000 metric events for asynchronous processing.
199+
#
200+
# @param request_options [Hash]
201+
# @param params [Hash]
202+
# @option request_options [String] :base_url
203+
# @option request_options [Hash{String => Object}] :additional_headers
204+
# @option request_options [Hash{String => Object}] :additional_query_parameters
205+
# @option request_options [Hash{String => Object}] :additional_body_parameters
206+
# @option request_options [Integer] :timeout_in_seconds
207+
#
208+
# @return [Trophy::Types::BatchEventsResponse]
209+
def batch_events(request_options: {}, **params)
210+
params = Trophy::Internal::Types::Utils.normalize_keys(params)
211+
request = Trophy::Internal::JSON::Request.new(
212+
base_url: request_options[:base_url] || @base_url || @environment&.dig(:admin),
213+
method: "POST",
214+
path: "metrics/events",
215+
body: params,
216+
request_options: request_options
217+
)
218+
begin
219+
response = @client.send(request)
220+
rescue Net::HTTPRequestTimeout
221+
raise Trophy::Errors::TimeoutError
222+
end
223+
code = response.code.to_i
224+
if code.between?(200, 299)
225+
Trophy::Types::BatchEventsResponse.load(response.body)
226+
else
227+
error_class = Trophy::Errors::ResponseError.subclass_for_code(code)
228+
raise error_class.new(response.body, code: code)
229+
end
230+
end
197231
end
198232
end
199233
end

‎lib/trophy/client.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Client
99
# @param max_retries [Integer]
1010
#
1111
# @return [void]
12-
def initialize(api_key:, base_url: nil, environment: Trophy::Environment::PRODUCTION, sdk_version: "1.18.0", max_retries: 2)
12+
def initialize(api_key:, base_url: nil, environment: Trophy::Environment::PRODUCTION, sdk_version: "1.19.0", max_retries: 2)
1313
@base_url = base_url
1414
@environment = environment
1515

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
module Trophy
4+
module Types
5+
# Response returned when a batch of metric events is accepted.
6+
class BatchEventsResponse < Internal::Types::Model
7+
field :accepted, -> { Integer }, optional: false, nullable: false
8+
end
9+
end
10+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module Trophy
4+
module Types
5+
# A metric event submitted as part of a batch. Same shape as a single metric event, with the metric key included in
6+
# the body.
7+
class BatchMetricEvent < Internal::Types::Model
8+
field :key, -> { String }, optional: false, nullable: false
9+
10+
field :user, -> { Trophy::Types::BatchMetricEventUser }, optional: false, nullable: false
11+
12+
field :value, -> { Integer }, optional: false, nullable: false
13+
14+
field :attributes, -> { Internal::Types::Hash[String, String] }, optional: true, nullable: false
15+
16+
field :idempotency_key, -> { String }, optional: true, nullable: false, api_name: "idempotencyKey"
17+
end
18+
end
19+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
module Trophy
4+
module Types
5+
# The user that triggered a batch metric event.
6+
class BatchMetricEventUser < Internal::Types::Model
7+
field :id, -> { String }, optional: false, nullable: false
8+
9+
field :email, -> { String }, optional: true, nullable: false
10+
11+
field :name, -> { String }, optional: true, nullable: false
12+
13+
field :tz, -> { String }, optional: true, nullable: false
14+
15+
field :device_tokens, -> { Internal::Types::Array[String] }, optional: true, nullable: false, api_name: "deviceTokens"
16+
17+
field :subscribe_to_emails, -> { Internal::Types::Boolean }, optional: true, nullable: false, api_name: "subscribeToEmails"
18+
19+
field :attributes, -> { Internal::Types::Hash[String, String] }, optional: true, nullable: false
20+
end
21+
end
22+
end

‎lib/trophy_api_client/version.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module MyGem
2-
VERSION = "1.18.0"
2+
VERSION = "1.19.0"
33
end

‎reference.md‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,6 +2712,85 @@ client.admin.metrics.get(id: "550e8400-e29b-41d4-a716-446655440000")
27122712
</dl>
27132713

27142714

2715+
</dd>
2716+
</dl>
2717+
</details>
2718+
2719+
<details><summary><code>client.admin.metrics.<a href="/lib/trophy/admin/metrics/client.rb">batch_events</a>(request) -> Trophy::Types::BatchEventsResponse</code></summary>
2720+
<dl>
2721+
<dd>
2722+
2723+
#### 📝 Description
2724+
2725+
<dl>
2726+
<dd>
2727+
2728+
<dl>
2729+
<dd>
2730+
2731+
Submit up to 1,000 metric events for asynchronous processing.
2732+
</dd>
2733+
</dl>
2734+
</dd>
2735+
</dl>
2736+
2737+
#### 🔌 Usage
2738+
2739+
<dl>
2740+
<dd>
2741+
2742+
<dl>
2743+
<dd>
2744+
2745+
```ruby
2746+
client.admin.metrics.batch_events(request: [{
2747+
key: "words-written",
2748+
user: {
2749+
id: "18",
2750+
email: "user@example.com",
2751+
tz: "Europe/London",
2752+
attributes: {
2753+
department: "engineering",
2754+
role: "developer"
2755+
}
2756+
},
2757+
value: 750,
2758+
attributes: {
2759+
category: "writing",
2760+
source: "mobile-app"
2761+
},
2762+
idempotency_key: "e4296e4b-8493-4bd1-9c30-5a1a9ac4d78f"
2763+
}])
2764+
```
2765+
</dd>
2766+
</dl>
2767+
</dd>
2768+
</dl>
2769+
2770+
#### ⚙️ Parameters
2771+
2772+
<dl>
2773+
<dd>
2774+
2775+
<dl>
2776+
<dd>
2777+
2778+
**request:** `Internal::Types::Array[Trophy::Types::BatchMetricEvent]`
2779+
2780+
</dd>
2781+
</dl>
2782+
2783+
<dl>
2784+
<dd>
2785+
2786+
**request_options:** `Trophy::Admin::Metrics::RequestOptions`
2787+
2788+
</dd>
2789+
</dl>
2790+
</dd>
2791+
</dl>
2792+
2793+
27152794
</dd>
27162795
</dl>
27172796
</details>

0 commit comments

Comments
 (0)