Module: Keybase::Local::Team

Defined in:
lib/keybase/local/team.rb

Overview

Represents Keybase’s JSON team API.

Constant Summary collapse

TEAM_EXEC_ARGS =

The initial arguments to pass when executing Keybase for team management.

%w[keybase team api].freeze

Class Method Summary collapse

Class Method Details

.add_members(team, emails: [], users: []) ⇒ OpenStruct

Add members to a team.

Examples:

Keybase::Local::Team.add_members "foo", users: [{ username: "bob", role: "reader" }]
Keybase::Local::Team.add_members "bar", emails: [{ email: "[email protected]", role: "admin" }]

Parameters:

  • team (String)

    the team name

  • emails (Array<Hash>) (defaults to: [])

    a list of email-role hashes to add to the team

  • users (Array<Hash>) (defaults to: [])

    a list of Keybase user-role hashes to add to the team

Returns:

  • (OpenStruct)

    a struct mapping of the JSON response

Raises:



106
107
108
109
110
111
112
# File 'lib/keybase/local/team.rb', line 106

def add_members(team, emails: [], users: [])
  team_call "add-members", options: {
    team: team,
    emails: emails,
    usernames: users,
  }
end

.create_team(team) ⇒ OpenStruct

Create a new team.

Parameters:

  • team (String)

    the team name

Returns:

  • (OpenStruct)

    a struct mapping of the JSON response

Raises:



91
92
93
94
95
# File 'lib/keybase/local/team.rb', line 91

def create_team(team)
  team_call "create-team", options: {
    team: team,
  }
end

.edit_member(team, user, role) ⇒ OpenStruct

Edit the role of a user on a team.

Examples:

Keybase::Local::Team.edit_member "foo", "bob", "reader"

Parameters:

  • team (String)

    the team name

  • user (String)

    the Keybase user to edit

  • role (String)

    the user’s new role

Returns:

  • (OpenStruct)

    a struct mapping of the JSON response

Raises:



122
123
124
125
126
127
128
# File 'lib/keybase/local/team.rb', line 122

def edit_member(team, user, role)
  team_call "edit-member", options: {
    team: team,
    username: user,
    role: role,
  }
end

.envelope(meth, options: {}) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the JSON serialized envelope.

Parameters:

  • meth (Symbol)

    the team method

  • options (Hash) (defaults to: {})

    the options hash

Returns:

  • (String)

    the JSON serialized envelope



19
20
21
22
23
24
25
26
# File 'lib/keybase/local/team.rb', line 19

def envelope(meth, options: {})
  {
    method: meth,
    params: {
      options: options,
    },
  }.to_json
end

.leave_team(team, permanent: false) ⇒ OpenStruct

Leave a team.

Parameters:

  • team (String)

    the team name

  • permanent (Boolean) (defaults to: false)

    whether or not to leave the team permanently

Returns:

  • (OpenStruct)

    a struct mapping of the JSON response

Raises:



161
162
163
164
165
166
# File 'lib/keybase/local/team.rb', line 161

def leave_team(team, permanent: false)
  team_call "leave-team", options: {
    team: team,
    permanent: permanent,
  }
end

.list_self_membershipsOpenStruct Also known as: self_memberships

List all team memberships for the current user.

Returns:

  • (OpenStruct)

    a struct mapping of the JSON response

Raises:



57
58
59
# File 'lib/keybase/local/team.rb', line 57

def list_self_memberships
  team_call "list-self-memberships"
end

.list_team_memberships(team) ⇒ OpenStruct Also known as: team_memberships

List all users in the given team.

Parameters:

  • team (String)

    the team to list

Returns:

  • (OpenStruct)

    a struct mapping of the JSON response

Raises:



67
68
69
70
71
# File 'lib/keybase/local/team.rb', line 67

def list_team_memberships(team)
  team_call "list-team-memberships", options: {
    team: team,
  }
end

.list_user_memberships(user) ⇒ OpenStruct Also known as: user_memberships

List teams for a user.

Parameters:

  • user (String)

    a Keybase username

Returns:

  • (OpenStruct)

    a struct mapping of the JSON response

Raises:



79
80
81
82
83
# File 'lib/keybase/local/team.rb', line 79

def list_user_memberships(user)
  team_call "list-user-memberships", options: {
    username: user,
  }
end

.remove_member(team, user) ⇒ OpenStruct

Remove a user from a team.

Parameters:

  • team (String)

    the team name

  • user (String)

    the Keybase user to remove

Returns:

  • (OpenStruct)

    a struct mapping of the JSON response

Raises:



135
136
137
138
139
140
# File 'lib/keybase/local/team.rb', line 135

def remove_member(team, user)
  team_call "remove-member", options: {
    team: team,
    username: user,
  }
end

.rename_subteam(old_name, new_name) ⇒ OpenStruct

Rename a subteam.

Examples:

Keybase::Local::Team.rename_subteam "foo.bar", "foo.baz"

Parameters:

  • old_name (String)

    the subteam’s current name

  • new_name (String)

    the subteam’s new name

Returns:

  • (OpenStruct)

    a struct mapping of the JSON response

Raises:



149
150
151
152
153
154
# File 'lib/keybase/local/team.rb', line 149

def rename_subteam(old_name, new_name)
  team_call "rename-subteam", options: {
    team: old_name,
    "new-team-name": new_name,
  }
end

.team_call(meth, options: {}) ⇒ OpenStruct

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Makes team API calls.

Parameters:

  • meth (String, Symbol)

    the team method

  • options (Hash) (defaults to: {})

    the options hash

Returns:

  • (OpenStruct)

    a struct mapping on the JSON response



44
45
46
47
48
49
50
51
52
# File 'lib/keybase/local/team.rb', line 44

def team_call(meth, options: {})
  response = Open3.popen3(*TEAM_EXEC_ARGS) do |stdin, stdout, _, _|
    stdin.write envelope meth, options: options
    stdin.close
    stdout.read
  end

  unwrap JSON.parse response, object_class: OpenStruct
end

.unwrap(struct) ⇒ OpenStruct

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Cleans up the object returned by team_call.

Parameters:

  • struct (OpenStruct)

    a structified response from the Keybase team API

Returns:

  • (OpenStruct)

    an unwrapped version of the response

Raises:



33
34
35
36
37
# File 'lib/keybase/local/team.rb', line 33

def unwrap(struct)
  raise Exceptions::TeamError, struct.error.message if struct.error

  struct.result
end