Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 75 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ See [API reference](https://activitysmith.com/docs/api-reference/introduction).
- [Start & Update Live Activity](#start--update-live-activity)
- [End Live Activity](#end-live-activity)
- [Live Activity Action](#live-activity-action)
- [Icons and Badges](#icons-and-badges)
- [Live Activity Colors](#live-activity-colors)
- [Channels](#channels)
- [Widgets](#widgets)

Expand Down Expand Up @@ -264,14 +266,6 @@ activitysmith.live_activities.stream(
)
```

The `icon` symbol value is an Apple SF Symbol name. Browse the catalog with one of these tools:

- [ActivitySmith app](https://apps.apple.com/us/app/activitysmith/id6752254835) - Open Settings -> SF Symbols to browse 45 hand-picked icons ready to use
- [SF Symbols](https://developer.apple.com/sf-symbols/) - Apple's official macOS app
- [Interactful](https://apps.apple.com/app/interactful/id1528095640) - free third-party iOS app listing all SF Symbols under Foundations -> Iconography

`icon` and `badge` are optional. If you omit either one, that element is not shown in the Live Activity.

### End Live Activity

Call `end_stream(...)` with the same `stream_key` to dismiss the Live Activity. You can include final values before it is removed. By default, iOS removes the Live Activity after two minutes. Set `auto_dismiss_minutes` to choose a different dismissal time, including `0` for immediate dismissal.
Expand Down Expand Up @@ -358,6 +352,79 @@ activitysmith.live_activities.stream(
)
```

### Icons and Badges

Add more context to Live Activities with icons and badges.

#### Icon

Supported Live Activity types: `stats`, `metrics`, `progress`, `segmented_progress`, and `alert`.

<p align="center">
<img
src="https://cdn.activitysmith.com/features/metrics-live-activity-with-icon.png"
alt="Metrics Live Activity with an SF Symbol icon on the iPhone Lock Screen"
width="680"
/>
</p>

```ruby
activitysmith.live_activities.stream(
"prod-web-1",
{
content_state: ActivitySmith::LiveActivities.content_state(
title: "Server Health",
subtitle: "prod-web-1",
type: "metrics",
icon: ActivitySmith::LiveActivities.alert_icon("server.rack", color: "blue"),
metrics: [
{ label: "CPU", value: 18, unit: "%" },
{ label: "MEM", value: 42, unit: "%" }
]
)
}
)
```

The `icon` symbol value is an Apple SF Symbol name. Browse the catalog with one of these tools:

- [ActivitySmith app](https://apps.apple.com/us/app/activitysmith/id6752254835) - Open Settings -> SF Symbols to browse 45 hand-picked icons ready to use
- [SF Symbols](https://developer.apple.com/sf-symbols/) - Apple's official macOS app
- [Interactful](https://apps.apple.com/app/interactful/id1528095640) - free third-party iOS app listing all SF Symbols under Foundations -> Iconography

#### Badge

Badges are supported by `alert`, `progress`, and `segmented_progress` Live Activities.

<p align="center">
<img
src="https://cdn.activitysmith.com/features/progress-live-activity-with-badge.png"
alt="Progress Live Activity with a badge on the iPhone Lock Screen"
width="680"
/>
</p>

```ruby
activitysmith.live_activities.stream(
"nightly-database-backup",
{
content_state: ActivitySmith::LiveActivities.content_state(
title: "Nightly Database Backup",
subtitle: "verify restore",
type: "progress",
badge: ActivitySmith::LiveActivities.alert_badge("S3", color: "cyan"),
percentage: 62
)
}
)
```

### Live Activity Colors

Choose from these colors for the Live Activity accent, including progress bars and action buttons, or apply them to an individual icon or badge:

`lime`, `green`, `cyan`, `blue`, `purple`, `magenta`, `red`, `orange`, `yellow`, `gray`

## Channels

Channels are used to target specific team members or devices. Can be used for both push notifications and live activities.
Expand Down
6 changes: 3 additions & 3 deletions generated/activitysmith_openapi/models/content_state_end.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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. For metrics and stats include a non-empty metrics array. For alert include message, with optional icon and badge. 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 and stats include a non-empty metrics array. For alert include message. Optional icon is supported by all Live Activity types. Optional badge is supported by alert, progress, and segmented_progress. 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

Expand All @@ -41,10 +41,10 @@ class ContentStateEnd
# Alert message. Use for type=alert.
attr_accessor :message

# Optional SF Symbol icon for type=alert.
# Optional SF Symbol icon. Supported by alert, progress, segmented_progress, metrics, and stats.
attr_accessor :icon

# Optional badge for type=alert.
# Optional badge. Supported by alert, progress, and segmented_progress.
attr_accessor :badge

# Optional. When omitted, the API uses the existing Live Activity type.
Expand Down
6 changes: 3 additions & 3 deletions generated/activitysmith_openapi/models/content_state_start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 metrics and stats include a non-empty metrics array. For alert include message, with optional icon and badge. 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 and stats include a non-empty metrics array. For alert include message. Optional icon is supported by all Live Activity types. Optional badge is supported by alert, progress, and segmented_progress. For segmented_progress, number_of_steps is not locked and can be changed in later update or end calls.
class ContentStateStart
attr_accessor :title

Expand All @@ -41,10 +41,10 @@ class ContentStateStart
# Required for type=alert.
attr_accessor :message

# Optional SF Symbol icon for type=alert.
# Optional SF Symbol icon. Supported by alert, progress, segmented_progress, metrics, and stats.
attr_accessor :icon

# Optional badge for type=alert.
# Optional badge. Supported by alert, progress, and segmented_progress.
attr_accessor :badge

attr_accessor :type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. For metrics and stats include a non-empty metrics array. For alert include message, with optional icon and badge. 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 and stats include a non-empty metrics array. For alert include message. Optional icon is supported by all Live Activity types. Optional badge is supported by alert, progress, and segmented_progress. Type is optional when updating an existing activity. You can increase or decrease number_of_steps during updates.
class ContentStateUpdate
attr_accessor :title

Expand All @@ -41,10 +41,10 @@ class ContentStateUpdate
# Alert message. Use for type=alert.
attr_accessor :message

# Optional SF Symbol icon for type=alert.
# Optional SF Symbol icon. Supported by alert, progress, segmented_progress, metrics, and stats.
attr_accessor :icon

# Optional badge for type=alert.
# Optional badge. Supported by alert, progress, and segmented_progress.
attr_accessor :badge

# Optional. When omitted, the API uses the existing Live Activity type.
Expand Down
62 changes: 19 additions & 43 deletions generated/activitysmith_openapi/models/live_activity_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LiveActivityAction

attr_accessor :type

# HTTPS URL. For open_url it is opened in browser. For webhook it is called by ActivitySmith backend.
# Action URL. For open_url, use an HTTPS or shortcuts:// URL. For webhook, use an HTTPS URL called by the ActivitySmith backend.
attr_accessor :url

# Webhook HTTP method. Used only when type=webhook.
Expand All @@ -30,28 +30,6 @@ class LiveActivityAction
# Optional webhook payload body. Used only when type=webhook.
attr_accessor :body

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
{
Expand Down Expand Up @@ -117,6 +95,7 @@ def initialize(attributes = {})
else
self.url = nil
end
validate_action_url!

if attributes.key?(:'method')
self.method = attributes[:'method']
Expand All @@ -131,6 +110,16 @@ def initialize(attributes = {})
end
end

def validate_action_url!
return if @url.nil? || @type.nil?
if @type == LiveActivityActionType::OPEN_URL && @url !~ /\A(https|shortcuts):\/\//
fail ArgumentError, 'invalid value for "url", open_url must use https or shortcuts.'
end
if @type == LiveActivityActionType::WEBHOOK && @url !~ /\Ahttps:\/\//
fail ArgumentError, 'invalid value for "url", webhook must use https.'
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
Expand All @@ -147,10 +136,11 @@ def list_invalid_properties
if @url.nil?
invalid_properties.push('invalid value for "url", url cannot be nil.')
end

pattern = Regexp.new(/^https:\/\//)
if @url !~ pattern
invalid_properties.push("invalid value for \"url\", must conform to the pattern #{pattern}.")
if !@url.nil? && @type == LiveActivityActionType::OPEN_URL && @url !~ /\A(https|shortcuts):\/\//
invalid_properties.push('invalid value for "url", open_url must use https or shortcuts.')
end
if !@url.nil? && @type == LiveActivityActionType::WEBHOOK && @url !~ /\Ahttps:\/\//
invalid_properties.push('invalid value for "url", webhook must use https.')
end

invalid_properties
Expand All @@ -163,25 +153,11 @@ def valid?
return false if @title.nil?
return false if @type.nil?
return false if @url.nil?
return false if @url !~ Regexp.new(/^https:\/\//)
return false if !@url.nil? && @type == LiveActivityActionType::OPEN_URL && @url !~ /\A(https|shortcuts):\/\//
return false if !@url.nil? && @type == LiveActivityActionType::WEBHOOK && @url !~ /\Ahttps:\/\//
true
end

# Custom attribute writer method with validation
# @param [Object] url Value to be assigned
def url=(url)
if url.nil?
fail ArgumentError, 'url cannot be nil'
end

pattern = Regexp.new(/^https:\/\//)
if url !~ pattern
fail ArgumentError, "invalid value for \"url\", must conform to the pattern #{pattern}."
end

@url = url
end

# Checks equality by comparing each attribute.
# @param [Object] Object to be compared
def ==(o)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
require 'time'

module OpenapiClient
# Optional badge for Alert Live Activities.
# Optional badge for Live Activities.
class LiveActivityAlertBadge
attr_accessor :title

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
require 'time'

module OpenapiClient
# Optional SF Symbol icon for Alert Live Activities.
# Optional SF Symbol icon for Live Activities.
class LiveActivityAlertIcon
# Apple SF Symbol name.
attr_accessor :symbol
Expand Down
Loading