lib/github_api/orgs/teams.rb in github_api-0.4.11 vs lib/github_api/orgs/teams.rb in github_api-0.5.0.rc1
- old
+ new
@@ -1,244 +1,243 @@
# encoding: utf-8
module Github
- class Orgs
+ class Orgs::Teams < API
# All actions against teams require at a minimum an authenticated user
# who is a member of the owner’s team in the :org being managed.
# Api calls that require explicit permissions are noted.
- module Teams
- VALID_TEAM_PARAM_NAMES = %w[ name repo_names permission ].freeze
- VALID_TEAM_PARAM_VALUES = {
- 'permission' => %w[ pull push admin ].freeze
- }
+ VALID_TEAM_PARAM_NAMES = %w[ name repo_names permission ].freeze
+ VALID_TEAM_PARAM_VALUES = {
+ 'permission' => %w[ pull push admin ].freeze
+ }
- # List teams
- #
- # = Examples
- # @github = Github.new :oauth_token => '...'
- # @github.orgs.teams 'org-name'
- #
- def teams(org_name, params={})
- _validate_presence_of org_name
- _normalize_params_keys(params)
+ # List teams
+ #
+ # = Examples
+ # github = Github.new :oauth_token => '...'
+ # github.orgs.teams.list 'org-name'
+ #
+ def list(org_name, params={})
+ _validate_presence_of org_name
+ _normalize_params_keys(params)
- response = get("/orgs/#{org_name}/teams", params)
- return response unless block_given?
- response.each { |el| yield el }
- end
- alias :list_teams :teams
+ response = get_request("/orgs/#{org_name}/teams", params)
+ return response unless block_given?
+ response.each { |el| yield el }
+ end
+ alias :all :list
- # Get a team
- #
- # = Examples
- # @github = Github.new :oauth_token => '...'
- # @github.orgs.team 'team-name'
- #
- def team(team_name, params={})
- _validate_presence_of team_name
- _normalize_params_keys(params)
+ # Get a team
+ #
+ # = Examples
+ # github = Github.new :oauth_token => '...'
+ # github.orgs.teams.get 'team-name'
+ #
+ def get(team_name, params={})
+ _validate_presence_of team_name
+ _normalize_params_keys(params)
- get("/teams/#{team_name}", params)
- end
- alias :get_team :team
+ get_request("/teams/#{team_name}", params)
+ end
+ alias :find :get
- # Create a team
- #
- # In order to create a team, the authenticated user must be an owner of<tt>:org</tt>.
- # = Inputs
- # <tt>:name</tt> - Required string
- # <tt>:repo_names</tt> - Optional array of strings
- # <tt>:permission</tt> - Optional string
- # * <tt>pull</tt> - team members can pull, but not push or administor this repositories. Default
- # * <tt>push</tt> - team members can pull and push, but not administor this repositores.
- # * <tt>admin</tt> - team members can pull, push and administor these repositories.
- #
- # = Examples
- # @github = Github.new :oauth_token => '...'
- # @github.orgs.create_team 'org-name',
- # "name" => "new team",
- # "permission" => "push",
- # "repo_names" => [
- # "github/dotfiles"
- # ]
- #
- def create_team(org_name, params={})
- _validate_presence_of org_name
- _normalize_params_keys(params)
- _filter_params_keys(VALID_TEAM_PARAM_NAMES, params)
- _validate_params_values(VALID_TEAM_PARAM_VALUES, params)
- _validate_inputs(%w[ name ], params)
+ # Create a team
+ #
+ # In order to create a team, the authenticated user must be an owner of<tt>:org</tt>.
+ # = Inputs
+ # <tt>:name</tt> - Required string
+ # <tt>:repo_names</tt> - Optional array of strings
+ # <tt>:permission</tt> - Optional string
+ # * <tt>pull</tt> - team members can pull, but not push or administor this repositories. Default
+ # * <tt>push</tt> - team members can pull and push, but not administor this repositores.
+ # * <tt>admin</tt> - team members can pull, push and administor these repositories.
+ #
+ # = Examples
+ # github = Github.new :oauth_token => '...'
+ # github.orgs.teams.create 'org-name',
+ # "name" => "new team",
+ # "permission" => "push",
+ # "repo_names" => [
+ # "github/dotfiles"
+ # ]
+ #
+ def create(org_name, params={})
+ _validate_presence_of org_name
+ _normalize_params_keys(params)
+ _filter_params_keys(VALID_TEAM_PARAM_NAMES, params)
+ _validate_params_values(VALID_TEAM_PARAM_VALUES, params)
+ _validate_inputs(%w[ name ], params)
- post("/orgs/#{org_name}/teams", params)
- end
+ post_request("/orgs/#{org_name}/teams", params)
+ end
- # Edit a team
- # In order to edit a team, the authenticated user must be an owner of the org that the team is associated with.
- #
- # = Inputs
- # <tt>:name</tt> - Required string
- # <tt>:permission</tt> - Optional string
- # * <tt>pull</tt> - team members can pull, but not push or administor this repositories. Default
- # * <tt>push</tt> - team members can pull and push, but not administor this repositores.
- # * <tt>admin</tt> - team members can pull, push and administor these repositories.
- #
- # = Examples
- # @github = Github.new :oauth_token => '...'
- # @github.orgs.edit_team 'team-name',
- # "name" => "new team name",
- # "permission" => "push"
- #
- def edit_team(team_name, params={})
- _validate_presence_of team_name
- _normalize_params_keys(params)
+ # Edit a team
+ # In order to edit a team, the authenticated user must be an owner of the org that the team is associated with.
+ #
+ # = Inputs
+ # <tt>:name</tt> - Required string
+ # <tt>:permission</tt> - Optional string
+ # * <tt>pull</tt> - team members can pull, but not push or administor this repositories. Default
+ # * <tt>push</tt> - team members can pull and push, but not administor this repositores.
+ # * <tt>admin</tt> - team members can pull, push and administor these repositories.
+ #
+ # = Examples
+ # github = Github.new :oauth_token => '...'
+ # github.orgs.teams.edit 'team-name',
+ # "name" => "new team name",
+ # "permission" => "push"
+ #
+ def edit(team_name, params={})
+ _validate_presence_of team_name
+ _normalize_params_keys(params)
- _filter_params_keys(VALID_TEAM_PARAM_NAMES, params)
- _validate_params_values(VALID_TEAM_PARAM_VALUES, params)
- _validate_inputs(%w[ name ], params)
+ _filter_params_keys(VALID_TEAM_PARAM_NAMES, params)
+ _validate_params_values(VALID_TEAM_PARAM_VALUES, params)
+ _validate_inputs(%w[ name ], params)
- patch("/teams/#{team_name}", params)
- end
+ patch_request("/teams/#{team_name}", params)
+ end
- # Delete a team
- # In order to delete a team, the authenticated user must be an owner of the org that the team is associated with
- #
- # = Examples
- # @github = Github.new :oauth_token => '...'
- # @github.orgs.delete_team 'team-name'
- #
- def delete_team(team_name, params={})
- _validate_presence_of team_name
- _normalize_params_keys(params)
- delete("/teams/#{team_name}", params)
- end
+ # Delete a team
+ # In order to delete a team, the authenticated user must be an owner of the org that the team is associated with
+ #
+ # = Examples
+ # github = Github.new :oauth_token => '...'
+ # github.orgs.teams.delete 'team-name'
+ #
+ def delete(team_name, params={})
+ _validate_presence_of team_name
+ _normalize_params_keys(params)
+ delete_request("/teams/#{team_name}", params)
+ end
+ alias :remove :delete
- # List team members
- # In order to list members in a team, the authenticated user must be a member of the team.
- #
- # = Examples
- # @github = Github.new :oauth_token => '...'
- # @github.orgs.team_members 'team-name'
- # @github.orgs.team_members 'team-name' { |member| ... }
- #
- def team_members(team_name, params={})
- _validate_presence_of team_name
- _normalize_params_keys(params)
+ # List team members
+ # In order to list members in a team, the authenticated user must be a member of the team.
+ #
+ # = Examples
+ # github = Github.new :oauth_token => '...'
+ # github.orgs.teams.list_members 'team-name'
+ # github.orgs.teams.list_members 'team-name' { |member| ... }
+ #
+ def list_members(team_name, params={})
+ _validate_presence_of team_name
+ _normalize_params_keys(params)
- response = get("/teams/#{team_name}/members", params)
- return response unless block_given?
- response.each { |el| yield el }
- end
- alias :list_team_members :team_members
+ response = get_request("/teams/#{team_name}/members", params)
+ return response unless block_given?
+ response.each { |el| yield el }
+ end
+ alias :all_members :list_members
- # Check if a user is a member of a team
- #
- # = Examples
- # @github = Github.new :oauth_token => '...'
- # @github.orgs.team_member? 'team-name', 'user-name'
- #
- def team_member?(team_name, member_name, params={})
- _validate_presence_of team_name, member_name
- _normalize_params_keys(params)
- get("/teams/#{team_name}/members/#{member_name}", params)
- true
- rescue Github::Error::NotFound
- false
- end
+ # Check if a user is a member of a team
+ #
+ # = Examples
+ # github = Github.new :oauth_token => '...'
+ # github.orgs.teams.team_member? 'team-name', 'user-name'
+ #
+ def team_member?(team_name, member_name, params={})
+ _validate_presence_of team_name, member_name
+ _normalize_params_keys(params)
+ get_request("/teams/#{team_name}/members/#{member_name}", params)
+ true
+ rescue Github::Error::NotFound
+ false
+ end
- # Add a team member
- # In order to add a user to a team, the authenticated user must have ‘admin’ permissions to the team or be an owner of the org that the team is associated with.
- #
- # = Examples
- # @github = Github.new :oauth_token => '...'
- # @github.orgs.add_team_member 'team-name', 'user-name'
- #
- def add_team_member(team_name, member_name, params={})
- _validate_presence_of team_name, member_name
- _normalize_params_keys(params)
- put("/teams/#{team_name}/members/#{member_name}", params)
- end
- alias :add_member :add_team_member
+ # Add a team member
+ # In order to add a user to a team, the authenticated user must have ‘admin’ permissions to the team or be an owner of the org that the team is associated with.
+ #
+ # = Examples
+ # github = Github.new :oauth_token => '...'
+ # github.orgs.teams.add_member 'team-name', 'user-name'
+ #
+ def add_member(team_name, member_name, params={})
+ _validate_presence_of team_name, member_name
+ _normalize_params_keys(params)
+ put_request("/teams/#{team_name}/members/#{member_name}", params)
+ end
+ alias :add_team_member :add_member
- # Remove a team member
- # In order to remove a user from a team, the authenticated user must
- # have ‘admin’ permissions to the team or be an owner of the org that
- # the team is associated with.
- # note: This does not delete the user, it just remove them from the team.
- #
- # = Examples
- # @github = Github.new :oauth_token => '...'
- # @github.orgs.remove_team_member 'team-name', 'member-name'
- #
- def remove_team_member(team_name, member_name, params={})
- _validate_presence_of team_name, member_name
- _normalize_params_keys(params)
- delete("/teams/#{team_name}/members/#{member_name}", params)
- end
- alias :remove_member :remove_team_member
+ # Remove a team member
+ # In order to remove a user from a team, the authenticated user must
+ # have ‘admin’ permissions to the team or be an owner of the org that
+ # the team is associated with.
+ # note: This does not delete the user, it just remove them from the team.
+ #
+ # = Examples
+ # github = Github.new :oauth_token => '...'
+ # github.orgs.teams.remove_member 'team-name', 'member-name'
+ #
+ def remove_member(team_name, member_name, params={})
+ _validate_presence_of team_name, member_name
+ _normalize_params_keys(params)
+ delete_request("/teams/#{team_name}/members/#{member_name}", params)
+ end
+ alias :remove_team_member :remove_member
- # List team repositories
- #
- # = Examples
- # @github = Github.new :oauth_token => '...'
- # @github.orgs.team_repos 'team-name'
- #
- def team_repos(team_name, params={})
- _validate_presence_of team_name
- _normalize_params_keys(params)
+ # List team repositories
+ #
+ # = Examples
+ # github = Github.new :oauth_token => '...'
+ # github.orgs.teams.list_repos 'team-name'
+ #
+ def list_repos(team_name, params={})
+ _validate_presence_of team_name
+ _normalize_params_keys(params)
- response = get("/teams/#{team_name}/repos", params)
- return response unless block_given?
- response.each { |el| yield el }
- end
- alias :team_repositories :team_repos
+ response = get_request("/teams/#{team_name}/repos", params)
+ return response unless block_given?
+ response.each { |el| yield el }
+ end
+ alias :repos :list_repos
- # Check if a repository belongs to a team
- #
- # = Examples
- # @github = Github.new :oauth_token => '...'
- # @github.orgs.team_repo? 'team-name', 'user-name', 'repo-name'
- #
- def team_repo?(team_name, user_name, repo_name, params={})
- _validate_presence_of team_name, user_name, repo_name
- _normalize_params_keys(params)
- get("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
- true
- rescue Github::Error::NotFound
- false
- end
- alias :team_repository? :team_repo?
+ # Check if a repository belongs to a team
+ #
+ # = Examples
+ # github = Github.new :oauth_token => '...'
+ # github.orgs.teams.team_repo? 'team-name', 'user-name', 'repo-name'
+ #
+ def team_repo?(team_name, user_name, repo_name, params={})
+ _validate_presence_of team_name, user_name, repo_name
+ _normalize_params_keys(params)
+ get_request("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
+ true
+ rescue Github::Error::NotFound
+ false
+ end
+ alias :team_repository? :team_repo?
- # Add a team repository
- # In order to add a repo to a team, the authenticated user must be
- # an owner of the org that the team is associated with.
- #
- # = Examples
- # @github = Github.new :oauth_token => '...'
- # @github.orgs.add_team_repo 'team-name', 'user-name', 'repo-name'
- #
- def add_team_repo(team_name, user_name, repo_name, params={})
- _validate_presence_of team_name, user_name, repo_name
- _normalize_params_keys(params)
- put("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
- end
- alias :add_team_repository :add_team_repo
+ # Add a team repository
+ # In order to add a repo to a team, the authenticated user must be
+ # an owner of the org that the team is associated with.
+ #
+ # = Examples
+ # github = Github.new :oauth_token => '...'
+ # github.orgs.teams.add_repo 'team-name', 'user-name', 'repo-name'
+ #
+ def add_repo(team_name, user_name, repo_name, params={})
+ _validate_presence_of team_name, user_name, repo_name
+ _normalize_params_keys(params)
+ put_request("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
+ end
+ alias :add_repository :add_repo
- # Remove a team repository
- # In order to add a repo to a team, the authenticated user must be
- # an owner of the org that the team is associated with.
- # note: This does not delete the repo, it just removes it from the team.
- #
- # = Examples
- # @github = Github.new :oauth_token => '...'
- # @github.orgs.remove_team_repo 'team-name', 'user-name', 'repo-name'
- #
- def remove_team_repo(team_name, user_name, repo_name, params={})
- _validate_presence_of team_name, user_name, repo_name
- _normalize_params_keys(params)
- delete("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
- end
- alias :remove_team_repository :remove_team_repo
+ # Remove a team repository
+ # In order to add a repo to a team, the authenticated user must be
+ # an owner of the org that the team is associated with.
+ # note: This does not delete the repo, it just removes it from the team.
+ #
+ # = Examples
+ # github = Github.new :oauth_token => '...'
+ # github.orgs.teams.remove_repo 'team-name', 'user-name', 'repo-name'
+ #
+ def remove_repo(team_name, user_name, repo_name, params={})
+ _validate_presence_of team_name, user_name, repo_name
+ _normalize_params_keys(params)
+ delete_request("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
+ end
+ alias :remove_repository :remove_repo
- end # Teams
- end # Orgs
+ end # Orgs::Teams
end # Github