Skip to content

ActivitySmithHQ/activitysmith-ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ActivitySmith Ruby SDK

The ActivitySmith Ruby SDK provides convenient access to the ActivitySmith API from Ruby applications.

Documentation

See API reference.

Installation

gem install activitysmith

Setup

require "activitysmith"

activitysmith = ActivitySmith::Client.new(api_key: ENV.fetch("ACTIVITYSMITH_API_KEY"))

Usage

Send a Push Notification

Push notification example

response = activitysmith.notifications.send(
  {
    title: "New subscription 💸",
    message: "Customer upgraded to Pro plan",
    channels: ["devs", "ops"] # Optional
  }
)

puts response.success
puts response.devices_notified

Start a Live Activity

Start live activity example

start = activitysmith.live_activities.start(
  {
    content_state: {
      title: "Nightly database backup",
      subtitle: "create snapshot",
      number_of_steps: 3,
      current_step: 1,
      type: "segmented_progress",
      color: "yellow"
    },
    channels: ["devs", "ops"] # Optional
  }
)

activity_id = start.activity_id

Update a Live Activity

Update live activity example

update = activitysmith.live_activities.update(
  {
    activity_id: activity_id,
    content_state: {
      title: "Nightly database backup",
      subtitle: "upload archive",
      current_step: 2
    }
  }
)

puts update.devices_notified

End a Live Activity

End live activity example

finish = activitysmith.live_activities.end(
  {
    activity_id: activity_id,
    content_state: {
      title: "Nightly database backup",
      subtitle: "verify restore",
      current_step: 3,
      auto_dismiss_minutes: 2
    }
  }
)

puts finish.success

Error Handling

begin
  activitysmith.notifications.send(
    { title: "New subscription 💸" }
  )
rescue OpenapiClient::ApiError => err
  puts "Request failed: #{err.code} #{err.message}"
end

API Surface

  • activitysmith.notifications
  • activitysmith.live_activities

Requirements

  • Ruby 3.0+

License

MIT