0.0
No release in over 3 years
Ruby client for the Sprites API - stateful sandbox environments
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

 Project Readme

Sprites

Ruby client for the Sprites API - stateful sandbox environments.

Installation

Add this line to your application's Gemfile:

gem "sprites-ruby"

Getting Started

Create a client

client = Sprites::Client.new(token: ENV["SPRITES_TOKEN"])

Or configure globally

Sprites.configure do |config|
  config.token = ENV["SPRITES_TOKEN"]
end

client = Sprites::Client.new

Sprites

Create a sprite

sprite = client.sprites.create(name: "my-sprite")

Create and wait until ready

sprite = client.sprites.create(name: "my-sprite", wait: true)

List sprites

collection = client.sprites.list
collection.sprites.each { |s| puts s.name }

Get a sprite

sprite = client.sprites.retrieve("my-sprite")
sprite.status # => "warm"

Update a sprite

sprite = client.sprites.update("my-sprite", url_settings: { auth: "public" })

Delete a sprite

client.sprites.delete("my-sprite")

Command Execution

Run a command (HTTP, simple)

result = client.exec.create("my-sprite", command: "echo hello")
result[:output]    # => "hello\n"
result[:exit_code] # => 0

Run a command (WebSocket, streaming)

result = client.exec.run("my-sprite", ["ls", "-la"])
result.stdout
result.stderr
result.exit_code

Interactive terminal session

client.exec.interactive("my-sprite", ["bash"])

With custom I/O

client.exec.interactive("my-sprite", ["bash"], input: $stdin, output: $stdout)

Sessions

List active sessions

sessions = client.exec.list("my-sprite")
sessions.each { |s| puts "#{s[:id]}: #{s[:command]}" }

Attach to a session

client.exec.attach("my-sprite", session_id)

Kill a session

client.exec.kill("my-sprite", session_id)

With a specific signal

client.exec.kill("my-sprite", session_id, signal: "SIGKILL")

Checkpoints

Create a checkpoint

client.checkpoints.create("my-sprite", comment: "before deploy")

List checkpoints

checkpoints = client.checkpoints.list("my-sprite")

Restore a checkpoint

client.checkpoints.restore("my-sprite", checkpoint_id)

Network Policies

Get current policy

policy = client.policies.retrieve("my-sprite")
policy[:egress][:policy] # => "allow-all"

Update policy

client.policies.update("my-sprite", egress: { policy: "block-all" })

Low-Level WebSocket API

For advanced use cases, use connect directly

client.exec.connect("my-sprite", command: ["bash"], tty: true) do |task, session|
  session.on_stdout { |data| print data }
  session.on_stderr { |data| $stderr.print data }
  session.on_exit { |code| puts "Exit: #{code}" }

  task.async do
    while (line = $stdin.gets)
      session.write(line)
    end
  end
end

Development

bundle install
rake test

Releasing

rake release            # build, tag, push gem to RubyGems
just release          # create GitHub release with CHANGELOG notes

License

MIT