module Keybase::Local::Team
Represents Keybase's JSON team API.
Constants
- TEAM_EXEC_ARGS
The initial arguments to pass when executing
Keybase
for team management.
Public Class Methods
Add members to a team. @param team [String] the team name @param emails [Array<Hash>] a list of email-role hashes to add to the team @param users [Array<Hash>] a list of Keybase
user-role hashes to add to the team @return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::TeamError] if the team call fails @example
Keybase::Local::Team.add_members "foo", users: [{ username: "bob", role: "reader" }] Keybase::Local::Team.add_members "bar", emails: [{ email: "foo@bar.com", role: "admin" }]
# 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 a new team. @param team [String] the team name @return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::TeamError] if the team call fails
# File lib/keybase/local/team.rb, line 91 def create_team(team) team_call "create-team", options: { team: team, } end
Edit the role of a user on a team. @param team [String] the team name @param user [String] the Keybase
user to edit @param role [String] the user's new role @return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::TeamError] if the team call fails @example
Keybase::Local::Team.edit_member "foo", "bob", "reader"
# 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
@param meth [Symbol] the team method @param options [Hash] the options hash @return [String] the JSON serialized envelope @api private
# File lib/keybase/local/team.rb, line 19 def envelope(meth, options: {}) { method: meth, params: { options: options, }, }.to_json end
Leave a team. @param team [String] the team name @param permanent [Boolean] whether or not to leave the team permanently @return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::TeamError] if the team call fails
# 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 all team memberships for the current user. @return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::TeamError] if the team call fails
# File lib/keybase/local/team.rb, line 57 def list_self_memberships team_call "list-self-memberships" end
List all users in the given team. @param team [String] the team to list @return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::TeamError] if the team call fails
# File lib/keybase/local/team.rb, line 67 def list_team_memberships(team) team_call "list-team-memberships", options: { team: team, } end
List teams for a user. @param user [String] a Keybase
username @return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::TeamError] if the team call fails
# File lib/keybase/local/team.rb, line 79 def list_user_memberships(user) team_call "list-user-memberships", options: { username: user, } end
Remove a user from a team. @param team [String] the team name @param user [String] the Keybase
user to remove @return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::TeamError] if the team call fails
# File lib/keybase/local/team.rb, line 135 def remove_member(team, user) team_call "remove-member", options: { team: team, username: user, } end
Rename a subteam. @param old_name [String] the subteam's current name @param new_name [String] the subteam's new name @return [OpenStruct] a struct mapping of the JSON response @raise [Exceptions::TeamError] if the team call fails @example
Keybase::Local::Team.rename_subteam "foo.bar", "foo.baz"
# 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
Makes team API calls. @param meth [String, Symbol] the team method @param options [Hash] the options hash @return [OpenStruct] a struct mapping on the JSON response @api private
# 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
Cleans up the object returned by {team_call}. @param struct [OpenStruct] a structified response from the Keybase
team API @return [OpenStruct] an unwrapped version of the response @raise [Exceptions::TeamError] when the struct contains an error message @api private
# File lib/keybase/local/team.rb, line 33 def unwrap(struct) raise Exceptions::TeamError, struct.error.message if struct.error struct.result end