Class: GitHubV3API::ReposAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/github_v3_api/repos_api.rb

Overview

Provides access to the GitHub Repos API (developer.github.com/v3/repos/)

example:

api = GitHubV3API.new(ACCESS_TOKEN)

# get list of all of the user's public and private repos
repos = api.repos.list
#=> returns an array of GitHubV3API::Repo instances

repo = api.repos.get('octocat', 'hello-world')
#=> returns an instance of GitHubV3API::Repo

repo.name
#=> 'hello-world'

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ ReposAPI

Typically not used directly. Use GitHubV3API#repos instead.

connection

an instance of GitHubV3API



23
24
25
# File 'lib/github_v3_api/repos_api.rb', line 23

def initialize(connection)
  @connection = connection
end

Instance Method Details

#get(user, repo_name) ⇒ Object

Returns a GitHubV3API::Repo instance for the specified user and repo_name.

user

the string ID of the user, e.g. “octocat”

repo_name

the string ID of the repository, e.g. “hello-world”



40
41
42
43
44
45
# File 'lib/github_v3_api/repos_api.rb', line 40

def get(user, repo_name)
  org_data = @connection.get("/repos/#{user}/#{repo_name}")
  GitHubV3API::Repo.new_with_all_data(self, org_data)
rescue RestClient::ResourceNotFound
  raise NotFound, "The repository #{user}/#{repo_name} does not exist or is not visible to the user."
end

#listObject

Returns an array of GitHubV3API::Repo instances representing the user’s public and private repos



29
30
31
32
33
# File 'lib/github_v3_api/repos_api.rb', line 29

def list
  @connection.get('/user/repos').map do |repo_data|
    GitHubV3API::Repo.new(self, repo_data)
  end
end

#list_collaborators(user, repo_name) ⇒ Object

Returns an array of GitHubV3API::User instances for the collaborators of the specified user and repo_name.

user

the string ID of the user, e.g. “octocat”

repo_name

the string ID of the repository, e.g. “hello-world”



52
53
54
55
56
# File 'lib/github_v3_api/repos_api.rb', line 52

def list_collaborators(user, repo_name)
  @connection.get("/repos/#{user}/#{repo_name}/collaborators").map do |user_data|
    GitHubV3API::User.new(@connection.users, user_data)
  end
end

#list_forks(user, repo_name) ⇒ Object

Returns an array of GitHubV3API::Repo instances containing the repositories which were forked from the repository specified by user and repo_name.

user

the string ID of the user, e.g. “octocat”

repo_name

the string ID of the repository, e.g. “hello-world”



74
75
76
77
78
# File 'lib/github_v3_api/repos_api.rb', line 74

def list_forks(user, repo_name)
  @connection.get("/repos/#{user}/#{repo_name}/forks").map do |repo_data|
    GitHubV3API::Repo.new(self, repo_data)
  end
end

#list_watchers(user, repo_name) ⇒ Object

Returns an array of GitHubV3API::User instances containing the users who are watching the repository specified by user and repo_name.

user

the string ID of the user, e.g. “octocat”

repo_name

the string ID of the repository, e.g. “hello-world”



63
64
65
66
67
# File 'lib/github_v3_api/repos_api.rb', line 63

def list_watchers(user, repo_name)
  @connection.get("/repos/#{user}/#{repo_name}/watchers").map do |user_data|
    GitHubV3API::User.new(@connection.users, user_data)
  end
end