From 9caa7be5b9706d5627ba1595fc3973d93cfa3acb Mon Sep 17 00:00:00 2001 From: activitysmith-bot Date: Mon, 26 Oct 2026 03:00:35 +0000 Subject: [PATCH 1/2] chore: regenerate SDK --- generated/activitysmith_openapi.rb | 3 + .../api/app_icon_badges_api.rb | 8 +- .../activitysmith_openapi/api/metrics_api.rb | 91 +++- .../app_icon_badge_count_update_response.rb | 2 +- .../activitysmith_openapi/models/metric.rb | 411 ++++++++++++++++++ .../models/metric_response.rb | 221 ++++++++++ .../models/metric_upsert_request.rb | 370 ++++++++++++++++ .../models/metric_value_update_response.rb | 18 +- generated/openapi-source.json | 4 +- 9 files changed, 1113 insertions(+), 15 deletions(-) create mode 100644 generated/activitysmith_openapi/models/metric.rb create mode 100644 generated/activitysmith_openapi/models/metric_response.rb create mode 100644 generated/activitysmith_openapi/models/metric_upsert_request.rb diff --git a/generated/activitysmith_openapi.rb b/generated/activitysmith_openapi.rb index a810273..2264a0c 100644 --- a/generated/activitysmith_openapi.rb +++ b/generated/activitysmith_openapi.rb @@ -50,7 +50,10 @@ require 'activitysmith_openapi/models/live_activity_value' require 'activitysmith_openapi/models/live_activity_webhook_method' require 'activitysmith_openapi/models/metadata_value' +require 'activitysmith_openapi/models/metric' require 'activitysmith_openapi/models/metric_error' +require 'activitysmith_openapi/models/metric_response' +require 'activitysmith_openapi/models/metric_upsert_request' require 'activitysmith_openapi/models/metric_value_update_request' require 'activitysmith_openapi/models/metric_value_update_request_value' require 'activitysmith_openapi/models/metric_value_update_response' diff --git a/generated/activitysmith_openapi/api/app_icon_badges_api.rb b/generated/activitysmith_openapi/api/app_icon_badges_api.rb index a1deb11..7d1870c 100644 --- a/generated/activitysmith_openapi/api/app_icon_badges_api.rb +++ b/generated/activitysmith_openapi/api/app_icon_badges_api.rb @@ -19,8 +19,8 @@ class AppIconBadgesApi def initialize(api_client = ApiClient.default) @api_client = api_client end - # Set App Icon Badge Count - # Shows a number on the ActivitySmith app icon. + # Set App Icon Badge + # Shows a number on the ActivitySmith app icon. Requires Push Notifications enabled for ActivitySmith on the device. # @param app_icon_badge_count_update_request [AppIconBadgeCountUpdateRequest] # @param [Hash] opts the optional parameters # @return [AppIconBadgeCountUpdateResponse] @@ -29,8 +29,8 @@ def update_app_icon_badge_count(app_icon_badge_count_update_request, opts = {}) data end - # Set App Icon Badge Count - # Shows a number on the ActivitySmith app icon. + # Set App Icon Badge + # Shows a number on the ActivitySmith app icon. Requires Push Notifications enabled for ActivitySmith on the device. # @param app_icon_badge_count_update_request [AppIconBadgeCountUpdateRequest] # @param [Hash] opts the optional parameters # @return [Array<(AppIconBadgeCountUpdateResponse, Integer, Hash)>] AppIconBadgeCountUpdateResponse data, response status code and response headers diff --git a/generated/activitysmith_openapi/api/metrics_api.rb b/generated/activitysmith_openapi/api/metrics_api.rb index 1efa62b..f0d5e05 100644 --- a/generated/activitysmith_openapi/api/metrics_api.rb +++ b/generated/activitysmith_openapi/api/metrics_api.rb @@ -20,8 +20,8 @@ def initialize(api_client = ApiClient.default) @api_client = api_client end # Update a widget metric value - # Updates the latest value for a metric displayed in ActivitySmith widgets. Create the metric in the web app first, then update its value using the key. Metric updates have an independent 300-requests-per-minute account allowance. They do not consume the Push Notification, badge, or Live Activity allowances. - # @param key [String] Metric key configured in the web app. Lowercase letters, numbers, dots, underscores, and dashes are allowed. + # Updates the latest value for a metric displayed in ActivitySmith widgets. If no metric uses the key yet, the first value creates one: the label comes from the key, numeric values get the number format, and text values get the string format. To choose a currency, percent, or unit format, create the metric first with PUT /metrics/{key} or in the web app. A deleted metric is not recreated by new values; the request returns 404 with code metric_deleted. Each account can have up to 100 metrics created through the API. Metric updates have an independent 300-requests-per-minute account allowance. They do not consume the Push Notification, badge, or Live Activity allowances. + # @param key [String] Metric key. A key that has never been used creates the metric. Lowercase letters, numbers, dots, underscores, and dashes are allowed. # @param metric_value_update_request [MetricValueUpdateRequest] # @param [Hash] opts the optional parameters # @return [MetricValueUpdateResponse] @@ -31,8 +31,8 @@ def update_metric_value(key, metric_value_update_request, opts = {}) end # Update a widget metric value - # Updates the latest value for a metric displayed in ActivitySmith widgets. Create the metric in the web app first, then update its value using the key. Metric updates have an independent 300-requests-per-minute account allowance. They do not consume the Push Notification, badge, or Live Activity allowances. - # @param key [String] Metric key configured in the web app. Lowercase letters, numbers, dots, underscores, and dashes are allowed. + # Updates the latest value for a metric displayed in ActivitySmith widgets. If no metric uses the key yet, the first value creates one: the label comes from the key, numeric values get the number format, and text values get the string format. To choose a currency, percent, or unit format, create the metric first with PUT /metrics/{key} or in the web app. A deleted metric is not recreated by new values; the request returns 404 with code metric_deleted. Each account can have up to 100 metrics created through the API. Metric updates have an independent 300-requests-per-minute account allowance. They do not consume the Push Notification, badge, or Live Activity allowances. + # @param key [String] Metric key. A key that has never been used creates the metric. Lowercase letters, numbers, dots, underscores, and dashes are allowed. # @param metric_value_update_request [MetricValueUpdateRequest] # @param [Hash] opts the optional parameters # @return [Array<(MetricValueUpdateResponse, Integer, Hash)>] MetricValueUpdateResponse data, response status code and response headers @@ -105,5 +105,88 @@ def update_metric_value_with_http_info(key, metric_value_update_request, opts = end return data, status_code, headers end + + # Create or update a widget metric + # Creates a metric for widgets, or updates the fields sent for an existing metric. Omitted fields keep their current values, so repeating the same request does not change the metric. Changing between the string format and a numeric format clears the latest value. Shares the metric account allowance of 300 requests per minute and is not a billable metric update. + # @param key [String] Metric key. Lowercase letters, numbers, dots, underscores, and dashes are allowed. + # @param [Hash] opts the optional parameters + # @option opts [MetricUpsertRequest] :metric_upsert_request + # @return [MetricResponse] + def upsert_metric(key, opts = {}) + data, _status_code, _headers = upsert_metric_with_http_info(key, opts) + data + end + + # Create or update a widget metric + # Creates a metric for widgets, or updates the fields sent for an existing metric. Omitted fields keep their current values, so repeating the same request does not change the metric. Changing between the string format and a numeric format clears the latest value. Shares the metric account allowance of 300 requests per minute and is not a billable metric update. + # @param key [String] Metric key. Lowercase letters, numbers, dots, underscores, and dashes are allowed. + # @param [Hash] opts the optional parameters + # @option opts [MetricUpsertRequest] :metric_upsert_request + # @return [Array<(MetricResponse, Integer, Hash)>] MetricResponse data, response status code and response headers + def upsert_metric_with_http_info(key, opts = {}) + if @api_client.config.debugging + @api_client.config.logger.debug 'Calling API: MetricsApi.upsert_metric ...' + end + # verify the required parameter 'key' is set + if @api_client.config.client_side_validation && key.nil? + fail ArgumentError, "Missing the required parameter 'key' when calling MetricsApi.upsert_metric" + end + if @api_client.config.client_side_validation && key.to_s.length > 64 + fail ArgumentError, 'invalid value for "key" when calling MetricsApi.upsert_metric, the character length must be smaller than or equal to 64.' + end + + if @api_client.config.client_side_validation && key.to_s.length < 1 + fail ArgumentError, 'invalid value for "key" when calling MetricsApi.upsert_metric, the character length must be great than or equal to 1.' + end + + pattern = Regexp.new(/^[a-z0-9][a-z0-9_.-]{0,63}$/) + if @api_client.config.client_side_validation && key !~ pattern + fail ArgumentError, "invalid value for 'key' when calling MetricsApi.upsert_metric, must conform to the pattern #{pattern}." + end + + # resource path + local_var_path = '/metrics/{key}'.sub('{' + 'key' + '}', CGI.escape(key.to_s)) + + # query parameters + query_params = opts[:query_params] || {} + + # header parameters + header_params = opts[:header_params] || {} + # HTTP header 'Accept' (if needed) + header_params['Accept'] = @api_client.select_header_accept(['application/json']) + # HTTP header 'Content-Type' + content_type = @api_client.select_header_content_type(['application/json']) + if !content_type.nil? + header_params['Content-Type'] = content_type + end + + # form parameters + form_params = opts[:form_params] || {} + + # http body (model) + post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'metric_upsert_request']) + + # return_type + return_type = opts[:debug_return_type] || 'MetricResponse' + + # auth_names + auth_names = opts[:debug_auth_names] || ['apiKeyAuth'] + + new_options = opts.merge( + :operation => :"MetricsApi.upsert_metric", + :header_params => header_params, + :query_params => query_params, + :form_params => form_params, + :body => post_body, + :auth_names => auth_names, + :return_type => return_type + ) + + data, status_code, headers = @api_client.call_api(:PUT, local_var_path, new_options) + if @api_client.config.debugging + @api_client.config.logger.debug "API called: MetricsApi#upsert_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + end + return data, status_code, headers + end end end diff --git a/generated/activitysmith_openapi/models/app_icon_badge_count_update_response.rb b/generated/activitysmith_openapi/models/app_icon_badge_count_update_response.rb index 02eb456..e996a29 100644 --- a/generated/activitysmith_openapi/models/app_icon_badge_count_update_response.rb +++ b/generated/activitysmith_openapi/models/app_icon_badge_count_update_response.rb @@ -19,7 +19,7 @@ class AppIconBadgeCountUpdateResponse attr_accessor :badge - # Number of devices whose App Icon Badge Count was updated. + # Number of devices whose App Icon Badge was updated. attr_accessor :devices_updated # Number of account users with at least one updated device. diff --git a/generated/activitysmith_openapi/models/metric.rb b/generated/activitysmith_openapi/models/metric.rb new file mode 100644 index 0000000..e6823e7 --- /dev/null +++ b/generated/activitysmith_openapi/models/metric.rb @@ -0,0 +1,411 @@ +=begin +#ActivitySmith API + +#Send push notifications and Live Activities to your own devices via a single API key. + +The version of the OpenAPI document: 1.0.0 + +Generated by: https://openapi-generator.tech +Generator version: 7.7.0 + +=end + +require 'date' +require 'time' + +module OpenapiClient + class Metric + attr_accessor :public_id + + attr_accessor :key + + attr_accessor :label + + attr_accessor :format + + attr_accessor :currency_code + + attr_accessor :unit + + attr_accessor :unit_spacing + + attr_accessor :latest_value + + attr_accessor :latest_value_at + + attr_accessor :created_at + + attr_accessor :updated_at + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'public_id' => :'public_id', + :'key' => :'key', + :'label' => :'label', + :'format' => :'format', + :'currency_code' => :'currency_code', + :'unit' => :'unit', + :'unit_spacing' => :'unit_spacing', + :'latest_value' => :'latest_value', + :'latest_value_at' => :'latest_value_at', + :'created_at' => :'created_at', + :'updated_at' => :'updated_at' + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'public_id' => :'String', + :'key' => :'String', + :'label' => :'String', + :'format' => :'String', + :'currency_code' => :'String', + :'unit' => :'String', + :'unit_spacing' => :'String', + :'latest_value' => :'Object', + :'latest_value_at' => :'Time', + :'created_at' => :'Time', + :'updated_at' => :'Time' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + :'currency_code', + :'unit', + :'latest_value', + :'latest_value_at', + ]) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::Metric` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::Metric`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'public_id') + self.public_id = attributes[:'public_id'] + else + self.public_id = nil + end + + if attributes.key?(:'key') + self.key = attributes[:'key'] + else + self.key = nil + end + + if attributes.key?(:'label') + self.label = attributes[:'label'] + else + self.label = nil + end + + if attributes.key?(:'format') + self.format = attributes[:'format'] + else + self.format = nil + end + + if attributes.key?(:'currency_code') + self.currency_code = attributes[:'currency_code'] + else + self.currency_code = nil + end + + if attributes.key?(:'unit') + self.unit = attributes[:'unit'] + else + self.unit = nil + end + + if attributes.key?(:'unit_spacing') + self.unit_spacing = attributes[:'unit_spacing'] + else + self.unit_spacing = nil + end + + if attributes.key?(:'latest_value') + self.latest_value = attributes[:'latest_value'] + else + self.latest_value = nil + end + + if attributes.key?(:'latest_value_at') + self.latest_value_at = attributes[:'latest_value_at'] + else + self.latest_value_at = nil + end + + if attributes.key?(:'created_at') + self.created_at = attributes[:'created_at'] + else + self.created_at = nil + end + + if attributes.key?(:'updated_at') + self.updated_at = attributes[:'updated_at'] + else + self.updated_at = nil + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' + invalid_properties = Array.new + if @public_id.nil? + invalid_properties.push('invalid value for "public_id", public_id cannot be nil.') + end + + if @key.nil? + invalid_properties.push('invalid value for "key", key cannot be nil.') + end + + if @label.nil? + invalid_properties.push('invalid value for "label", label cannot be nil.') + end + + if @format.nil? + invalid_properties.push('invalid value for "format", format cannot be nil.') + end + + if @unit_spacing.nil? + invalid_properties.push('invalid value for "unit_spacing", unit_spacing cannot be nil.') + end + + if @created_at.nil? + invalid_properties.push('invalid value for "created_at", created_at cannot be nil.') + end + + if @updated_at.nil? + invalid_properties.push('invalid value for "updated_at", updated_at cannot be nil.') + end + + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + warn '[DEPRECATED] the `valid?` method is obsolete' + return false if @public_id.nil? + return false if @key.nil? + return false if @label.nil? + return false if @format.nil? + format_validator = EnumAttributeValidator.new('String', ["number", "currency", "percent", "unit", "string"]) + return false unless format_validator.valid?(@format) + return false if @unit_spacing.nil? + unit_spacing_validator = EnumAttributeValidator.new('String', ["none", "space"]) + return false unless unit_spacing_validator.valid?(@unit_spacing) + return false if @created_at.nil? + return false if @updated_at.nil? + true + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] format Object to be assigned + def format=(format) + validator = EnumAttributeValidator.new('String', ["number", "currency", "percent", "unit", "string"]) + unless validator.valid?(format) + fail ArgumentError, "invalid value for \"format\", must be one of #{validator.allowable_values}." + end + @format = format + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] unit_spacing Object to be assigned + def unit_spacing=(unit_spacing) + validator = EnumAttributeValidator.new('String', ["none", "space"]) + unless validator.valid?(unit_spacing) + fail ArgumentError, "invalid value for \"unit_spacing\", must be one of #{validator.allowable_values}." + end + @unit_spacing = unit_spacing + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + public_id == o.public_id && + key == o.key && + label == o.label && + format == o.format && + currency_code == o.currency_code && + unit == o.unit && + unit_spacing == o.unit_spacing && + latest_value == o.latest_value && + latest_value_at == o.latest_value_at && + created_at == o.created_at && + updated_at == o.updated_at + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [public_id, key, label, format, currency_code, unit, unit_spacing, latest_value, latest_value_at, created_at, updated_at].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + openapi_types.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + end + end + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + # models (e.g. Pet) or oneOf + klass = OpenapiClient.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + + end + +end diff --git a/generated/activitysmith_openapi/models/metric_response.rb b/generated/activitysmith_openapi/models/metric_response.rb new file mode 100644 index 0000000..6145d2f --- /dev/null +++ b/generated/activitysmith_openapi/models/metric_response.rb @@ -0,0 +1,221 @@ +=begin +#ActivitySmith API + +#Send push notifications and Live Activities to your own devices via a single API key. + +The version of the OpenAPI document: 1.0.0 + +Generated by: https://openapi-generator.tech +Generator version: 7.7.0 + +=end + +require 'date' +require 'time' + +module OpenapiClient + class MetricResponse + attr_accessor :metric + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'metric' => :'metric' + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'metric' => :'Metric' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + ]) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::MetricResponse` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::MetricResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'metric') + self.metric = attributes[:'metric'] + else + self.metric = nil + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' + invalid_properties = Array.new + if @metric.nil? + invalid_properties.push('invalid value for "metric", metric cannot be nil.') + end + + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + warn '[DEPRECATED] the `valid?` method is obsolete' + return false if @metric.nil? + true + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + metric == o.metric + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [metric].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + openapi_types.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + end + end + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + # models (e.g. Pet) or oneOf + klass = OpenapiClient.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + + end + +end diff --git a/generated/activitysmith_openapi/models/metric_upsert_request.rb b/generated/activitysmith_openapi/models/metric_upsert_request.rb new file mode 100644 index 0000000..ad826c5 --- /dev/null +++ b/generated/activitysmith_openapi/models/metric_upsert_request.rb @@ -0,0 +1,370 @@ +=begin +#ActivitySmith API + +#Send push notifications and Live Activities to your own devices via a single API key. + +The version of the OpenAPI document: 1.0.0 + +Generated by: https://openapi-generator.tech +Generator version: 7.7.0 + +=end + +require 'date' +require 'time' + +module OpenapiClient + # Metric definition. Omitted fields keep their current values, or use defaults for a new metric: a label made from the key and the number format. + class MetricUpsertRequest + # Name shown on the widget. + attr_accessor :label + + # How widgets display the value: number (1,234), currency (requires currency_code), percent (send 99.9 to show 99.9%), unit (a number with a unit suffix, such as 120 ms), or string (text up to 64 characters). Defaults to number for a new metric. + attr_accessor :format + + # 3-letter ISO 4217 currency code, such as USD. Required for the currency format. + attr_accessor :currency_code + + # Unit suffix for the unit format, such as ms or GB. + attr_accessor :unit + + # For the unit format: none shows 120ms, space shows 120 ms. + attr_accessor :unit_spacing + + class EnumAttributeValidator + attr_reader :datatype + attr_reader :allowable_values + + def initialize(datatype, allowable_values) + @allowable_values = allowable_values.map do |value| + case datatype.to_s + when /Integer/i + value.to_i + when /Float/i + value.to_f + else + value + end + end + end + + def valid?(value) + !value || allowable_values.include?(value) + end + end + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'label' => :'label', + :'format' => :'format', + :'currency_code' => :'currency_code', + :'unit' => :'unit', + :'unit_spacing' => :'unit_spacing' + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.openapi_types + { + :'label' => :'String', + :'format' => :'String', + :'currency_code' => :'String', + :'unit' => :'String', + :'unit_spacing' => :'String' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + ]) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::MetricUpsertRequest` initialize method" + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::MetricUpsertRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + end + h[k.to_sym] = v + } + + if attributes.key?(:'label') + self.label = attributes[:'label'] + end + + if attributes.key?(:'format') + self.format = attributes[:'format'] + end + + if attributes.key?(:'currency_code') + self.currency_code = attributes[:'currency_code'] + end + + if attributes.key?(:'unit') + self.unit = attributes[:'unit'] + end + + if attributes.key?(:'unit_spacing') + self.unit_spacing = attributes[:'unit_spacing'] + end + end + + # Show invalid properties with the reasons. Usually used together with valid? + # @return Array for valid properties with the reasons + def list_invalid_properties + warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' + invalid_properties = Array.new + if !@label.nil? && @label.to_s.length > 80 + invalid_properties.push('invalid value for "label", the character length must be smaller than or equal to 80.') + end + + if !@label.nil? && @label.to_s.length < 1 + invalid_properties.push('invalid value for "label", the character length must be great than or equal to 1.') + end + + pattern = Regexp.new(/^[A-Za-z]{3}$/) + if !@currency_code.nil? && @currency_code !~ pattern + invalid_properties.push("invalid value for \"currency_code\", must conform to the pattern #{pattern}.") + end + + if !@unit.nil? && @unit.to_s.length > 16 + invalid_properties.push('invalid value for "unit", the character length must be smaller than or equal to 16.') + end + + invalid_properties + end + + # Check to see if the all the properties in the model are valid + # @return true if the model is valid + def valid? + warn '[DEPRECATED] the `valid?` method is obsolete' + return false if !@label.nil? && @label.to_s.length > 80 + return false if !@label.nil? && @label.to_s.length < 1 + format_validator = EnumAttributeValidator.new('String', ["number", "currency", "percent", "unit", "string"]) + return false unless format_validator.valid?(@format) + return false if !@currency_code.nil? && @currency_code !~ Regexp.new(/^[A-Za-z]{3}$/) + return false if !@unit.nil? && @unit.to_s.length > 16 + unit_spacing_validator = EnumAttributeValidator.new('String', ["none", "space"]) + return false unless unit_spacing_validator.valid?(@unit_spacing) + true + end + + # Custom attribute writer method with validation + # @param [Object] label Value to be assigned + def label=(label) + if label.nil? + fail ArgumentError, 'label cannot be nil' + end + + if label.to_s.length > 80 + fail ArgumentError, 'invalid value for "label", the character length must be smaller than or equal to 80.' + end + + if label.to_s.length < 1 + fail ArgumentError, 'invalid value for "label", the character length must be great than or equal to 1.' + end + + @label = label + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] format Object to be assigned + def format=(format) + validator = EnumAttributeValidator.new('String', ["number", "currency", "percent", "unit", "string"]) + unless validator.valid?(format) + fail ArgumentError, "invalid value for \"format\", must be one of #{validator.allowable_values}." + end + @format = format + end + + # Custom attribute writer method with validation + # @param [Object] currency_code Value to be assigned + def currency_code=(currency_code) + if currency_code.nil? + fail ArgumentError, 'currency_code cannot be nil' + end + + pattern = Regexp.new(/^[A-Za-z]{3}$/) + if currency_code !~ pattern + fail ArgumentError, "invalid value for \"currency_code\", must conform to the pattern #{pattern}." + end + + @currency_code = currency_code + end + + # Custom attribute writer method with validation + # @param [Object] unit Value to be assigned + def unit=(unit) + if unit.nil? + fail ArgumentError, 'unit cannot be nil' + end + + if unit.to_s.length > 16 + fail ArgumentError, 'invalid value for "unit", the character length must be smaller than or equal to 16.' + end + + @unit = unit + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] unit_spacing Object to be assigned + def unit_spacing=(unit_spacing) + validator = EnumAttributeValidator.new('String', ["none", "space"]) + unless validator.valid?(unit_spacing) + fail ArgumentError, "invalid value for \"unit_spacing\", must be one of #{validator.allowable_values}." + end + @unit_spacing = unit_spacing + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(o) + return true if self.equal?(o) + self.class == o.class && + label == o.label && + format == o.format && + currency_code == o.currency_code && + unit == o.unit && + unit_spacing == o.unit_spacing + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(o) + self == o + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [label, format, currency_code, unit, unit_spacing].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + openapi_types.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + end + end + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + else # model + # models (e.g. Pet) or oneOf + klass = OpenapiClient.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = self.send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to? :to_hash + value.to_hash + else + value + end + end + + end + +end diff --git a/generated/activitysmith_openapi/models/metric_value_update_response.rb b/generated/activitysmith_openapi/models/metric_value_update_response.rb index daab4cd..6d2d85b 100644 --- a/generated/activitysmith_openapi/models/metric_value_update_response.rb +++ b/generated/activitysmith_openapi/models/metric_value_update_response.rb @@ -17,10 +17,14 @@ module OpenapiClient class MetricValueUpdateResponse attr_accessor :success + # true when this request created the metric because no metric used the key yet. + attr_accessor :created + # Attribute mapping from ruby-style variable name to JSON key. def self.attribute_map { - :'success' => :'success' + :'success' => :'success', + :'created' => :'created' } end @@ -32,7 +36,8 @@ def self.acceptable_attributes # Attribute type mapping. def self.openapi_types { - :'success' => :'Boolean' + :'success' => :'Boolean', + :'created' => :'Boolean' } end @@ -62,6 +67,10 @@ def initialize(attributes = {}) else self.success = nil end + + if attributes.key?(:'created') + self.created = attributes[:'created'] + end end # Show invalid properties with the reasons. Usually used together with valid? @@ -89,7 +98,8 @@ def valid? def ==(o) return true if self.equal?(o) self.class == o.class && - success == o.success + success == o.success && + created == o.created end # @see the `==` method @@ -101,7 +111,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [success].hash + [success, created].hash end # Builds the object from hash diff --git a/generated/openapi-source.json b/generated/openapi-source.json index 8c9c874..498433c 100644 --- a/generated/openapi-source.json +++ b/generated/openapi-source.json @@ -1,6 +1,6 @@ { "repository": "ActivitySmithHQ/activitysmith-backend", - "commit": "ab7064d65ad2097e3b57dc435c10b4f80a0ee27e", + "commit": "7bf9c3d88459fe3f122810979a45da0a1e6fd2d6", "path": "openapi.json", - "sha256": "f0548e423e06f90169dae8d935b08f78291e9dbf95d4ae591e6d10d8eb269448" + "sha256": "6987f90b106e28a0ab8058f43309e7a9f045c7c54d27ce90bbdd5966c3f99f7a" } From 8610c3f69fdf9d1894b91916a531d7628963787a Mon Sep 17 00:00:00 2001 From: bardonadam Date: Mon, 26 Oct 2026 10:04:30 +0700 Subject: [PATCH 2/2] Add metrics.create for PUT /metrics/{key} Co-Authored-By: Claude Opus 5.5 --- lib/activitysmith/metrics.rb | 16 ++++++++- test/metrics_test.rb | 14 ++++++++ test/support/metrics_serialization.rb | 48 +++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 test/metrics_test.rb create mode 100644 test/support/metrics_serialization.rb diff --git a/lib/activitysmith/metrics.rb b/lib/activitysmith/metrics.rb index 8a8b290..21dbcec 100644 --- a/lib/activitysmith/metrics.rb +++ b/lib/activitysmith/metrics.rb @@ -10,7 +10,21 @@ def update(key, value_or_request, timestamp: nil, **opts) @api.update_metric_value(key, metric_value_request(value_or_request, timestamp), opts) end - # Backward-compatible generated-style alias. + # Creates the metric, or updates the fields sent for an existing one. + # Omitted fields keep their current values, so it is safe to call on every start. + def create(key, definition = nil, label: nil, format: nil, currency_code: nil, unit: nil, unit_spacing: nil, **opts) + fields = { label: label, format: format, currency_code: currency_code, unit: unit, unit_spacing: unit_spacing }.compact + request = fields.empty? ? definition : (definition || {}).to_h.merge(fields) + request = nil if request.respond_to?(:empty?) && request.empty? + opts = opts.merge(metric_upsert_request: request) unless request.nil? + @api.upsert_metric(key, opts) + end + + # Backward-compatible generated-style aliases. + def upsert_metric(key, opts = {}) + @api.upsert_metric(key, opts) + end + def update_metric_value(key, metric_value_update_request, opts = {}) @api.update_metric_value(key, metric_value_update_request, opts) end diff --git a/test/metrics_test.rb b/test/metrics_test.rb new file mode 100644 index 0000000..eaad0a8 --- /dev/null +++ b/test/metrics_test.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require_relative 'test_helper' +require 'open3' +require 'rbconfig' + +class MetricsSerializationTest < Minitest::Test + def test_real_generated_client_in_isolation + # Other wrapper tests install fake OpenapiClient classes globally. + output, status = Open3.capture2e(RbConfig.ruby, '-Ilib', 'test/support/metrics_serialization.rb') + assert status.success?, output + assert_includes output, '0 failures, 0 errors' + end +end diff --git a/test/support/metrics_serialization.rb b/test/support/metrics_serialization.rb new file mode 100644 index 0000000..befa025 --- /dev/null +++ b/test/support/metrics_serialization.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require_relative '../test_helper' +require 'json' + +class MetricsCreateTest < Minitest::Test + METRIC_RESPONSE = '{"metric":{"public_id":"m1","key":"mrr","label":"MRR","format":"currency","currency_code":"USD",' \ + '"unit":null,"unit_spacing":"none","latest_value":null,"latest_value_at":null,' \ + '"created_at":"2026-10-26T09:00:00Z","updated_at":"2026-10-26T09:00:00Z"}}' + + def metrics_with_capture(captured) + ActivitySmith::Client.new(api_key: 'mock-only') + api_client = OpenapiClient::ApiClient.new + api_client.define_singleton_method(:call_api) do |http_method, path, opts = {}| + request = build_request(http_method, path, opts) + body = request.options[:body] + captured << [http_method, path, body.nil? || body.empty? ? nil : JSON.parse(body)] + response = Struct.new(:body, :headers).new(METRIC_RESPONSE, { 'Content-Type' => 'application/json' }) + [deserialize(response, opts[:return_type]), 201, {}] + end + ActivitySmith::Metrics.new(OpenapiClient::MetricsApi.new(api_client)) + end + + def test_create_serializes_definition_forms + expected = { 'label' => 'MRR', 'format' => 'currency', 'currency_code' => 'USD' } + captured = [] + metrics = metrics_with_capture(captured) + + response = metrics.create('mrr', label: 'MRR', format: 'currency', currency_code: 'USD') + metrics.create('mrr', { label: 'MRR', format: 'currency', currency_code: 'USD' }) + metrics.upsert_metric('mrr', metric_upsert_request: { label: 'MRR', format: 'currency', currency_code: 'USD' }) + + assert_equal [[:PUT, '/metrics/mrr', expected]] * 3, captured + assert_equal 'USD', response.metric.currency_code + assert_nil response.metric.unit + end + + def test_create_merges_keywords_and_sends_no_body_for_defaults + captured = [] + metrics = metrics_with_capture(captured) + + metrics.create('latency', { format: 'unit', unit: 'ms' }, unit_spacing: 'space') + metrics.create('deploy.success_rate') + + assert_equal [:PUT, '/metrics/latency', { 'format' => 'unit', 'unit' => 'ms', 'unit_spacing' => 'space' }], captured[0] + assert_equal [:PUT, '/metrics/deploy.success_rate', nil], captured[1] + end +end