lib/github_api/orgs/teams.rb in github_api-0.9.0 vs lib/github_api/orgs/teams.rb in github_api-0.9.1

- old
+ new

@@ -15,15 +15,14 @@ # # = Examples # github = Github.new :oauth_token => '...' # github.orgs.teams.list 'org-name' # - def list(org_name, params={}) - assert_presence_of org_name - normalize! params + def list(*args) + arguments(args, :required => [:org_name]) - response = get_request("/orgs/#{org_name}/teams", params) + response = get_request("/orgs/#{org_name}/teams", arguments.params) return response unless block_given? response.each { |el| yield el } end alias :all :list @@ -31,15 +30,14 @@ # # = Examples # github = Github.new :oauth_token => '...' # github.orgs.teams.get 'team-id' # - def get(team_id, params={}) - assert_presence_of team_id - normalize! params + def get(*args) + arguments(args, :required => [:team_id]) - get_request("/teams/#{team_id}", params) + get_request("/teams/#{team_id}", arguments.params) end alias :find :get # Create a team # @@ -59,18 +57,18 @@ # "permission" => "push", # "repo_names" => [ # "github/dotfiles" # ] # - def create(org_name, params={}) - assert_presence_of org_name - normalize! params - filter! VALID_TEAM_PARAM_NAMES, params - assert_valid_values(VALID_TEAM_PARAM_VALUES, params) - assert_required_keys(%w[ name ], params) + def create(*args) + arguments(args, :required => [:org_name]) do + sift VALID_TEAM_PARAM_NAMES + assert_values VALID_TEAM_PARAM_VALUES + assert_required %w[name] + end - post_request("/orgs/#{org_name}/teams", params) + post_request("/orgs/#{org_name}/teams", arguments.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. # @@ -85,31 +83,31 @@ # github = Github.new :oauth_token => '...' # github.orgs.teams.edit 'team-id', # "name" => "new team name", # "permission" => "push" # - def edit(team_id, params={}) - assert_presence_of team_id - normalize! params - filter! VALID_TEAM_PARAM_NAMES, params - assert_valid_values(VALID_TEAM_PARAM_VALUES, params) - assert_required_keys(%w[ name ], params) + def edit(*args) + arguments(args, :required => [:team_id]) do + sift VALID_TEAM_PARAM_NAMES + assert_values VALID_TEAM_PARAM_VALUES + assert_required %w[name] + end - patch_request("/teams/#{team_id}", params) + patch_request("/teams/#{team_id}", arguments.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-id' # - def delete(team_id, params={}) - assert_presence_of team_id - normalize! params - delete_request("/teams/#{team_id}", params) + def delete(*args) + arguments(args, :required => [:team_id]) + + delete_request("/teams/#{team_id}", arguments.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. @@ -117,15 +115,14 @@ # = Examples # github = Github.new :oauth_token => '...' # github.orgs.teams.list_members 'team-id' # github.orgs.teams.list_members 'team-id' { |member| ... } # - def list_members(team_id, params={}) - assert_presence_of team_id - normalize! params + def list_members(*args) + arguments(args, :required => [:team_id]) - response = get_request("/teams/#{team_id}/members", params) + response = get_request("/teams/#{team_id}/members", arguments.params) return response unless block_given? response.each { |el| yield el } end alias :all_members :list_members @@ -133,14 +130,14 @@ # # = Examples # github = Github.new :oauth_token => '...' # github.orgs.teams.team_member? 'team-id', 'user-name' # - def team_member?(team_id, user_name, params={}) - assert_presence_of team_id, user_name - normalize! params - response = get_request("/teams/#{team_id}/members/#{user_name}", params) + def team_member?(*args) + arguments(args, :required => [:team_id, :user]) + + response = get_request("/teams/#{team_id}/members/#{user}", arguments.params) response.status == 204 rescue Github::Error::NotFound false end @@ -149,14 +146,14 @@ # # = Examples # github = Github.new :oauth_token => '...' # github.orgs.teams.add_member 'team-id', 'user-name' # - def add_member(team_id, user_name, params={}) - assert_presence_of team_id, user_name - normalize! params - put_request("/teams/#{team_id}/members/#{user_name}", params) + def add_member(*args) + arguments(args, :required => [:team_id, :user]) + + put_request("/teams/#{team_id}/members/#{user}", arguments.params) end alias :add_team_member :add_member # Remove a team member # @@ -167,28 +164,27 @@ # # = Examples # github = Github.new :oauth_token => '...' # github.orgs.teams.remove_member 'team-id', 'user-name' # - def remove_member(team_id, user_name, params={}) - assert_presence_of team_id, user_name - normalize! params - delete_request("/teams/#{team_id}/members/#{user_name}", params) + def remove_member(*args) + arguments(args, :required => [:team_id, :user]) + + delete_request("/teams/#{team_id}/members/#{user}", arguments.params) end alias :remove_team_member :remove_member # List team repositories # # = Examples # github = Github.new :oauth_token => '...' # github.orgs.teams.list_repos 'team-id' # - def list_repos(team_id, params={}) - assert_presence_of team_id - normalize! params + def list_repos(*args) + arguments(args, :required => [:team_id]) - response = get_request("/teams/#{team_id}/repos", params) + response = get_request("/teams/#{team_id}/repos", arguments.params) return response unless block_given? response.each { |el| yield el } end alias :repos :list_repos @@ -196,14 +192,14 @@ # # = Examples # github = Github.new :oauth_token => '...' # github.orgs.teams.team_repo? 'team-id', 'user-name', 'repo-name' # - def team_repo?(team_id, user_name, repo_name, params={}) - assert_presence_of team_id, user_name, repo_name - normalize! params - response = get_request("/teams/#{team_id}/repos/#{user_name}/#{repo_name}", params) + def team_repo?(*args) + arguments(args, :required => [:team_id, :user, :repo]) + + response = get_request("/teams/#{team_id}/repos/#{user}/#{repo}", arguments.params) response.status == 204 rescue Github::Error::NotFound false end alias :team_repository? :team_repo? @@ -217,14 +213,14 @@ # # = Examples # github = Github.new :oauth_token => '...' # github.orgs.teams.add_repo 'team-id', 'user-name', 'repo-name' # - def add_repo(team_id, user_name, repo_name, params={}) - assert_presence_of team_id, user_name, repo_name - normalize! params - put_request("/teams/#{team_id}/repos/#{user_name}/#{repo_name}", params) + def add_repo(*args) + arguments(args, :required => [:team_id, :user, :repo]) + + put_request("/teams/#{team_id}/repos/#{user}/#{repo}", arguments.params) end alias :add_repository :add_repo # Remove a team repository # @@ -234,13 +230,13 @@ # # = Examples # github = Github.new :oauth_token => '...' # github.orgs.teams.remove_repo 'team-id', 'user-name', 'repo-name' # - def remove_repo(team_id, user_name, repo_name, params={}) - assert_presence_of team_id, user_name, repo_name - normalize! params - delete_request("/teams/#{team_id}/repos/#{user_name}/#{repo_name}", params) + def remove_repo(*args) + arguments(args, :required => [:team_id, :user, :repo]) + + delete_request("/teams/#{team_id}/repos/#{user}/#{repo}", arguments.params) end alias :remove_repository :remove_repo end # Orgs::Teams end # Github