From f84f9fa1864752814c869d3096a281e292476eae Mon Sep 17 00:00:00 2001 From: activitysmith-bot Date: Sun, 22 Mar 2026 12:57:04 +0000 Subject: [PATCH 1/2] chore: regenerate SDK --- generated/activitysmith_openapi.rb | 7 + .../api/live_activities_api.rb | 174 +++++- .../models/activity_metric.rb | 293 ++++++++++ .../models/content_state_end.rb | 51 +- .../models/content_state_start.rb | 57 +- .../models/content_state_update.rb | 57 +- .../live_activity_stream_delete_request.rb | 233 ++++++++ .../live_activity_stream_delete_response.rb | 332 +++++++++++ .../live_activity_stream_put_response.rb | 361 ++++++++++++ .../models/live_activity_stream_request.rb | 280 +++++++++ .../models/not_found_error.rb | 237 ++++++++ .../models/stream_content_state.rb | 538 ++++++++++++++++++ 12 files changed, 2596 insertions(+), 24 deletions(-) create mode 100644 generated/activitysmith_openapi/models/activity_metric.rb create mode 100644 generated/activitysmith_openapi/models/live_activity_stream_delete_request.rb create mode 100644 generated/activitysmith_openapi/models/live_activity_stream_delete_response.rb create mode 100644 generated/activitysmith_openapi/models/live_activity_stream_put_response.rb create mode 100644 generated/activitysmith_openapi/models/live_activity_stream_request.rb create mode 100644 generated/activitysmith_openapi/models/not_found_error.rb create mode 100644 generated/activitysmith_openapi/models/stream_content_state.rb diff --git a/generated/activitysmith_openapi.rb b/generated/activitysmith_openapi.rb index 79f7d55..1dc7bd9 100644 --- a/generated/activitysmith_openapi.rb +++ b/generated/activitysmith_openapi.rb @@ -17,6 +17,7 @@ require 'activitysmith_openapi/configuration' # Models +require 'activitysmith_openapi/models/activity_metric' require 'activitysmith_openapi/models/alert_payload' require 'activitysmith_openapi/models/bad_request_error' require 'activitysmith_openapi/models/channel_target' @@ -31,10 +32,15 @@ require 'activitysmith_openapi/models/live_activity_limit_error' require 'activitysmith_openapi/models/live_activity_start_request' require 'activitysmith_openapi/models/live_activity_start_response' +require 'activitysmith_openapi/models/live_activity_stream_delete_request' +require 'activitysmith_openapi/models/live_activity_stream_delete_response' +require 'activitysmith_openapi/models/live_activity_stream_put_response' +require 'activitysmith_openapi/models/live_activity_stream_request' require 'activitysmith_openapi/models/live_activity_update_request' require 'activitysmith_openapi/models/live_activity_update_response' require 'activitysmith_openapi/models/live_activity_webhook_method' require 'activitysmith_openapi/models/no_recipients_error' +require 'activitysmith_openapi/models/not_found_error' require 'activitysmith_openapi/models/push_notification_action' require 'activitysmith_openapi/models/push_notification_action_type' require 'activitysmith_openapi/models/push_notification_request' @@ -42,6 +48,7 @@ require 'activitysmith_openapi/models/push_notification_webhook_method' require 'activitysmith_openapi/models/rate_limit_error' require 'activitysmith_openapi/models/send_push_notification429_response' +require 'activitysmith_openapi/models/stream_content_state' # APIs require 'activitysmith_openapi/api/live_activities_api' diff --git a/generated/activitysmith_openapi/api/live_activities_api.rb b/generated/activitysmith_openapi/api/live_activities_api.rb index 214cf1f..7246038 100644 --- a/generated/activitysmith_openapi/api/live_activities_api.rb +++ b/generated/activitysmith_openapi/api/live_activities_api.rb @@ -20,7 +20,7 @@ def initialize(api_client = ApiClient.default) @api_client = api_client end # End a Live Activity - # Ends a Live Activity and archives its lifecycle. For segmented_progress activities, you can send the latest number_of_steps here if the workflow changed after start. + # Ends a Live Activity and archives its lifecycle. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, you can send the latest number_of_steps here if the workflow changed after start. # @param live_activity_end_request [LiveActivityEndRequest] # @param [Hash] opts the optional parameters # @return [LiveActivityEndResponse] @@ -30,7 +30,7 @@ def end_live_activity(live_activity_end_request, opts = {}) end # End a Live Activity - # Ends a Live Activity and archives its lifecycle. For segmented_progress activities, you can send the latest number_of_steps here if the workflow changed after start. + # Ends a Live Activity and archives its lifecycle. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, you can send the latest number_of_steps here if the workflow changed after start. # @param live_activity_end_request [LiveActivityEndRequest] # @param [Hash] opts the optional parameters # @return [Array<(LiveActivityEndResponse, Integer, Hash)>] LiveActivityEndResponse data, response status code and response headers @@ -87,8 +87,170 @@ def end_live_activity_with_http_info(live_activity_end_request, opts = {}) return data, status_code, headers end + # End a stream + # Use this endpoint when the process you are tracking is finished and you no longer want the Live Activity on your devices. ActivitySmith ends the current Live Activity for this stream and dismisses it from devices. If you need direct lifecycle control, use /live-activity/start, /live-activity/update, and /live-activity/end instead. + # @param stream_key [String] Stable identifier for one ongoing thing. Allowed characters: letters, numbers, underscores, and hyphens. + # @param [Hash] opts the optional parameters + # @option opts [LiveActivityStreamDeleteRequest] :live_activity_stream_delete_request + # @return [LiveActivityStreamDeleteResponse] + def end_live_activity_stream(stream_key, opts = {}) + data, _status_code, _headers = end_live_activity_stream_with_http_info(stream_key, opts) + data + end + + # End a stream + # Use this endpoint when the process you are tracking is finished and you no longer want the Live Activity on your devices. ActivitySmith ends the current Live Activity for this stream and dismisses it from devices. If you need direct lifecycle control, use /live-activity/start, /live-activity/update, and /live-activity/end instead. + # @param stream_key [String] Stable identifier for one ongoing thing. Allowed characters: letters, numbers, underscores, and hyphens. + # @param [Hash] opts the optional parameters + # @option opts [LiveActivityStreamDeleteRequest] :live_activity_stream_delete_request + # @return [Array<(LiveActivityStreamDeleteResponse, Integer, Hash)>] LiveActivityStreamDeleteResponse data, response status code and response headers + def end_live_activity_stream_with_http_info(stream_key, opts = {}) + if @api_client.config.debugging + @api_client.config.logger.debug 'Calling API: LiveActivitiesApi.end_live_activity_stream ...' + end + # verify the required parameter 'stream_key' is set + if @api_client.config.client_side_validation && stream_key.nil? + fail ArgumentError, "Missing the required parameter 'stream_key' when calling LiveActivitiesApi.end_live_activity_stream" + end + if @api_client.config.client_side_validation && stream_key.to_s.length > 255 + fail ArgumentError, 'invalid value for "stream_key" when calling LiveActivitiesApi.end_live_activity_stream, the character length must be smaller than or equal to 255.' + end + + pattern = Regexp.new(/^[A-Za-z0-9_-]+$/) + if @api_client.config.client_side_validation && stream_key !~ pattern + fail ArgumentError, "invalid value for 'stream_key' when calling LiveActivitiesApi.end_live_activity_stream, must conform to the pattern #{pattern}." + end + + # resource path + local_var_path = '/live-activity/stream/{stream_key}'.sub('{' + 'stream_key' + '}', CGI.escape(stream_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[:'live_activity_stream_delete_request']) + + # return_type + return_type = opts[:debug_return_type] || 'LiveActivityStreamDeleteResponse' + + # auth_names + auth_names = opts[:debug_auth_names] || ['apiKeyAuth'] + + new_options = opts.merge( + :operation => :"LiveActivitiesApi.end_live_activity_stream", + :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(:DELETE, local_var_path, new_options) + if @api_client.config.debugging + @api_client.config.logger.debug "API called: LiveActivitiesApi#end_live_activity_stream\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + end + return data, status_code, headers + end + + # Send a stream update + # Use this endpoint when you want the easiest, stateless way to trigger Live Activities. You do not need to store activity_id or manage the Live Activity lifecycle yourself. Send the latest state for a stable stream_key and ActivitySmith will handle the rest for you: if there is no Live Activity yet, it starts one; if there is already one for this stream, it updates it. If you need direct lifecycle control, use /live-activity/start, /live-activity/update, and /live-activity/end instead. + # @param stream_key [String] Stable identifier for one ongoing thing. Allowed characters: letters, numbers, underscores, and hyphens. + # @param live_activity_stream_request [LiveActivityStreamRequest] + # @param [Hash] opts the optional parameters + # @return [LiveActivityStreamPutResponse] + def reconcile_live_activity_stream(stream_key, live_activity_stream_request, opts = {}) + data, _status_code, _headers = reconcile_live_activity_stream_with_http_info(stream_key, live_activity_stream_request, opts) + data + end + + # Send a stream update + # Use this endpoint when you want the easiest, stateless way to trigger Live Activities. You do not need to store activity_id or manage the Live Activity lifecycle yourself. Send the latest state for a stable stream_key and ActivitySmith will handle the rest for you: if there is no Live Activity yet, it starts one; if there is already one for this stream, it updates it. If you need direct lifecycle control, use /live-activity/start, /live-activity/update, and /live-activity/end instead. + # @param stream_key [String] Stable identifier for one ongoing thing. Allowed characters: letters, numbers, underscores, and hyphens. + # @param live_activity_stream_request [LiveActivityStreamRequest] + # @param [Hash] opts the optional parameters + # @return [Array<(LiveActivityStreamPutResponse, Integer, Hash)>] LiveActivityStreamPutResponse data, response status code and response headers + def reconcile_live_activity_stream_with_http_info(stream_key, live_activity_stream_request, opts = {}) + if @api_client.config.debugging + @api_client.config.logger.debug 'Calling API: LiveActivitiesApi.reconcile_live_activity_stream ...' + end + # verify the required parameter 'stream_key' is set + if @api_client.config.client_side_validation && stream_key.nil? + fail ArgumentError, "Missing the required parameter 'stream_key' when calling LiveActivitiesApi.reconcile_live_activity_stream" + end + if @api_client.config.client_side_validation && stream_key.to_s.length > 255 + fail ArgumentError, 'invalid value for "stream_key" when calling LiveActivitiesApi.reconcile_live_activity_stream, the character length must be smaller than or equal to 255.' + end + + pattern = Regexp.new(/^[A-Za-z0-9_-]+$/) + if @api_client.config.client_side_validation && stream_key !~ pattern + fail ArgumentError, "invalid value for 'stream_key' when calling LiveActivitiesApi.reconcile_live_activity_stream, must conform to the pattern #{pattern}." + end + + # verify the required parameter 'live_activity_stream_request' is set + if @api_client.config.client_side_validation && live_activity_stream_request.nil? + fail ArgumentError, "Missing the required parameter 'live_activity_stream_request' when calling LiveActivitiesApi.reconcile_live_activity_stream" + end + # resource path + local_var_path = '/live-activity/stream/{stream_key}'.sub('{' + 'stream_key' + '}', CGI.escape(stream_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(live_activity_stream_request) + + # return_type + return_type = opts[:debug_return_type] || 'LiveActivityStreamPutResponse' + + # auth_names + auth_names = opts[:debug_auth_names] || ['apiKeyAuth'] + + new_options = opts.merge( + :operation => :"LiveActivitiesApi.reconcile_live_activity_stream", + :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: LiveActivitiesApi#reconcile_live_activity_stream\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + end + return data, status_code, headers + end + # Start a Live Activity - # Starts a Live Activity on devices matched by API key scope and optional target channels. For segmented_progress activities, number_of_steps can be changed later during update or end calls if the workflow changes. + # Starts a Live Activity on devices matched by API key scope and optional target channels. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, number_of_steps can be changed later during update or end calls if the workflow changes. # @param live_activity_start_request [LiveActivityStartRequest] # @param [Hash] opts the optional parameters # @return [LiveActivityStartResponse] @@ -98,7 +260,7 @@ def start_live_activity(live_activity_start_request, opts = {}) end # Start a Live Activity - # Starts a Live Activity on devices matched by API key scope and optional target channels. For segmented_progress activities, number_of_steps can be changed later during update or end calls if the workflow changes. + # Starts a Live Activity on devices matched by API key scope and optional target channels. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, number_of_steps can be changed later during update or end calls if the workflow changes. # @param live_activity_start_request [LiveActivityStartRequest] # @param [Hash] opts the optional parameters # @return [Array<(LiveActivityStartResponse, Integer, Hash)>] LiveActivityStartResponse data, response status code and response headers @@ -156,7 +318,7 @@ def start_live_activity_with_http_info(live_activity_start_request, opts = {}) end # Update a Live Activity - # Updates an existing Live Activity. If the per-activity token is not registered yet, the update is queued. For segmented_progress activities, you can increase or decrease number_of_steps here as the workflow changes. + # Updates an existing Live Activity. If the per-activity token is not registered yet, the update is queued. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, you can increase or decrease number_of_steps here as the workflow changes. # @param live_activity_update_request [LiveActivityUpdateRequest] # @param [Hash] opts the optional parameters # @return [LiveActivityUpdateResponse] @@ -166,7 +328,7 @@ def update_live_activity(live_activity_update_request, opts = {}) end # Update a Live Activity - # Updates an existing Live Activity. If the per-activity token is not registered yet, the update is queued. For segmented_progress activities, you can increase or decrease number_of_steps here as the workflow changes. + # Updates an existing Live Activity. If the per-activity token is not registered yet, the update is queued. Supports segmented_progress, progress, metrics, and the legacy counter/timer/countdown step-based activity types. For segmented_progress activities, you can increase or decrease number_of_steps here as the workflow changes. # @param live_activity_update_request [LiveActivityUpdateRequest] # @param [Hash] opts the optional parameters # @return [Array<(LiveActivityUpdateResponse, Integer, Hash)>] LiveActivityUpdateResponse data, response status code and response headers diff --git a/generated/activitysmith_openapi/models/activity_metric.rb b/generated/activitysmith_openapi/models/activity_metric.rb new file mode 100644 index 0000000..ba725db --- /dev/null +++ b/generated/activitysmith_openapi/models/activity_metric.rb @@ -0,0 +1,293 @@ +=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 ActivityMetric + attr_accessor :label + + attr_accessor :value + + attr_accessor :unit + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'label' => :'label', + :'value' => :'value', + :'unit' => :'unit' + } + 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', + :'value' => :'Float', + :'unit' => :'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::ActivityMetric` 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::ActivityMetric`. 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'] + else + self.label = nil + end + + if attributes.key?(:'value') + self.value = attributes[:'value'] + else + self.value = nil + end + + if attributes.key?(:'unit') + self.unit = attributes[:'unit'] + 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? + invalid_properties.push('invalid value for "label", label cannot be nil.') + end + + if @label.to_s.length < 1 + invalid_properties.push('invalid value for "label", the character length must be great than or equal to 1.') + end + + if @value.nil? + invalid_properties.push('invalid value for "value", value cannot be nil.') + end + + if @value > 100 + invalid_properties.push('invalid value for "value", must be smaller than or equal to 100.') + end + + if @value < 0 + invalid_properties.push('invalid value for "value", must be greater than or equal to 0.') + 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? + return false if @label.to_s.length < 1 + return false if @value.nil? + return false if @value > 100 + return false if @value < 0 + 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 < 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 with validation + # @param [Object] value Value to be assigned + def value=(value) + if value.nil? + fail ArgumentError, 'value cannot be nil' + end + + if value > 100 + fail ArgumentError, 'invalid value for "value", must be smaller than or equal to 100.' + end + + if value < 0 + fail ArgumentError, 'invalid value for "value", must be greater than or equal to 0.' + end + + @value = value + 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 && + value == o.value && + unit == o.unit + 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, value, unit].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/content_state_end.rb b/generated/activitysmith_openapi/models/content_state_end.rb index 23de9dc..078e6dd 100644 --- a/generated/activitysmith_openapi/models/content_state_end.rb +++ b/generated/activitysmith_openapi/models/content_state_end.rb @@ -14,7 +14,7 @@ require 'time' module OpenapiClient - # End payload requires title. For segmented_progress include current_step and optionally number_of_steps. For progress include percentage or value with upper_limit. Type is optional when ending an existing activity. You can send an updated number_of_steps here if the workflow changed after start. + # End payload requires title. For segmented_progress include current_step and optionally number_of_steps. For progress include percentage or value with upper_limit. For metrics include a non-empty metrics array. Legacy counter/timer/countdown types also use current_step and number_of_steps. Type is optional when ending an existing activity. You can send an updated number_of_steps here if the workflow changed after start. class ContentStateEnd attr_accessor :title @@ -35,6 +35,9 @@ class ContentStateEnd # Maximum progress value. Use with value for type=progress. attr_accessor :upper_limit + # Use for type=metrics. + attr_accessor :metrics + # Optional. When omitted, the API uses the existing Live Activity type. attr_accessor :type @@ -44,6 +47,9 @@ class ContentStateEnd # Optional. Overrides color for the current step. Only applies to type=segmented_progress. attr_accessor :step_color + # Optional. Colors for completed steps. When used with segmented_progress, the array length should match current_step. + attr_accessor :step_colors + # Optional. Minutes before the ended Live Activity is dismissed. Default 3. Set 0 for immediate dismissal. iOS will dismiss ended Live Activities after ~4 hours max. attr_accessor :auto_dismiss_minutes @@ -79,9 +85,11 @@ def self.attribute_map :'percentage' => :'percentage', :'value' => :'value', :'upper_limit' => :'upper_limit', + :'metrics' => :'metrics', :'type' => :'type', :'color' => :'color', :'step_color' => :'step_color', + :'step_colors' => :'step_colors', :'auto_dismiss_minutes' => :'auto_dismiss_minutes' } end @@ -101,9 +109,11 @@ def self.openapi_types :'percentage' => :'Float', :'value' => :'Float', :'upper_limit' => :'Float', + :'metrics' => :'Array', :'type' => :'String', :'color' => :'String', :'step_color' => :'String', + :'step_colors' => :'Array', :'auto_dismiss_minutes' => :'Integer' } end @@ -159,6 +169,12 @@ def initialize(attributes = {}) self.upper_limit = attributes[:'upper_limit'] end + if attributes.key?(:'metrics') + if (value = attributes[:'metrics']).is_a?(Array) + self.metrics = value + end + end + if attributes.key?(:'type') self.type = attributes[:'type'] end @@ -173,6 +189,12 @@ def initialize(attributes = {}) self.step_color = attributes[:'step_color'] end + if attributes.key?(:'step_colors') + if (value = attributes[:'step_colors']).is_a?(Array) + self.step_colors = value + end + end + if attributes.key?(:'auto_dismiss_minutes') self.auto_dismiss_minutes = attributes[:'auto_dismiss_minutes'] else @@ -205,6 +227,10 @@ def list_invalid_properties invalid_properties.push('invalid value for "percentage", must be greater than or equal to 0.') end + if !@metrics.nil? && @metrics.length < 1 + invalid_properties.push('invalid value for "metrics", number of items must be greater than or equal to 1.') + end + if !@auto_dismiss_minutes.nil? && @auto_dismiss_minutes < 0 invalid_properties.push('invalid value for "auto_dismiss_minutes", must be greater than or equal to 0.') end @@ -221,7 +247,8 @@ def valid? return false if !@current_step.nil? && @current_step < 1 return false if !@percentage.nil? && @percentage > 100 return false if !@percentage.nil? && @percentage < 0 - type_validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress"]) + return false if !@metrics.nil? && @metrics.length < 1 + type_validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress", "metrics", "counter", "timer", "countdown"]) return false unless type_validator.valid?(@type) color_validator = EnumAttributeValidator.new('String', ["lime", "green", "cyan", "blue", "purple", "magenta", "red", "orange", "yellow"]) return false unless color_validator.valid?(@color) @@ -277,10 +304,24 @@ def percentage=(percentage) @percentage = percentage end + # Custom attribute writer method with validation + # @param [Object] metrics Value to be assigned + def metrics=(metrics) + if metrics.nil? + fail ArgumentError, 'metrics cannot be nil' + end + + if metrics.length < 1 + fail ArgumentError, 'invalid value for "metrics", number of items must be greater than or equal to 1.' + end + + @metrics = metrics + end + # Custom attribute writer method checking allowed values (enum). # @param [Object] type Object to be assigned def type=(type) - validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress"]) + validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress", "metrics", "counter", "timer", "countdown"]) unless validator.valid?(type) fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}." end @@ -333,9 +374,11 @@ def ==(o) percentage == o.percentage && value == o.value && upper_limit == o.upper_limit && + metrics == o.metrics && type == o.type && color == o.color && step_color == o.step_color && + step_colors == o.step_colors && auto_dismiss_minutes == o.auto_dismiss_minutes end @@ -348,7 +391,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [title, subtitle, number_of_steps, current_step, percentage, value, upper_limit, type, color, step_color, auto_dismiss_minutes].hash + [title, subtitle, number_of_steps, current_step, percentage, value, upper_limit, metrics, type, color, step_color, step_colors, auto_dismiss_minutes].hash end # Builds the object from hash diff --git a/generated/activitysmith_openapi/models/content_state_start.rb b/generated/activitysmith_openapi/models/content_state_start.rb index 88b3daf..f459d42 100644 --- a/generated/activitysmith_openapi/models/content_state_start.rb +++ b/generated/activitysmith_openapi/models/content_state_start.rb @@ -14,7 +14,7 @@ require 'time' module OpenapiClient - # Start payload requires title and type. For segmented_progress include number_of_steps and current_step. For progress include percentage or value with upper_limit. For segmented_progress, number_of_steps is not locked and can be changed in later update or end calls. + # Start payload requires title and type. For segmented_progress include number_of_steps and current_step. For progress include percentage or value with upper_limit. For metrics include a non-empty metrics array. Legacy counter/timer/countdown types also use current_step and number_of_steps. For segmented_progress, number_of_steps is not locked and can be changed in later update or end calls. class ContentStateStart attr_accessor :title @@ -35,6 +35,9 @@ class ContentStateStart # Maximum progress value. Use with value for type=progress. attr_accessor :upper_limit + # Use for type=metrics. + attr_accessor :metrics + attr_accessor :type # Optional. Accent color for the Live Activity. Defaults to blue. @@ -43,6 +46,9 @@ class ContentStateStart # Optional. Overrides color for the current step. Only applies to type=segmented_progress. attr_accessor :step_color + # Optional. Colors for completed steps. When used with segmented_progress, the array length should match current_step. + attr_accessor :step_colors + class EnumAttributeValidator attr_reader :datatype attr_reader :allowable_values @@ -75,9 +81,11 @@ def self.attribute_map :'percentage' => :'percentage', :'value' => :'value', :'upper_limit' => :'upper_limit', + :'metrics' => :'metrics', :'type' => :'type', :'color' => :'color', - :'step_color' => :'step_color' + :'step_color' => :'step_color', + :'step_colors' => :'step_colors' } end @@ -96,9 +104,11 @@ def self.openapi_types :'percentage' => :'Float', :'value' => :'Float', :'upper_limit' => :'Float', + :'metrics' => :'Array', :'type' => :'String', :'color' => :'String', - :'step_color' => :'String' + :'step_color' => :'String', + :'step_colors' => :'Array' } end @@ -153,6 +163,12 @@ def initialize(attributes = {}) self.upper_limit = attributes[:'upper_limit'] end + if attributes.key?(:'metrics') + if (value = attributes[:'metrics']).is_a?(Array) + self.metrics = value + end + end + if attributes.key?(:'type') self.type = attributes[:'type'] else @@ -168,6 +184,12 @@ def initialize(attributes = {}) if attributes.key?(:'step_color') self.step_color = attributes[:'step_color'] end + + if attributes.key?(:'step_colors') + if (value = attributes[:'step_colors']).is_a?(Array) + self.step_colors = value + end + end end # Show invalid properties with the reasons. Usually used together with valid? @@ -195,6 +217,10 @@ def list_invalid_properties invalid_properties.push('invalid value for "percentage", must be greater than or equal to 0.') end + if !@metrics.nil? && @metrics.length < 1 + invalid_properties.push('invalid value for "metrics", number of items must be greater than or equal to 1.') + end + if @type.nil? invalid_properties.push('invalid value for "type", type cannot be nil.') end @@ -211,8 +237,9 @@ def valid? return false if !@current_step.nil? && @current_step < 1 return false if !@percentage.nil? && @percentage > 100 return false if !@percentage.nil? && @percentage < 0 + return false if !@metrics.nil? && @metrics.length < 1 return false if @type.nil? - type_validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress"]) + type_validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress", "metrics", "counter", "timer", "countdown"]) return false unless type_validator.valid?(@type) color_validator = EnumAttributeValidator.new('String', ["lime", "green", "cyan", "blue", "purple", "magenta", "red", "orange", "yellow"]) return false unless color_validator.valid?(@color) @@ -267,10 +294,24 @@ def percentage=(percentage) @percentage = percentage end + # Custom attribute writer method with validation + # @param [Object] metrics Value to be assigned + def metrics=(metrics) + if metrics.nil? + fail ArgumentError, 'metrics cannot be nil' + end + + if metrics.length < 1 + fail ArgumentError, 'invalid value for "metrics", number of items must be greater than or equal to 1.' + end + + @metrics = metrics + end + # Custom attribute writer method checking allowed values (enum). # @param [Object] type Object to be assigned def type=(type) - validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress"]) + validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress", "metrics", "counter", "timer", "countdown"]) unless validator.valid?(type) fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}." end @@ -309,9 +350,11 @@ def ==(o) percentage == o.percentage && value == o.value && upper_limit == o.upper_limit && + metrics == o.metrics && type == o.type && color == o.color && - step_color == o.step_color + step_color == o.step_color && + step_colors == o.step_colors end # @see the `==` method @@ -323,7 +366,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [title, subtitle, number_of_steps, current_step, percentage, value, upper_limit, type, color, step_color].hash + [title, subtitle, number_of_steps, current_step, percentage, value, upper_limit, metrics, type, color, step_color, step_colors].hash end # Builds the object from hash diff --git a/generated/activitysmith_openapi/models/content_state_update.rb b/generated/activitysmith_openapi/models/content_state_update.rb index 8c83307..1d5573f 100644 --- a/generated/activitysmith_openapi/models/content_state_update.rb +++ b/generated/activitysmith_openapi/models/content_state_update.rb @@ -14,7 +14,7 @@ require 'time' module OpenapiClient - # Update payload requires title. For segmented_progress include current_step and optionally number_of_steps. For progress include percentage or value with upper_limit. Type is optional when updating an existing activity. You can increase or decrease number_of_steps during updates. + # Update payload requires title. For segmented_progress include current_step and optionally number_of_steps. For progress include percentage or value with upper_limit. For metrics include a non-empty metrics array. Legacy counter/timer/countdown types also use current_step and number_of_steps. Type is optional when updating an existing activity. You can increase or decrease number_of_steps during updates. class ContentStateUpdate attr_accessor :title @@ -35,6 +35,9 @@ class ContentStateUpdate # Maximum progress value. Use with value for type=progress. attr_accessor :upper_limit + # Use for type=metrics. + attr_accessor :metrics + # Optional. When omitted, the API uses the existing Live Activity type. attr_accessor :type @@ -44,6 +47,9 @@ class ContentStateUpdate # Optional. Overrides color for the current step. Only applies to type=segmented_progress. attr_accessor :step_color + # Optional. Colors for completed steps. When used with segmented_progress, the array length should match current_step. + attr_accessor :step_colors + class EnumAttributeValidator attr_reader :datatype attr_reader :allowable_values @@ -76,9 +82,11 @@ def self.attribute_map :'percentage' => :'percentage', :'value' => :'value', :'upper_limit' => :'upper_limit', + :'metrics' => :'metrics', :'type' => :'type', :'color' => :'color', - :'step_color' => :'step_color' + :'step_color' => :'step_color', + :'step_colors' => :'step_colors' } end @@ -97,9 +105,11 @@ def self.openapi_types :'percentage' => :'Float', :'value' => :'Float', :'upper_limit' => :'Float', + :'metrics' => :'Array', :'type' => :'String', :'color' => :'String', - :'step_color' => :'String' + :'step_color' => :'String', + :'step_colors' => :'Array' } end @@ -154,6 +164,12 @@ def initialize(attributes = {}) self.upper_limit = attributes[:'upper_limit'] end + if attributes.key?(:'metrics') + if (value = attributes[:'metrics']).is_a?(Array) + self.metrics = value + end + end + if attributes.key?(:'type') self.type = attributes[:'type'] end @@ -167,6 +183,12 @@ def initialize(attributes = {}) if attributes.key?(:'step_color') self.step_color = attributes[:'step_color'] end + + if attributes.key?(:'step_colors') + if (value = attributes[:'step_colors']).is_a?(Array) + self.step_colors = value + end + end end # Show invalid properties with the reasons. Usually used together with valid? @@ -194,6 +216,10 @@ def list_invalid_properties invalid_properties.push('invalid value for "percentage", must be greater than or equal to 0.') end + if !@metrics.nil? && @metrics.length < 1 + invalid_properties.push('invalid value for "metrics", number of items must be greater than or equal to 1.') + end + invalid_properties end @@ -206,7 +232,8 @@ def valid? return false if !@current_step.nil? && @current_step < 1 return false if !@percentage.nil? && @percentage > 100 return false if !@percentage.nil? && @percentage < 0 - type_validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress"]) + return false if !@metrics.nil? && @metrics.length < 1 + type_validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress", "metrics", "counter", "timer", "countdown"]) return false unless type_validator.valid?(@type) color_validator = EnumAttributeValidator.new('String', ["lime", "green", "cyan", "blue", "purple", "magenta", "red", "orange", "yellow"]) return false unless color_validator.valid?(@color) @@ -261,10 +288,24 @@ def percentage=(percentage) @percentage = percentage end + # Custom attribute writer method with validation + # @param [Object] metrics Value to be assigned + def metrics=(metrics) + if metrics.nil? + fail ArgumentError, 'metrics cannot be nil' + end + + if metrics.length < 1 + fail ArgumentError, 'invalid value for "metrics", number of items must be greater than or equal to 1.' + end + + @metrics = metrics + end + # Custom attribute writer method checking allowed values (enum). # @param [Object] type Object to be assigned def type=(type) - validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress"]) + validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress", "metrics", "counter", "timer", "countdown"]) unless validator.valid?(type) fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}." end @@ -303,9 +344,11 @@ def ==(o) percentage == o.percentage && value == o.value && upper_limit == o.upper_limit && + metrics == o.metrics && type == o.type && color == o.color && - step_color == o.step_color + step_color == o.step_color && + step_colors == o.step_colors end # @see the `==` method @@ -317,7 +360,7 @@ def eql?(o) # Calculates hash code according to all attributes. # @return [Integer] Hash code def hash - [title, subtitle, number_of_steps, current_step, percentage, value, upper_limit, type, color, step_color].hash + [title, subtitle, number_of_steps, current_step, percentage, value, upper_limit, metrics, type, color, step_color, step_colors].hash end # Builds the object from hash diff --git a/generated/activitysmith_openapi/models/live_activity_stream_delete_request.rb b/generated/activitysmith_openapi/models/live_activity_stream_delete_request.rb new file mode 100644 index 0000000..5d8d4a3 --- /dev/null +++ b/generated/activitysmith_openapi/models/live_activity_stream_delete_request.rb @@ -0,0 +1,233 @@ +=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 + # Optional payload for ending a managed stream. When omitted, ActivitySmith ends the stream using the latest known state when possible. + class LiveActivityStreamDeleteRequest + attr_accessor :content_state + + attr_accessor :action + + attr_accessor :alert + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'content_state' => :'content_state', + :'action' => :'action', + :'alert' => :'alert' + } + 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 + { + :'content_state' => :'StreamContentState', + :'action' => :'LiveActivityAction', + :'alert' => :'AlertPayload' + } + 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::LiveActivityStreamDeleteRequest` 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::LiveActivityStreamDeleteRequest`. 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?(:'content_state') + self.content_state = attributes[:'content_state'] + end + + if attributes.key?(:'action') + self.action = attributes[:'action'] + end + + if attributes.key?(:'alert') + self.alert = attributes[:'alert'] + 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 + 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' + 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 && + content_state == o.content_state && + action == o.action && + alert == o.alert + 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 + [content_state, action, alert].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/live_activity_stream_delete_response.rb b/generated/activitysmith_openapi/models/live_activity_stream_delete_response.rb new file mode 100644 index 0000000..f21f246 --- /dev/null +++ b/generated/activitysmith_openapi/models/live_activity_stream_delete_response.rb @@ -0,0 +1,332 @@ +=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 + # Returned after a managed stream is ended and removed. + class LiveActivityStreamDeleteResponse + attr_accessor :success + + attr_accessor :operation + + attr_accessor :stream_key + + attr_accessor :activity_id + + attr_accessor :devices_queued + + attr_accessor :devices_notified + + attr_accessor :timestamp + + 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 + { + :'success' => :'success', + :'operation' => :'operation', + :'stream_key' => :'stream_key', + :'activity_id' => :'activity_id', + :'devices_queued' => :'devices_queued', + :'devices_notified' => :'devices_notified', + :'timestamp' => :'timestamp' + } + 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 + { + :'success' => :'Boolean', + :'operation' => :'String', + :'stream_key' => :'String', + :'activity_id' => :'String', + :'devices_queued' => :'Integer', + :'devices_notified' => :'Integer', + :'timestamp' => :'Time' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + :'activity_id', + ]) + 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::LiveActivityStreamDeleteResponse` 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::LiveActivityStreamDeleteResponse`. 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?(:'success') + self.success = attributes[:'success'] + else + self.success = nil + end + + if attributes.key?(:'operation') + self.operation = attributes[:'operation'] + else + self.operation = nil + end + + if attributes.key?(:'stream_key') + self.stream_key = attributes[:'stream_key'] + else + self.stream_key = nil + end + + if attributes.key?(:'activity_id') + self.activity_id = attributes[:'activity_id'] + end + + if attributes.key?(:'devices_queued') + self.devices_queued = attributes[:'devices_queued'] + end + + if attributes.key?(:'devices_notified') + self.devices_notified = attributes[:'devices_notified'] + end + + if attributes.key?(:'timestamp') + self.timestamp = attributes[:'timestamp'] + else + self.timestamp = 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 @success.nil? + invalid_properties.push('invalid value for "success", success cannot be nil.') + end + + if @operation.nil? + invalid_properties.push('invalid value for "operation", operation cannot be nil.') + end + + if @stream_key.nil? + invalid_properties.push('invalid value for "stream_key", stream_key cannot be nil.') + end + + if @timestamp.nil? + invalid_properties.push('invalid value for "timestamp", timestamp 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 @success.nil? + return false if @operation.nil? + operation_validator = EnumAttributeValidator.new('String', ["ended"]) + return false unless operation_validator.valid?(@operation) + return false if @stream_key.nil? + return false if @timestamp.nil? + true + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] operation Object to be assigned + def operation=(operation) + validator = EnumAttributeValidator.new('String', ["ended"]) + unless validator.valid?(operation) + fail ArgumentError, "invalid value for \"operation\", must be one of #{validator.allowable_values}." + end + @operation = operation + 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 && + success == o.success && + operation == o.operation && + stream_key == o.stream_key && + activity_id == o.activity_id && + devices_queued == o.devices_queued && + devices_notified == o.devices_notified && + timestamp == o.timestamp + 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 + [success, operation, stream_key, activity_id, devices_queued, devices_notified, timestamp].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/live_activity_stream_put_response.rb b/generated/activitysmith_openapi/models/live_activity_stream_put_response.rb new file mode 100644 index 0000000..f195c0d --- /dev/null +++ b/generated/activitysmith_openapi/models/live_activity_stream_put_response.rb @@ -0,0 +1,361 @@ +=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 + # Returned after a managed stream request is reconciled. + class LiveActivityStreamPutResponse + attr_accessor :success + + attr_accessor :operation + + attr_accessor :stream_key + + attr_accessor :activity_id + + attr_accessor :previous_activity_id + + attr_accessor :devices_notified + + attr_accessor :devices_queued + + attr_accessor :users_notified + + attr_accessor :effective_channel_slugs + + attr_accessor :timestamp + + 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 + { + :'success' => :'success', + :'operation' => :'operation', + :'stream_key' => :'stream_key', + :'activity_id' => :'activity_id', + :'previous_activity_id' => :'previous_activity_id', + :'devices_notified' => :'devices_notified', + :'devices_queued' => :'devices_queued', + :'users_notified' => :'users_notified', + :'effective_channel_slugs' => :'effective_channel_slugs', + :'timestamp' => :'timestamp' + } + 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 + { + :'success' => :'Boolean', + :'operation' => :'String', + :'stream_key' => :'String', + :'activity_id' => :'String', + :'previous_activity_id' => :'String', + :'devices_notified' => :'Integer', + :'devices_queued' => :'Integer', + :'users_notified' => :'Integer', + :'effective_channel_slugs' => :'Array', + :'timestamp' => :'Time' + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new([ + :'activity_id', + ]) + 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::LiveActivityStreamPutResponse` 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::LiveActivityStreamPutResponse`. 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?(:'success') + self.success = attributes[:'success'] + else + self.success = nil + end + + if attributes.key?(:'operation') + self.operation = attributes[:'operation'] + else + self.operation = nil + end + + if attributes.key?(:'stream_key') + self.stream_key = attributes[:'stream_key'] + else + self.stream_key = nil + end + + if attributes.key?(:'activity_id') + self.activity_id = attributes[:'activity_id'] + end + + if attributes.key?(:'previous_activity_id') + self.previous_activity_id = attributes[:'previous_activity_id'] + end + + if attributes.key?(:'devices_notified') + self.devices_notified = attributes[:'devices_notified'] + end + + if attributes.key?(:'devices_queued') + self.devices_queued = attributes[:'devices_queued'] + end + + if attributes.key?(:'users_notified') + self.users_notified = attributes[:'users_notified'] + end + + if attributes.key?(:'effective_channel_slugs') + if (value = attributes[:'effective_channel_slugs']).is_a?(Array) + self.effective_channel_slugs = value + end + end + + if attributes.key?(:'timestamp') + self.timestamp = attributes[:'timestamp'] + else + self.timestamp = 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 @success.nil? + invalid_properties.push('invalid value for "success", success cannot be nil.') + end + + if @operation.nil? + invalid_properties.push('invalid value for "operation", operation cannot be nil.') + end + + if @stream_key.nil? + invalid_properties.push('invalid value for "stream_key", stream_key cannot be nil.') + end + + if @timestamp.nil? + invalid_properties.push('invalid value for "timestamp", timestamp 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 @success.nil? + return false if @operation.nil? + operation_validator = EnumAttributeValidator.new('String', ["started", "updated", "rotated", "noop", "paused"]) + return false unless operation_validator.valid?(@operation) + return false if @stream_key.nil? + return false if @timestamp.nil? + true + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] operation Object to be assigned + def operation=(operation) + validator = EnumAttributeValidator.new('String', ["started", "updated", "rotated", "noop", "paused"]) + unless validator.valid?(operation) + fail ArgumentError, "invalid value for \"operation\", must be one of #{validator.allowable_values}." + end + @operation = operation + 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 && + success == o.success && + operation == o.operation && + stream_key == o.stream_key && + activity_id == o.activity_id && + previous_activity_id == o.previous_activity_id && + devices_notified == o.devices_notified && + devices_queued == o.devices_queued && + users_notified == o.users_notified && + effective_channel_slugs == o.effective_channel_slugs && + timestamp == o.timestamp + 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 + [success, operation, stream_key, activity_id, previous_activity_id, devices_notified, devices_queued, users_notified, effective_channel_slugs, timestamp].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/live_activity_stream_request.rb b/generated/activitysmith_openapi/models/live_activity_stream_request.rb new file mode 100644 index 0000000..5aec908 --- /dev/null +++ b/generated/activitysmith_openapi/models/live_activity_stream_request.rb @@ -0,0 +1,280 @@ +=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 + # Send the latest state for a managed Live Activity stream. channels is the streamlined form for stream targeting. target.channels is also accepted for compatibility. If both are provided, they must match. + class LiveActivityStreamRequest + attr_accessor :content_state + + attr_accessor :action + + attr_accessor :alert + + # Channel slugs. When omitted, API key scope determines recipients. + attr_accessor :channels + + attr_accessor :target + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'content_state' => :'content_state', + :'action' => :'action', + :'alert' => :'alert', + :'channels' => :'channels', + :'target' => :'target' + } + 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 + { + :'content_state' => :'StreamContentState', + :'action' => :'LiveActivityAction', + :'alert' => :'AlertPayload', + :'channels' => :'Array', + :'target' => :'ChannelTarget' + } + 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::LiveActivityStreamRequest` 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::LiveActivityStreamRequest`. 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?(:'content_state') + self.content_state = attributes[:'content_state'] + else + self.content_state = nil + end + + if attributes.key?(:'action') + self.action = attributes[:'action'] + end + + if attributes.key?(:'alert') + self.alert = attributes[:'alert'] + end + + if attributes.key?(:'channels') + if (value = attributes[:'channels']).is_a?(Array) + self.channels = value + end + end + + if attributes.key?(:'target') + self.target = attributes[:'target'] + 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 @content_state.nil? + invalid_properties.push('invalid value for "content_state", content_state cannot be nil.') + end + + if !@channels.nil? && @channels.length < 1 + invalid_properties.push('invalid value for "channels", number of items must be greater than or equal to 1.') + 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 @content_state.nil? + return false if !@channels.nil? && @channels.length < 1 + true + end + + # Custom attribute writer method with validation + # @param [Object] channels Value to be assigned + def channels=(channels) + if channels.nil? + fail ArgumentError, 'channels cannot be nil' + end + + if channels.length < 1 + fail ArgumentError, 'invalid value for "channels", number of items must be greater than or equal to 1.' + end + + @channels = channels + 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 && + content_state == o.content_state && + action == o.action && + alert == o.alert && + channels == o.channels && + target == o.target + 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 + [content_state, action, alert, channels, target].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/not_found_error.rb b/generated/activitysmith_openapi/models/not_found_error.rb new file mode 100644 index 0000000..12dddb2 --- /dev/null +++ b/generated/activitysmith_openapi/models/not_found_error.rb @@ -0,0 +1,237 @@ +=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 NotFoundError + attr_accessor :error + + attr_accessor :message + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :'error' => :'error', + :'message' => :'message' + } + 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 + { + :'error' => :'String', + :'message' => :'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::NotFoundError` 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::NotFoundError`. 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?(:'error') + self.error = attributes[:'error'] + else + self.error = nil + end + + if attributes.key?(:'message') + self.message = attributes[:'message'] + else + self.message = 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 @error.nil? + invalid_properties.push('invalid value for "error", error cannot be nil.') + end + + if @message.nil? + invalid_properties.push('invalid value for "message", message 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 @error.nil? + return false if @message.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 && + error == o.error && + message == o.message + 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 + [error, message].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/stream_content_state.rb b/generated/activitysmith_openapi/models/stream_content_state.rb new file mode 100644 index 0000000..b683f44 --- /dev/null +++ b/generated/activitysmith_openapi/models/stream_content_state.rb @@ -0,0 +1,538 @@ +=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 + # 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. + class StreamContentState + attr_accessor :title + + attr_accessor :subtitle + + # Use for segmented_progress, counter, timer, and countdown. + attr_accessor :number_of_steps + + # Use for segmented_progress, counter, timer, and countdown. + attr_accessor :current_step + + # Use for progress. Takes precedence over value/upper_limit if both are provided. + attr_accessor :percentage + + # Current progress value. Use with upper_limit for progress. + attr_accessor :value + + # Maximum progress value. Use with value for progress. + attr_accessor :upper_limit + + # Required on the first PUT or whenever the stream cannot infer the current activity type. + attr_accessor :type + + # Optional. Accent color for the Live Activity. Defaults to blue. + attr_accessor :color + + # Optional. Overrides color for the current step. Only applies to segmented_progress. + attr_accessor :step_color + + # Optional. Colors for completed steps. When used with segmented_progress, the array length should match current_step. + attr_accessor :step_colors + + # Use for metrics activities. + attr_accessor :metrics + + # Optional. Seconds before the ended Live Activity is dismissed. + attr_accessor :auto_dismiss_seconds + + # Optional. Minutes before the ended Live Activity is dismissed. + attr_accessor :auto_dismiss_minutes + + 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 + { + :'title' => :'title', + :'subtitle' => :'subtitle', + :'number_of_steps' => :'number_of_steps', + :'current_step' => :'current_step', + :'percentage' => :'percentage', + :'value' => :'value', + :'upper_limit' => :'upper_limit', + :'type' => :'type', + :'color' => :'color', + :'step_color' => :'step_color', + :'step_colors' => :'step_colors', + :'metrics' => :'metrics', + :'auto_dismiss_seconds' => :'auto_dismiss_seconds', + :'auto_dismiss_minutes' => :'auto_dismiss_minutes' + } + 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 + { + :'title' => :'String', + :'subtitle' => :'String', + :'number_of_steps' => :'Integer', + :'current_step' => :'Integer', + :'percentage' => :'Float', + :'value' => :'Float', + :'upper_limit' => :'Float', + :'type' => :'String', + :'color' => :'String', + :'step_color' => :'String', + :'step_colors' => :'Array', + :'metrics' => :'Array', + :'auto_dismiss_seconds' => :'Integer', + :'auto_dismiss_minutes' => :'Integer' + } + 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::StreamContentState` 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::StreamContentState`. 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?(:'title') + self.title = attributes[:'title'] + else + self.title = nil + end + + if attributes.key?(:'subtitle') + self.subtitle = attributes[:'subtitle'] + end + + if attributes.key?(:'number_of_steps') + self.number_of_steps = attributes[:'number_of_steps'] + end + + if attributes.key?(:'current_step') + self.current_step = attributes[:'current_step'] + end + + if attributes.key?(:'percentage') + self.percentage = attributes[:'percentage'] + end + + if attributes.key?(:'value') + self.value = attributes[:'value'] + end + + if attributes.key?(:'upper_limit') + self.upper_limit = attributes[:'upper_limit'] + end + + if attributes.key?(:'type') + self.type = attributes[:'type'] + end + + if attributes.key?(:'color') + self.color = attributes[:'color'] + else + self.color = 'blue' + end + + if attributes.key?(:'step_color') + self.step_color = attributes[:'step_color'] + end + + if attributes.key?(:'step_colors') + if (value = attributes[:'step_colors']).is_a?(Array) + self.step_colors = value + end + end + + if attributes.key?(:'metrics') + if (value = attributes[:'metrics']).is_a?(Array) + self.metrics = value + end + end + + if attributes.key?(:'auto_dismiss_seconds') + self.auto_dismiss_seconds = attributes[:'auto_dismiss_seconds'] + end + + if attributes.key?(:'auto_dismiss_minutes') + self.auto_dismiss_minutes = attributes[:'auto_dismiss_minutes'] + 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 @title.nil? + invalid_properties.push('invalid value for "title", title cannot be nil.') + end + + if !@number_of_steps.nil? && @number_of_steps < 1 + invalid_properties.push('invalid value for "number_of_steps", must be greater than or equal to 1.') + end + + if !@current_step.nil? && @current_step < 1 + invalid_properties.push('invalid value for "current_step", must be greater than or equal to 1.') + end + + if !@percentage.nil? && @percentage > 100 + invalid_properties.push('invalid value for "percentage", must be smaller than or equal to 100.') + end + + if !@percentage.nil? && @percentage < 0 + invalid_properties.push('invalid value for "percentage", must be greater than or equal to 0.') + end + + if !@metrics.nil? && @metrics.length < 1 + invalid_properties.push('invalid value for "metrics", number of items must be greater than or equal to 1.') + end + + if !@auto_dismiss_seconds.nil? && @auto_dismiss_seconds < 0 + invalid_properties.push('invalid value for "auto_dismiss_seconds", must be greater than or equal to 0.') + end + + if !@auto_dismiss_minutes.nil? && @auto_dismiss_minutes < 0 + invalid_properties.push('invalid value for "auto_dismiss_minutes", must be greater than or equal to 0.') + 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 @title.nil? + return false if !@number_of_steps.nil? && @number_of_steps < 1 + return false if !@current_step.nil? && @current_step < 1 + return false if !@percentage.nil? && @percentage > 100 + return false if !@percentage.nil? && @percentage < 0 + type_validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress", "metrics", "counter", "timer", "countdown"]) + return false unless type_validator.valid?(@type) + color_validator = EnumAttributeValidator.new('String', ["lime", "green", "cyan", "blue", "purple", "magenta", "red", "orange", "yellow"]) + return false unless color_validator.valid?(@color) + step_color_validator = EnumAttributeValidator.new('String', ["lime", "green", "cyan", "blue", "purple", "magenta", "red", "orange", "yellow"]) + return false unless step_color_validator.valid?(@step_color) + return false if !@metrics.nil? && @metrics.length < 1 + return false if !@auto_dismiss_seconds.nil? && @auto_dismiss_seconds < 0 + return false if !@auto_dismiss_minutes.nil? && @auto_dismiss_minutes < 0 + true + end + + # Custom attribute writer method with validation + # @param [Object] number_of_steps Value to be assigned + def number_of_steps=(number_of_steps) + if number_of_steps.nil? + fail ArgumentError, 'number_of_steps cannot be nil' + end + + if number_of_steps < 1 + fail ArgumentError, 'invalid value for "number_of_steps", must be greater than or equal to 1.' + end + + @number_of_steps = number_of_steps + end + + # Custom attribute writer method with validation + # @param [Object] current_step Value to be assigned + def current_step=(current_step) + if current_step.nil? + fail ArgumentError, 'current_step cannot be nil' + end + + if current_step < 1 + fail ArgumentError, 'invalid value for "current_step", must be greater than or equal to 1.' + end + + @current_step = current_step + end + + # Custom attribute writer method with validation + # @param [Object] percentage Value to be assigned + def percentage=(percentage) + if percentage.nil? + fail ArgumentError, 'percentage cannot be nil' + end + + if percentage > 100 + fail ArgumentError, 'invalid value for "percentage", must be smaller than or equal to 100.' + end + + if percentage < 0 + fail ArgumentError, 'invalid value for "percentage", must be greater than or equal to 0.' + end + + @percentage = percentage + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] type Object to be assigned + def type=(type) + validator = EnumAttributeValidator.new('String', ["segmented_progress", "progress", "metrics", "counter", "timer", "countdown"]) + unless validator.valid?(type) + fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}." + end + @type = type + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] color Object to be assigned + def color=(color) + validator = EnumAttributeValidator.new('String', ["lime", "green", "cyan", "blue", "purple", "magenta", "red", "orange", "yellow"]) + unless validator.valid?(color) + fail ArgumentError, "invalid value for \"color\", must be one of #{validator.allowable_values}." + end + @color = color + end + + # Custom attribute writer method checking allowed values (enum). + # @param [Object] step_color Object to be assigned + def step_color=(step_color) + validator = EnumAttributeValidator.new('String', ["lime", "green", "cyan", "blue", "purple", "magenta", "red", "orange", "yellow"]) + unless validator.valid?(step_color) + fail ArgumentError, "invalid value for \"step_color\", must be one of #{validator.allowable_values}." + end + @step_color = step_color + end + + # Custom attribute writer method with validation + # @param [Object] metrics Value to be assigned + def metrics=(metrics) + if metrics.nil? + fail ArgumentError, 'metrics cannot be nil' + end + + if metrics.length < 1 + fail ArgumentError, 'invalid value for "metrics", number of items must be greater than or equal to 1.' + end + + @metrics = metrics + end + + # Custom attribute writer method with validation + # @param [Object] auto_dismiss_seconds Value to be assigned + def auto_dismiss_seconds=(auto_dismiss_seconds) + if auto_dismiss_seconds.nil? + fail ArgumentError, 'auto_dismiss_seconds cannot be nil' + end + + if auto_dismiss_seconds < 0 + fail ArgumentError, 'invalid value for "auto_dismiss_seconds", must be greater than or equal to 0.' + end + + @auto_dismiss_seconds = auto_dismiss_seconds + end + + # Custom attribute writer method with validation + # @param [Object] auto_dismiss_minutes Value to be assigned + def auto_dismiss_minutes=(auto_dismiss_minutes) + if auto_dismiss_minutes.nil? + fail ArgumentError, 'auto_dismiss_minutes cannot be nil' + end + + if auto_dismiss_minutes < 0 + fail ArgumentError, 'invalid value for "auto_dismiss_minutes", must be greater than or equal to 0.' + end + + @auto_dismiss_minutes = auto_dismiss_minutes + 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 && + title == o.title && + subtitle == o.subtitle && + number_of_steps == o.number_of_steps && + current_step == o.current_step && + percentage == o.percentage && + value == o.value && + upper_limit == o.upper_limit && + type == o.type && + color == o.color && + step_color == o.step_color && + step_colors == o.step_colors && + metrics == o.metrics && + auto_dismiss_seconds == o.auto_dismiss_seconds && + auto_dismiss_minutes == o.auto_dismiss_minutes + 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 + [title, subtitle, number_of_steps, current_step, percentage, value, upper_limit, type, color, step_color, step_colors, metrics, auto_dismiss_seconds, auto_dismiss_minutes].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 From 8b7a2d51f190998cc0e792791472a9347b3ff11f Mon Sep 17 00:00:00 2001 From: bardonadam Date: Sun, 22 Mar 2026 16:17:36 +0100 Subject: [PATCH 2/2] feat: add stream helpers and docs --- README.md | 270 +++++++++++++++++++++++---- lib/activitysmith/live_activities.rb | 19 ++ lib/activitysmith/version.rb | 2 +- test/client_test.rb | 2 + test/resources_test.rb | 67 +++++++ 5 files changed, 327 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 0060b60..8d0a939 100644 --- a/README.md +++ b/README.md @@ -105,27 +105,230 @@ activitysmith.notifications.send( ## Live Activities -Live Activities come in two UI types, but the lifecycle stays the same: -start the activity, keep the returned `activity_id`, update it as state -changes, then end it when the work is done. +

+ Live Activities example +

+ +ActivitySmith supports two ways to drive Live Activities: + +- Recommended: stream updates with `activitysmith.live_activities.stream(...)` +- Advanced: manual lifecycle control with `start`, `update`, and `end` + +Use stream updates when you want the easiest, stateless flow. You don't need to +store `activity_id` or manage lifecycle state yourself. Send the latest state +for a stable `stream_key` and ActivitySmith will start or update the Live +Activity for you. When the tracked process is over, call `end_stream(...)`. + +Use the manual lifecycle methods when you need direct control over a specific +Live Activity instance. + +Live Activity UI types: + +- `metrics`: best for live operational stats like server CPU and memory, queue depth, or replica lag +- `segmented_progress`: best for step-based workflows like deployments, backups, and ETL pipelines +- `progress`: best for continuous jobs like uploads, reindexes, and long-running migrations tracked as a percentage -- `segmented_progress`: best for jobs tracked in steps -- `progress`: best for jobs tracked as a percentage or numeric range +### Recommended: Stream updates + +Use a stable `stream_key` to identify the system or workflow you are tracking, +such as a server, deployment, build pipeline, cron job, or charging session. +This is especially useful for cron jobs and other scheduled tasks where you do +not want to store `activity_id` between runs. + +#### Metrics + +

+ Metrics stream example +

+ +```ruby +status = activitysmith.live_activities.stream( + "prod-web-1", + { + content_state: { + title: "Server Health", + subtitle: "prod-web-1", + type: "metrics", + metrics: [ + { label: "CPU", value: 9, unit: "%" }, + { label: "MEM", value: 45, unit: "%" } + ] + } + } +) +``` + +#### Segmented progress + +

+ Segmented progress stream example +

+ +```ruby +activitysmith.live_activities.stream( + "nightly-backup", + { + content_state: { + title: "Nightly Backup", + subtitle: "upload archive", + type: "segmented_progress", + number_of_steps: 3, + current_step: 2 + } + } +) +``` + +#### Progress + +

+ Progress stream example +

+ +```ruby +activitysmith.live_activities.stream( + "search-reindex", + { + content_state: { + title: "Search Reindex", + subtitle: "catalog-v2", + type: "progress", + percentage: 42 + } + } +) +``` + +Call `stream(...)` again with the same `stream_key` whenever the state changes. + +#### End a stream + +Use this when the tracked process is finished and you no longer want the Live +Activity on devices. `content_state` is optional here; include it if you want +to end the stream with a final state. + +```ruby +activitysmith.live_activities.end_stream( + "prod-web-1", + { + content_state: { + title: "Server Health", + subtitle: "prod-web-1", + type: "metrics", + metrics: [ + { label: "CPU", value: 7, unit: "%" }, + { label: "MEM", value: 38, unit: "%" } + ] + } + } +) +``` -### Shared flow +If you later send another `stream(...)` request with the same `stream_key`, +ActivitySmith starts a new Live Activity for that stream again. + +Stream responses include an `operation` field: + +- `started`: ActivitySmith started a new Live Activity for this `stream_key` +- `updated`: ActivitySmith updated the current Live Activity +- `rotated`: ActivitySmith ended the previous Live Activity and started a new one +- `noop`: the incoming state matched the current state, so no update was sent +- `paused`: the stream is paused, so no Live Activity was started or updated +- `ended`: returned by `end_stream(...)` after the stream is ended + +### Advanced: Manual lifecycle control + +Use these methods when you want to manage the Live Activity lifecycle yourself. + +#### Shared flow 1. Call `activitysmith.live_activities.start(...)`. 2. Save the returned `activity_id`. 3. Call `activitysmith.live_activities.update(...)` as progress changes. 4. Call `activitysmith.live_activities.end(...)` when the work is finished. +### Metrics Type + +Use `metrics` when you want to keep a small set of live stats visible, such as +server health, queue pressure, or database load. + +#### Start + +

+ Metrics start example +

+ +```ruby +start = activitysmith.live_activities.start( + { + content_state: { + title: "Server Health", + subtitle: "prod-web-1", + type: "metrics", + metrics: [ + { label: "CPU", value: 9, unit: "%" }, + { label: "MEM", value: 45, unit: "%" } + ] + } + } +) + +activity_id = start.activity_id +``` + +#### Update + +

+ Metrics update example +

+ +```ruby +activitysmith.live_activities.update( + { + activity_id: activity_id, + content_state: { + title: "Server Health", + subtitle: "prod-web-1", + type: "metrics", + metrics: [ + { label: "CPU", value: 76, unit: "%" }, + { label: "MEM", value: 52, unit: "%" } + ] + } + } +) +``` + +#### End + +

+ Metrics end example +

+ +```ruby +activitysmith.live_activities.end( + { + activity_id: activity_id, + content_state: { + title: "Server Health", + subtitle: "prod-web-1", + type: "metrics", + metrics: [ + { label: "CPU", value: 7, unit: "%" }, + { label: "MEM", value: 38, unit: "%" } + ], + auto_dismiss_minutes: 2 + } + } +) +``` + ### Segmented Progress Type Use `segmented_progress` when progress is easier to follow as steps instead of a raw percentage. It fits jobs like backups, deployments, ETL pipelines, and -checklists where "step 2 of 3" is more useful than "67%". -`number_of_steps` is dynamic, so you can increase or decrease it later if the -workflow changes. +checklists where "step 2 of 3" is more useful than "67%". `number_of_steps` is +dynamic, so you can increase or decrease it later if the workflow changes. #### Start @@ -143,8 +346,7 @@ start = activitysmith.live_activities.start( current_step: 1, type: "segmented_progress", color: "yellow" - }, - channels: ["devs", "ops"] # Optional + } } ) @@ -164,7 +366,7 @@ activitysmith.live_activities.update( content_state: { title: "Nightly database backup", subtitle: "upload archive", - number_of_steps: 4, + number_of_steps: 3, current_step: 2 } } @@ -184,8 +386,8 @@ activitysmith.live_activities.end( content_state: { title: "Nightly database backup", subtitle: "verify restore", - number_of_steps: 4, - current_step: 4, + number_of_steps: 3, + current_step: 3, auto_dismiss_minutes: 2 } } @@ -211,8 +413,7 @@ start = activitysmith.live_activities.start( title: "EV Charging", subtitle: "Added 30 mi range", type: "progress", - percentage: 15, - color: "lime" + percentage: 15 } } ) @@ -261,10 +462,10 @@ activitysmith.live_activities.end( ### Live Activity Action -Just like Actionable Push Notifications, Live Activities can have a button that opens provided URL in a browser or triggers a webhook. Webhooks are executed by the ActivitySmith backend. +Just like Actionable Push Notifications, Live Activities can have a button that opens a URL in a browser or triggers a webhook. Webhooks are executed by the ActivitySmith backend.

- Live Activity with action + Metrics Live Activity with action

#### Open URL action @@ -273,16 +474,18 @@ Just like Actionable Push Notifications, Live Activities can have a button that start = activitysmith.live_activities.start( { content_state: { - title: "Deploying payments-api", - subtitle: "Running database migrations", - number_of_steps: 5, - current_step: 3, - type: "segmented_progress" + title: "Server Health", + subtitle: "prod-web-1", + type: "metrics", + metrics: [ + { label: "CPU", value: 76, unit: "%" }, + { label: "MEM", value: 52, unit: "%" } + ] }, action: { - title: "Open Workflow", + title: "Open Dashboard", type: "open_url", - url: "https://github.com/acme/payments-api/actions/runs/1234567890" + url: "https://ops.example.com/servers/prod-web-1" } } ) @@ -297,18 +500,21 @@ activitysmith.live_activities.update( { activity_id: activity_id, content_state: { - title: "Reindexing product search", - subtitle: "Shard 7 of 12", - number_of_steps: 12, - current_step: 7 + title: "Server Health", + subtitle: "prod-web-1", + type: "metrics", + metrics: [ + { label: "CPU", value: 91, unit: "%" }, + { label: "MEM", value: 57, unit: "%" } + ] }, action: { - title: "Pause Reindex", + title: "Restart Service", type: "webhook", - url: "https://ops.example.com/hooks/search/reindex/pause", + url: "https://ops.example.com/hooks/servers/prod-web-1/restart", method: "POST", body: { - job_id: "reindex-2026-03-19", + server_id: "prod-web-1", requested_by: "activitysmith-ruby" } } diff --git a/lib/activitysmith/live_activities.rb b/lib/activitysmith/live_activities.rb index 384d66a..75c847f 100644 --- a/lib/activitysmith/live_activities.rb +++ b/lib/activitysmith/live_activities.rb @@ -18,6 +18,14 @@ def end(request, opts = {}) @api.end_live_activity(request, opts) end + def stream(stream_key, request, opts = {}) + @api.reconcile_live_activity_stream(stream_key, normalize_channels_target(request), opts) + end + + def end_stream(stream_key, request = nil, opts = {}) + @api.end_live_activity_stream(stream_key, { live_activity_stream_delete_request: request }.merge(opts)) + end + # Backward-compatible aliases. def start_live_activity(live_activity_start_request, opts = {}) @api.start_live_activity(normalize_channels_target(live_activity_start_request), opts) @@ -31,6 +39,17 @@ def end_live_activity(live_activity_end_request, opts = {}) @api.end_live_activity(live_activity_end_request, opts) end + def reconcile_live_activity_stream(stream_key, live_activity_stream_request, opts = {}) + @api.reconcile_live_activity_stream(stream_key, normalize_channels_target(live_activity_stream_request), opts) + end + + def end_live_activity_stream(stream_key, live_activity_stream_delete_request = nil, opts = {}) + @api.end_live_activity_stream( + stream_key, + { live_activity_stream_delete_request: live_activity_stream_delete_request }.merge(opts) + ) + end + def method_missing(name, *args, &block) return @api.public_send(name, *args, &block) if @api.respond_to?(name) diff --git a/lib/activitysmith/version.rb b/lib/activitysmith/version.rb index eba5f20..de24c53 100644 --- a/lib/activitysmith/version.rb +++ b/lib/activitysmith/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ActivitySmith - VERSION = "1.0.0" + VERSION = "1.1.0" end diff --git a/test/client_test.rb b/test/client_test.rb index 55f4944..7039dce 100644 --- a/test/client_test.rb +++ b/test/client_test.rb @@ -20,6 +20,8 @@ def test_constructs_when_generated_client_is_present assert_respond_to client.live_activities, :start assert_respond_to client.live_activities, :update assert_respond_to client.live_activities, :end + assert_respond_to client.live_activities, :stream + assert_respond_to client.live_activities, :end_stream rescue RuntimeError => error skip "Generated OpenAPI client is not present yet." if error.message.include?("Generated Ruby client not found") diff --git a/test/resources_test.rb b/test/resources_test.rb index ac0b4df..d1a4a2e 100644 --- a/test/resources_test.rb +++ b/test/resources_test.rb @@ -46,6 +46,16 @@ def end_live_activity_with_http_info(request, opts = {}) @calls << [:end_live_activity_with_http_info, request, opts] [:ok, 200, {}] end + + def reconcile_live_activity_stream(stream_key, request, opts = {}) + @calls << [:reconcile_live_activity_stream, stream_key, request, opts] + { success: true, operation: "started", stream_key: stream_key } + end + + def end_live_activity_stream(stream_key, opts = {}) + @calls << [:end_live_activity_stream, stream_key, opts] + { success: true, operation: "ended", stream_key: stream_key } + end end class ResourcesTest < Minitest::Test @@ -222,6 +232,63 @@ def test_live_activities_support_progress_payloads ) end + def test_live_activities_stream_short_and_legacy_methods + api = FakeLiveApi.new + resource = ActivitySmith::LiveActivities.new(api) + + stream_payload = { + content_state: { + title: "Server Health", + subtitle: "prod-web-1", + type: "metrics", + metrics: [ + { label: "CPU", value: 9, unit: "%" }, + { label: "MEM", value: 45, unit: "%" } + ] + }, + channels: ["ops"] + } + end_payload = { + content_state: { + title: "Server Health", + subtitle: "prod-web-1", + type: "metrics", + metrics: [ + { label: "CPU", value: 7, unit: "%" }, + { label: "MEM", value: 38, unit: "%" } + ] + } + } + + resource.stream("prod-web-1", stream_payload) + resource.reconcile_live_activity_stream("prod-web-1", stream_payload) + resource.end_stream("prod-web-1", end_payload) + resource.end_live_activity_stream("prod-web-1", end_payload) + + expected_stream_payload = { + content_state: stream_payload[:content_state], + target: { channels: ["ops"] } + } + + assert_equal( + [ + [:reconcile_live_activity_stream, "prod-web-1", expected_stream_payload, {}], + [:reconcile_live_activity_stream, "prod-web-1", expected_stream_payload, {}], + [ + :end_live_activity_stream, + "prod-web-1", + { live_activity_stream_delete_request: end_payload } + ], + [ + :end_live_activity_stream, + "prod-web-1", + { live_activity_stream_delete_request: end_payload } + ] + ], + api.calls + ) + end + def test_live_activities_pass_action_payloads_through api = FakeLiveApi.new resource = ActivitySmith::LiveActivities.new(api)