activitysmith 1.1.0 → 1.2.1

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,221 @@
1
+ =begin
2
+ #ActivitySmith API
3
+
4
+ #Send push notifications and Live Activities to your own devices via a single API key.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.7.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module OpenapiClient
17
+ class MetricValueUpdateResponse
18
+ attr_accessor :success
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :'success' => :'success'
24
+ }
25
+ end
26
+
27
+ # Returns all the JSON keys this model knows about
28
+ def self.acceptable_attributes
29
+ attribute_map.values
30
+ end
31
+
32
+ # Attribute type mapping.
33
+ def self.openapi_types
34
+ {
35
+ :'success' => :'Boolean'
36
+ }
37
+ end
38
+
39
+ # List of attributes with nullable: true
40
+ def self.openapi_nullable
41
+ Set.new([
42
+ ])
43
+ end
44
+
45
+ # Initializes the object
46
+ # @param [Hash] attributes Model attributes in the form of hash
47
+ def initialize(attributes = {})
48
+ if (!attributes.is_a?(Hash))
49
+ fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::MetricValueUpdateResponse` initialize method"
50
+ end
51
+
52
+ # check to see if the attribute exists and convert string to symbol for hash key
53
+ attributes = attributes.each_with_object({}) { |(k, v), h|
54
+ if (!self.class.attribute_map.key?(k.to_sym))
55
+ fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::MetricValueUpdateResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
56
+ end
57
+ h[k.to_sym] = v
58
+ }
59
+
60
+ if attributes.key?(:'success')
61
+ self.success = attributes[:'success']
62
+ else
63
+ self.success = nil
64
+ end
65
+ end
66
+
67
+ # Show invalid properties with the reasons. Usually used together with valid?
68
+ # @return Array for valid properties with the reasons
69
+ def list_invalid_properties
70
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
71
+ invalid_properties = Array.new
72
+ if @success.nil?
73
+ invalid_properties.push('invalid value for "success", success cannot be nil.')
74
+ end
75
+
76
+ invalid_properties
77
+ end
78
+
79
+ # Check to see if the all the properties in the model are valid
80
+ # @return true if the model is valid
81
+ def valid?
82
+ warn '[DEPRECATED] the `valid?` method is obsolete'
83
+ return false if @success.nil?
84
+ true
85
+ end
86
+
87
+ # Checks equality by comparing each attribute.
88
+ # @param [Object] Object to be compared
89
+ def ==(o)
90
+ return true if self.equal?(o)
91
+ self.class == o.class &&
92
+ success == o.success
93
+ end
94
+
95
+ # @see the `==` method
96
+ # @param [Object] Object to be compared
97
+ def eql?(o)
98
+ self == o
99
+ end
100
+
101
+ # Calculates hash code according to all attributes.
102
+ # @return [Integer] Hash code
103
+ def hash
104
+ [success].hash
105
+ end
106
+
107
+ # Builds the object from hash
108
+ # @param [Hash] attributes Model attributes in the form of hash
109
+ # @return [Object] Returns the model itself
110
+ def self.build_from_hash(attributes)
111
+ return nil unless attributes.is_a?(Hash)
112
+ attributes = attributes.transform_keys(&:to_sym)
113
+ transformed_hash = {}
114
+ openapi_types.each_pair do |key, type|
115
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
116
+ transformed_hash["#{key}"] = nil
117
+ elsif type =~ /\AArray<(.*)>/i
118
+ # check to ensure the input is an array given that the attribute
119
+ # is documented as an array but the input is not
120
+ if attributes[attribute_map[key]].is_a?(Array)
121
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
122
+ end
123
+ elsif !attributes[attribute_map[key]].nil?
124
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
125
+ end
126
+ end
127
+ new(transformed_hash)
128
+ end
129
+
130
+ # Deserializes the data based on type
131
+ # @param string type Data type
132
+ # @param string value Value to be deserialized
133
+ # @return [Object] Deserialized data
134
+ def self._deserialize(type, value)
135
+ case type.to_sym
136
+ when :Time
137
+ Time.parse(value)
138
+ when :Date
139
+ Date.parse(value)
140
+ when :String
141
+ value.to_s
142
+ when :Integer
143
+ value.to_i
144
+ when :Float
145
+ value.to_f
146
+ when :Boolean
147
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
148
+ true
149
+ else
150
+ false
151
+ end
152
+ when :Object
153
+ # generic object (usually a Hash), return directly
154
+ value
155
+ when /\AArray<(?<inner_type>.+)>\z/
156
+ inner_type = Regexp.last_match[:inner_type]
157
+ value.map { |v| _deserialize(inner_type, v) }
158
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
159
+ k_type = Regexp.last_match[:k_type]
160
+ v_type = Regexp.last_match[:v_type]
161
+ {}.tap do |hash|
162
+ value.each do |k, v|
163
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
164
+ end
165
+ end
166
+ else # model
167
+ # models (e.g. Pet) or oneOf
168
+ klass = OpenapiClient.const_get(type)
169
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
170
+ end
171
+ end
172
+
173
+ # Returns the string representation of the object
174
+ # @return [String] String presentation of the object
175
+ def to_s
176
+ to_hash.to_s
177
+ end
178
+
179
+ # to_body is an alias to to_hash (backward compatibility)
180
+ # @return [Hash] Returns the object in the form of hash
181
+ def to_body
182
+ to_hash
183
+ end
184
+
185
+ # Returns the object in the form of hash
186
+ # @return [Hash] Returns the object in the form of hash
187
+ def to_hash
188
+ hash = {}
189
+ self.class.attribute_map.each_pair do |attr, param|
190
+ value = self.send(attr)
191
+ if value.nil?
192
+ is_nullable = self.class.openapi_nullable.include?(attr)
193
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
194
+ end
195
+
196
+ hash[param] = _to_hash(value)
197
+ end
198
+ hash
199
+ end
200
+
201
+ # Outputs non-array value in the form of hash
202
+ # For object, use to_hash. Otherwise, just return the value
203
+ # @param [Object] value Any valid value
204
+ # @return [Hash] Returns the value in the form of hash
205
+ def _to_hash(value)
206
+ if value.is_a?(Array)
207
+ value.compact.map { |v| _to_hash(v) }
208
+ elsif value.is_a?(Hash)
209
+ {}.tap do |hash|
210
+ value.each { |k, v| hash[k] = _to_hash(v) }
211
+ end
212
+ elsif value.respond_to? :to_hash
213
+ value.to_hash
214
+ else
215
+ value
216
+ end
217
+ end
218
+
219
+ end
220
+
221
+ end
@@ -14,16 +14,16 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module OpenapiClient
17
- # Current state for a managed Live Activity stream. Include type on the first PUT, and whenever the stream may need to start a fresh activity. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based types.
17
+ # Current state for a managed Live Activity stream. Include type on the first PUT, and whenever the stream may need to start a fresh activity. Supports segmented_progress, progress, and metrics types.
18
18
  class StreamContentState
19
19
  attr_accessor :title
20
20
 
21
21
  attr_accessor :subtitle
22
22
 
23
- # Use for segmented_progress, counter, timer, and countdown.
23
+ # Use for segmented_progress.
24
24
  attr_accessor :number_of_steps
25
25
 
26
- # Use for segmented_progress, counter, timer, and countdown.
26
+ # Use for segmented_progress.
27
27
  attr_accessor :current_step
28
28
 
29
29
  # Use for progress. Takes precedence over value/upper_limit if both are provided.
@@ -258,7 +258,7 @@ module OpenapiClient
258
258
  return false if !@current_step.nil? && @current_step < 1
259
259
  return false if !@percentage.nil? && @percentage > 100
260
260
  return false if !@percentage.nil? && @percentage < 0
261
- type_validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress", "metrics", "counter", "timer", "countdown"])
261
+ type_validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress", "metrics"])
262
262
  return false unless type_validator.valid?(@type)
263
263
  color_validator = EnumAttributeValidator.new('String', ["lime", "green", "cyan", "blue", "purple", "magenta", "red", "orange", "yellow"])
264
264
  return false unless color_validator.valid?(@color)
@@ -319,7 +319,7 @@ module OpenapiClient
319
319
  # Custom attribute writer method checking allowed values (enum).
320
320
  # @param [Object] type Object to be assigned
321
321
  def type=(type)
322
- validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress", "metrics", "counter", "timer", "countdown"])
322
+ validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress", "metrics"])
323
323
  unless validator.valid?(type)
324
324
  fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}."
325
325
  end
@@ -11,5 +11,5 @@ Generator version: 7.7.0
11
11
  =end
12
12
 
13
13
  module OpenapiClient
14
- VERSION = '1.0.0'
14
+ VERSION = '1.2.1'
15
15
  end
@@ -39,6 +39,10 @@ require 'activitysmith_openapi/models/live_activity_stream_request'
39
39
  require 'activitysmith_openapi/models/live_activity_update_request'
40
40
  require 'activitysmith_openapi/models/live_activity_update_response'
41
41
  require 'activitysmith_openapi/models/live_activity_webhook_method'
42
+ require 'activitysmith_openapi/models/metric_error'
43
+ require 'activitysmith_openapi/models/metric_value_update_request'
44
+ require 'activitysmith_openapi/models/metric_value_update_request_value'
45
+ require 'activitysmith_openapi/models/metric_value_update_response'
42
46
  require 'activitysmith_openapi/models/no_recipients_error'
43
47
  require 'activitysmith_openapi/models/not_found_error'
44
48
  require 'activitysmith_openapi/models/push_notification_action'
@@ -52,6 +56,7 @@ require 'activitysmith_openapi/models/stream_content_state'
52
56
 
53
57
  # APIs
54
58
  require 'activitysmith_openapi/api/live_activities_api'
59
+ require 'activitysmith_openapi/api/metrics_api'
55
60
  require 'activitysmith_openapi/api/push_notifications_api'
56
61
 
57
62
  module OpenapiClient
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ActivitySmith
4
4
  class Client
5
- attr_reader :notifications, :live_activities
5
+ attr_reader :notifications, :live_activities, :metrics
6
6
 
7
7
  def initialize(api_key:)
8
8
  raise ArgumentError, "ActivitySmith: api_key is required" if api_key.to_s.strip.empty?
@@ -14,28 +14,40 @@ module ActivitySmith
14
14
  config.user_agent = VersionedUserAgent.value if config.respond_to?(:user_agent=)
15
15
 
16
16
  api_client = OpenapiClient::ApiClient.new(config)
17
+ api_client.user_agent = VersionedUserAgent.value
18
+ api_client.default_headers["X-ActivitySmith-SDK"] = "ruby-v#{ActivitySmith::VERSION}"
17
19
  @notifications = Notifications.new(OpenapiClient::PushNotificationsApi.new(api_client))
18
20
  @live_activities = LiveActivities.new(OpenapiClient::LiveActivitiesApi.new(api_client))
21
+ @metrics = Metrics.new(OpenapiClient::MetricsApi.new(api_client))
19
22
  end
20
23
 
21
24
  private
22
25
 
23
26
  def load_generated_client!
24
- generated_entrypoint = File.expand_path("../../generated/openapi_client", __dir__)
27
+ return if generated_client_present?
28
+
29
+ generated_root = File.expand_path("../../generated", __dir__)
30
+ $LOAD_PATH.unshift(generated_root) unless $LOAD_PATH.include?(generated_root)
31
+
32
+ generated_entrypoint = File.join(generated_root, "activitysmith_openapi")
25
33
  require generated_entrypoint if File.exist?("#{generated_entrypoint}.rb")
26
34
 
27
- required_constants = [
35
+ return if generated_client_present?
36
+
37
+ raise RuntimeError,
38
+ "Generated Ruby client not found. Run SDK regeneration so /generated contains OpenAPI output."
39
+ end
40
+
41
+ def generated_client_present?
42
+ missing = [
28
43
  "OpenapiClient::Configuration",
29
44
  "OpenapiClient::ApiClient",
30
45
  "OpenapiClient::PushNotificationsApi",
31
- "OpenapiClient::LiveActivitiesApi"
32
- ]
33
-
34
- missing = required_constants.reject { |name| constant_defined?(name) }
35
- return if missing.empty?
46
+ "OpenapiClient::LiveActivitiesApi",
47
+ "OpenapiClient::MetricsApi"
48
+ ].reject { |name| constant_defined?(name) }
36
49
 
37
- raise RuntimeError,
38
- "Generated Ruby client not found. Run SDK regeneration so /generated contains OpenAPI output."
50
+ missing.empty?
39
51
  end
40
52
 
41
53
  def constant_defined?(name)
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActivitySmith
4
+ class Metrics
5
+ def initialize(api)
6
+ @api = api
7
+ end
8
+
9
+ def update(key, value_or_request, timestamp: nil, **opts)
10
+ @api.update_metric_value(key, metric_value_request(value_or_request, timestamp), opts)
11
+ end
12
+
13
+ # Backward-compatible generated-style alias.
14
+ def update_metric_value(key, metric_value_update_request, opts = {})
15
+ @api.update_metric_value(key, metric_value_update_request, opts)
16
+ end
17
+
18
+ def method_missing(name, *args, &block)
19
+ return @api.public_send(name, *args, &block) if @api.respond_to?(name)
20
+
21
+ super
22
+ end
23
+
24
+ def respond_to_missing?(name, include_private = false)
25
+ @api.respond_to?(name, include_private) || super
26
+ end
27
+
28
+ private
29
+
30
+ def metric_value_request(value_or_request, timestamp)
31
+ if value_or_request.is_a?(Hash) && (value_or_request.key?(:value) || value_or_request.key?("value"))
32
+ hash = value_or_request.dup
33
+ hash[:timestamp] = timestamp unless timestamp.nil?
34
+ return hash
35
+ end
36
+
37
+ hash = { value: value_or_request }
38
+ hash[:timestamp] = timestamp unless timestamp.nil?
39
+ hash
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActivitySmith
4
- VERSION = "1.1.0"
4
+ VERSION = "1.2.1"
5
5
  end
data/lib/activitysmith.rb CHANGED
@@ -4,4 +4,5 @@ require_relative "activitysmith/version"
4
4
  require_relative "activitysmith/versioned_user_agent"
5
5
  require_relative "activitysmith/notifications"
6
6
  require_relative "activitysmith/live_activities"
7
+ require_relative "activitysmith/metrics"
7
8
  require_relative "activitysmith/client"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activitysmith
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ActivitySmith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-22 00:00:00.000000000 Z
11
+ date: 2026-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -77,6 +77,7 @@ files:
77
77
  - README.md
78
78
  - generated/activitysmith_openapi.rb
79
79
  - generated/activitysmith_openapi/api/live_activities_api.rb
80
+ - generated/activitysmith_openapi/api/metrics_api.rb
80
81
  - generated/activitysmith_openapi/api/push_notifications_api.rb
81
82
  - generated/activitysmith_openapi/api_client.rb
82
83
  - generated/activitysmith_openapi/api_error.rb
@@ -103,6 +104,10 @@ files:
103
104
  - generated/activitysmith_openapi/models/live_activity_update_request.rb
104
105
  - generated/activitysmith_openapi/models/live_activity_update_response.rb
105
106
  - generated/activitysmith_openapi/models/live_activity_webhook_method.rb
107
+ - generated/activitysmith_openapi/models/metric_error.rb
108
+ - generated/activitysmith_openapi/models/metric_value_update_request.rb
109
+ - generated/activitysmith_openapi/models/metric_value_update_request_value.rb
110
+ - generated/activitysmith_openapi/models/metric_value_update_response.rb
106
111
  - generated/activitysmith_openapi/models/no_recipients_error.rb
107
112
  - generated/activitysmith_openapi/models/not_found_error.rb
108
113
  - generated/activitysmith_openapi/models/push_notification_action.rb
@@ -117,6 +122,7 @@ files:
117
122
  - lib/activitysmith.rb
118
123
  - lib/activitysmith/client.rb
119
124
  - lib/activitysmith/live_activities.rb
125
+ - lib/activitysmith/metrics.rb
120
126
  - lib/activitysmith/notifications.rb
121
127
  - lib/activitysmith/version.rb
122
128
  - lib/activitysmith/versioned_user_agent.rb