Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration guide from seamapi Ruby gem #3

Open
Tracked by #73
razor-x opened this issue Apr 19, 2024 · 2 comments
Open
Tracked by #73

Migration guide from seamapi Ruby gem #3

razor-x opened this issue Apr 19, 2024 · 2 comments
Assignees

Comments

@razor-x
Copy link
Contributor

razor-x commented Apr 19, 2024

See for reference seamapi/javascript#1 or seamapi/python#7

@razor-x razor-x changed the title Migration guide from seamapi package Migration guide from seamapi Ruby gem Aug 7, 2024
@andrii-balitskyi andrii-balitskyi self-assigned this Aug 7, 2024
@andrii-balitskyi
Copy link
Collaborator

andrii-balitskyi commented Aug 7, 2024

Migration guide from seamapi to seam

Learn how to migrate from the seamapi package to the seam package. This guide includes descriptions of all breaking changes.

The new SDK has fewer dependencies and is generated daily to ensure methods and types are always up-to-date with the latest API changes. It is mostly a drop-in replacement, however some method signatures and options have changed to improve overall consistency with the Seam API.

This guide includes descriptions of all breaking changes. Please refer to the README for updated usage instructions and a complete list of new features.

New Ruby gem name

Changed the gem name from seamapi to seam.

- bundle add seamapi
+ bundle add seam

Updated API method signatures

Keyword arguments

API method signatures now only accept keyword arguments.

- seam.access_codes.get("my_access_code_id")
+ seam.access_codes.get(access_code_id: "my_access_code_id")
- seam.locks.get("my_lock_device_id")
+ seam.locks.get(device_id: "my_lock_device_id")

Standardized resource ID arguments

Changed from accepting both resource objects and resource ID strings to accepting only resource ID strings. Includes a renaming scheme for clarity.

- def unlock_door(device_or_id)
+ def unlock_door(device_id:)

Usage

- seam.locks.get(device: my_device)
+ seam.locks.get(device_id: my_device.device_id)

Removed methods

Removed wait_until_finished from ActionAttempt resource. To resolve an action attempt returned by the method, use the wait_for_action_attempt method argument instead.

- seam.locks.unlock_door(device_id: "my_device_id").wait_until_finished
+ seam.locks.unlock_door(device_id: "my_device_id", wait_for_action_attempt: true)

Deprecated methods

seam.unmanaged_access_codes

seam.unmanaged_access_codes is now deprecated, use seam.access_codes.unmanaged instead.

- seam.unmanaged_access_codes.get(access_code_id: "my_access_code_id")
+ seam.access_codes.unmanaged.get(access_code_id: "my_access_code_id")

seam.unmanaged_devices

seam.unmanaged_devices is now deprecated, use seam.devices.unmanaged instead.

- seam.unmanaged_devices.get(device_id: "my_device_id")
+ seam.devices.unmanaged.get(device_id: "my_device_id")

Return value changes

Changed the return values for some methods to enhance API consistency and reliability.

The following methods now return nil:

  • access_codes.delete: Instead, you should wait for the access_code.deleted event.
  • access_codes.update: Instead, you should watch for relevant access_code.* events or poll the resource as needed.
  • access_codes.unmanaged.delete
  • access_codes.unmanaged.convert_to_managed: Instead, you should wait for the access_code.unmanaged.converted_to_managed and access_code.unmanaged.failed_to_convert_to_managed events.

The following methods now return an ActionAttempt:

  • workspaces.reset_sandbox: Instead, you should use the newly-created action_attempt_id to poll the status of the action attempt via the /action_attempt/get endpoint.

Action attempt resolution

Methods returning action attempts still wait for the action attempt to resolve by default. Further, you can now configure this behavior using the wait_for_action_attempt option on a per-request basis. You can also set the default behavior for the client.

Set per request

# Wait for the action attempt to be ready with a default timeout of 5.0 seconds and a default polling interval of 0.5 seconds.
seam.locks.lock_door(
  device_id: "my_device_id",
  wait_for_action_attempt: true
)

# Wait up to 10 seconds for the action attempt to be ready, checking every 2 seconds.
seam.locks.lock_door(
  device_id: "my_device_id",
  wait_for_action_attempt: {
    timeout: 10.0,  # Up to 10 seconds
    polling_interval: 2.0  # Every 2 seconds
  }
)

Set default behavior

seam = Seam.new(wait_for_action_attempt: true)

Environment variables

Added support for the SEAM_ENDPOINT environment variable.

Version changes

  • Updated the minimum supported Ruby version to 3.1.0.

Highlighted new features

API key authentication with from_api_key factory method

Added a new from_api_key factory method for API key authentication of the Seam client.

seam = Seam.from_api_key(api_key: "your-api-key")

PAT authentication scoped to a single workspace

Added support for workspace personal access token (PAT) authentication.

# Pass as an option to the constructor
seam = Seam.new(
  personal_access_token: "your-personal-access-token",
  workspace_id: "your-workspace-id",
)

# Use the factory method
seam = Seam.from_personal_access_token(
  personal_access_token: "your-personal-access-token",
  workspace_id: "your-workspace-id",
)

PAT authentication not bound to a specific workspace

For authentication with a personal access token not bound to a specific workspace, use SeamMultiWorkspace.

# Pass as an option to the constructor
seam_multi_workspace = SeamMultiWorkspace.new(personal_access_token: "your-personal-access-token")

# Use the factory method
seam_multi_workspace = SeamMultiWorkspace.from_personal_access_token(
  personal_access_token: "your-personal-access-token"
)

workspace = seam_multi_workspace.workspaces.create(company_name: "Example Inc.")

Webhook handler

SDK exports a thin wrapper SeamWebhook around the svix package. Use it to parse and validate Seam webhook events.

@andrii-balitskyi
Copy link
Collaborator

andrii-balitskyi commented Aug 7, 2024

@razor-x here's the first version of migration guide. Some things are still not implemented, like:

  • allow using Seam.new and not Seam::Client.new
  • rename ClientMultiWorkspace to SeamMultiWorkspace and expose it from the SDK to be used as SeamMultiWorkspace.new without the Seam namespace
  • add SeamWebhook
  • document SDK usage in README.md for the links inside the guide to work correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants