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
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ accurate and fully typed.
- [Resume pagination](#resume-pagination)
- [Iterate over all resources](#iterate-over-all-resources)
- [Return all resources across all pages as a list](#return-all-resources-across-all-pages-as-a-list)
- [Interacting with Multiple Workspaces](#interacting-with-multiple-workspaces)
- [Requests without a Workspace in scope](#requests-without-a-workspace-in-scope)
- [Personal Access Token](#personal-access-token-1)
- [Webhooks](#webhooks)
- [Advanced Usage](#advanced-usage)
- [Additional Options](#additional-options)
Expand Down Expand Up @@ -314,18 +315,27 @@ paginator = seam.create_paginator(seam.devices.method(:list), {limit: 20})
all_devices = paginator.flatten_to_list
```

### Interacting with Multiple Workspaces
### Requests without a Workspace in scope

Some Seam API endpoints interact with multiple workspaces. The `Seam::Http::SeamMultiWorkspace` client is not bound to a specific workspace and may use those endpoints with a personal access token authentication method.
Some Seam API endpoints do not require a workspace in scope.
The `Seam::Http::WithoutWorkspace` client is not bound to a specific workspace
and may use those endpoints with a personal access token authentication method.

A Personal Access Token is scoped to a Seam Console user. Obtain one from the Seam Console.
#### Personal Access Token

A Personal Access Token is scoped to a Seam Console user.
Obtain one from the Seam Console.

```ruby
# Pass as an option to the constructor
seam = Seam::Http::SeamMultiWorkspace.new(personal_access_token: "your-personal-access-token")
# Pass as a keyword argument to the constructor
seam = Seam::Http::WithoutWorkspace.new(
personal_access_token: "your-personal-access-token"
)

# Use the factory method
seam = Seam::Http::SeamMultiWorkspace.from_personal_access_token("your-personal-access-token")
seam = Seam::Http::WithoutWorkspace.from_personal_access_token(
"your-personal-access-token"
)

# List workspaces authorized for this Personal Access Token
workspaces = seam.workspaces.list
Expand Down
2 changes: 1 addition & 1 deletion lib/seam.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_relative "seam/lts_version"
require_relative "seam/http"
require_relative "seam/http_multi_workspace"
require_relative "seam/http_without_workspace"
require_relative "seam/webhook"
require_relative "seam/wait_for_action_attempt"

Expand Down
2 changes: 1 addition & 1 deletion lib/seam/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def self.get_auth_headers_for_personal_access_token(personal_access_token, works
}
end

def self.get_auth_headers_for_multi_workspace_personal_access_token(personal_access_token)
def self.get_auth_headers_for_without_workspace_personal_access_token(personal_access_token)
if Auth.jwt?(personal_access_token)
raise SeamInvalidTokenError.new(
"A JWT cannot be used as a personal_access_token"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

module Seam
module Http
class MultiWorkspace
class WithoutWorkspace
attr_reader :client, :defaults

def initialize(personal_access_token:, endpoint: nil, wait_for_action_attempt: true, timeout: nil,
faraday_options: {}, faraday_retry_options: {})
@wait_for_action_attempt = wait_for_action_attempt
@defaults = {"wait_for_action_attempt" => wait_for_action_attempt}
@endpoint = Http::Options.get_endpoint(endpoint)
@auth_headers = Http::Auth.get_auth_headers_for_multi_workspace_personal_access_token(personal_access_token)
@auth_headers = Http::Auth.get_auth_headers_for_without_workspace_personal_access_token(personal_access_token)
@client = Http::Request.create_faraday_client(@endpoint, @auth_headers, faraday_options,
faraday_retry_options, timeout: timeout)
end
Expand All @@ -36,7 +36,8 @@ def workspaces
@workspaces ||= WorkspacesProxy.new(Seam::Clients::Workspaces.new(client: @client, defaults: @defaults))
end

def self.from_personal_access_token(personal_access_token, endpoint: nil, wait_for_action_attempt: true, timeout: nil, faraday_options: {}, faraday_retry_options: {})
def self.from_personal_access_token(personal_access_token, endpoint: nil, wait_for_action_attempt: true,
timeout: nil, faraday_options: {}, faraday_retry_options: {})
new(
personal_access_token: personal_access_token,
endpoint: endpoint,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Seam::Http::MultiWorkspace, :fake do
RSpec.describe Seam::Http::WithoutWorkspace, :fake do
describe ".from_personal_access_token" do
it "returns an instance authorized with the personal access token" do
seam = described_class.from_personal_access_token(
Expand Down
Loading