Class: GitHubV3API::ReposAPI
- Inherits:
-
Object
- Object
- GitHubV3API::ReposAPI
- 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
-
#get(user, repo_name) ⇒ Object
Returns a GitHubV3API::Repo instance for the specified
user
andrepo_name
. -
#initialize(connection) ⇒ ReposAPI
constructor
Typically not used directly.
-
#list ⇒ Object
Returns an array of GitHubV3API::Repo instances representing the user’s public and private repos.
-
#list_collaborators(user, repo_name) ⇒ Object
Returns an array of GitHubV3API::User instances for the collaborators of the specified
user
andrepo_name
. -
#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
andrepo_name
. -
#list_watchers(user, repo_name) ⇒ Object
Returns an array of GitHubV3API::User instances containing the users who are watching the repository specified by
user
andrepo_name
. - #public_repos ⇒ Object
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”
47 48 49 50 51 52 |
# File 'lib/github_v3_api/repos_api.rb', line 47 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 |
#list ⇒ Object
Returns an array of GitHubV3API::Repo instances representing the user’s public and private repos
36 37 38 39 40 |
# File 'lib/github_v3_api/repos_api.rb', line 36 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”
59 60 61 62 63 |
# File 'lib/github_v3_api/repos_api.rb', line 59 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”
81 82 83 84 85 |
# File 'lib/github_v3_api/repos_api.rb', line 81 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”
70 71 72 73 74 |
# File 'lib/github_v3_api/repos_api.rb', line 70 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 |
#public_repos ⇒ Object
27 28 29 30 31 |
# File 'lib/github_v3_api/repos_api.rb', line 27 def public_repos @connection.get('/repositories').map do |repo_data| GitHubV3API::Repo.new(self, repo_data) end end |