Sha256: dbfe3d7e76620ff9b44d9a5f067f7e52217a8e0aa582769c2b71e68173843330

Contents?: true

Size: 1.74 KB

Versions: 5

Compression:

Stored size: 1.74 KB

Contents

# encoding: utf-8

module Github
  class Repos
    module Collaborators
      
      # Add collaborator
      #
      # Examples:
      #  @github = Github.new
      #  @github.collaborators.add_collaborator('user', 'repo', 'collaborator') 
      #
      #  @repos = Github::Repos.new
      #  @repos.add_collaborator('user', 'repo', 'collaborator')
      #
      def add_collaborator(user, repo, collaborator)
        put("/repos/#{user}/#{repo}/collaborators/#{collaborator}")
      end
      
      
      # Checks if user is a collaborator for a given repository
      #
      # Examples:
      #  @github = Github.new
      #  @github.collaborators.collaborator?('user', 'repo', 'collaborator')
      #
      def collaborator?(user_name, repo_name, collaborator)
        get("/repos/#{user}/#{repo}/collaborators/#{collaborator}")
      end

      # List collaborators
      #
      # Examples:
      #   @github = Github.new
      #   @github.repos.collaborators('user-name', 'repo-name')
      #   @github.repos.collaborators('user-name', 'repo-name') { |cbr| .. }
      #
      def collaborators(user_name=nil, repo_name=nil)
        _update_user_repo_params(user_name, repo_name)      
        _validate_user_repo_params(user, repo) unless (user? && repo?)
        
        response = get("/repos/#{user}/#{repo}/collaborators")
        return response unless block_given?
        response.each { |el| yield el }
      end
      
      # Removes collaborator
      #
      # Examples:
      #  @github = Github.new
      #  @github.collaborators.remove('user', 'repo', 'collaborator')
      #
      def remove_collabolator(user, repo, collaborator) 
        delete("/repos/#{user}/#{repo}/collaborators/#{user}")
      end

    end # Collaborators
  end # Repos
end # Github

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
github_api-0.2.0 lib/github_api/repos/collaborators.rb
github_api-0.1.2 lib/github_api/repos/collaborators.rb
github_api-0.1.1 lib/github_api/repos/collaborators.rb
github_api-0.1.0 lib/github_api/repos/collaborators.rb
github_api-0.1.0.pre lib/github_api/repos/collaborators.rb