Class: ScreenshotFreeAPI::Resources::Workspaces

Inherits:
Object
  • Object
show all
Defined in:
lib/screenshotfreeapi/resources/workspaces.rb

Overview

Team workspace management.

Workspaces allow multiple users to share API keys and collaborate. All methods require a management JWT (from Auth#token) passed as ‘jwt:`.

Member roles: “owner” | “admin” | “member” | “viewer”

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Workspaces

Returns a new instance of Workspaces.



12
13
14
# File 'lib/screenshotfreeapi/resources/workspaces.rb', line 12

def initialize(http)
  @http = http
end

Instance Method Details

#create(jwt:, name:, **options) ⇒ Hash

Create a new workspace.

Parameters:

  • jwt (String)

    Management JWT

  • name (String)

    Workspace display name

Returns:

  • (Hash)

    Workspace object



22
23
24
25
# File 'lib/screenshotfreeapi/resources/workspaces.rb', line 22

def create(jwt:, name:, **options)
  body = { name: name }.merge(options)
  @http.request(:post, "/workspaces", body: body, auth_header: "Bearer #{jwt}")
end

#get(jwt:, workspace_id:) ⇒ Hash

Get a single workspace with its members list.

Parameters:

  • jwt (String)

    Management JWT

  • workspace_id (String)

    Workspace ID

Returns:

  • (Hash)

    Workspace object including “members” array



42
43
44
# File 'lib/screenshotfreeapi/resources/workspaces.rb', line 42

def get(jwt:, workspace_id:)
  @http.request(:get, "/workspaces/#{workspace_id}", auth_header: "Bearer #{jwt}")
end

#invite(jwt:, workspace_id:, email:, role: "member") ⇒ Hash

Invite a user to the workspace by email address.

Parameters:

  • jwt (String)
  • workspace_id (String)
  • email (String)

    Email of the person to invite

  • role (String) (defaults to: "member")

    “admin” | “member” | “viewer”

Returns:

  • (Hash)

    Invitation object



54
55
56
57
58
59
60
61
# File 'lib/screenshotfreeapi/resources/workspaces.rb', line 54

def invite(jwt:, workspace_id:, email:, role: "member")
  @http.request(
    :post,
    "/workspaces/#{workspace_id}/invite",
    body:        { email: email, role: role },
    auth_header: "Bearer #{jwt}"
  )
end

#list(jwt:) ⇒ Array<Hash>

List workspaces the authenticated user belongs to.

Parameters:

  • jwt (String)

    Management JWT

Returns:

  • (Array<Hash>)

    Array of workspace objects



32
33
34
# File 'lib/screenshotfreeapi/resources/workspaces.rb', line 32

def list(jwt:)
  @http.request(:get, "/workspaces", auth_header: "Bearer #{jwt}")
end

#remove_member(jwt:, workspace_id:, user_id:) ⇒ Hash

Remove a member from the workspace.

Parameters:

  • jwt (String)
  • workspace_id (String)
  • user_id (String)

    ID of the member to remove

Returns:

  • (Hash)

    Confirmation object



70
71
72
73
74
75
76
# File 'lib/screenshotfreeapi/resources/workspaces.rb', line 70

def remove_member(jwt:, workspace_id:, user_id:)
  @http.request(
    :delete,
    "/workspaces/#{workspace_id}/members/#{user_id}",
    auth_header: "Bearer #{jwt}"
  )
end

#update_member(jwt:, workspace_id:, user_id:, role:) ⇒ Hash

Change a member’s role within the workspace.

Parameters:

  • jwt (String)
  • workspace_id (String)
  • user_id (String)
  • role (String)

    New role: “admin” | “member” | “viewer”

Returns:

  • (Hash)

    Updated member object



86
87
88
89
90
91
92
93
# File 'lib/screenshotfreeapi/resources/workspaces.rb', line 86

def update_member(jwt:, workspace_id:, user_id:, role:)
  @http.request(
    :patch,
    "/workspaces/#{workspace_id}/members/#{user_id}",
    body:        { role: role },
    auth_header: "Bearer #{jwt}"
  )
end