Class: OctocatHerder::Repository
- Inherits:
-
Object
- Object
- OctocatHerder::Repository
- Includes:
- Base
- Defined in:
- lib/octocat_herder/repository.rb
Overview
Interface to the GitHub v3 API for interacting with repositories.
Currently, this only supports retrieval of information about the repository itself, not any updating/creation.
Instance Attribute Summary
Attributes included from Base
Class Method Summary collapse
-
.fetch(login, repository_name, conn = OctocatHerder::Connection.new) ⇒ OctocatHerder::Repository
Fetch a single repository.
-
.list(login, account_type, repository_type, conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::Repository>
Fetch repositories of the specified type, owned by the given login.
-
.method_missing(id, *args) ⇒ Array<OctocatHerder::Repository>
Fetch all, private, public, or member repositories for the specified user.
Instance Method Summary collapse
-
#closed_pull_requests ⇒ Array<OctocatHerder::PullRequest>
The closed pull requests for the repository.
-
#open_pull_requests ⇒ Array<OctocatHerder::PullRequest>
The open pull requests for the repository.
-
#owner ⇒ OctocatHerder::User
The owner of the repository.
-
#owner_avatar_url ⇒ String
The URL to the avatar image of the owner of the repository.
-
#owner_id ⇒ Integer
The ID number of the owner of the repository.
-
#owner_login ⇒ String
The login name of the owner of the repository.
-
#owner_url ⇒ String
The URL of the owner of the repository.
-
#source ⇒ OctocatHerder::Repository?
The source repository that this one was forked from, or
nil
if this repository is not a fork.
Methods included from Base
#available_attributes, #initialize, #method_missing
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class OctocatHerder::Base
Class Method Details
.fetch(login, repository_name, conn = OctocatHerder::Connection.new) ⇒ OctocatHerder::Repository
Fetch a single repository.
195 196 197 198 199 200 201 |
# File 'lib/octocat_herder/repository.rb', line 195 def self.fetch(login, repository_name, conn = OctocatHerder::Connection.new) repo_data = conn.get( "/repos/#{CGI.escape(login)}/#{CGI.escape(repository_name)}" ) new(repo_data, conn) end |
.list(login, account_type, repository_type, conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::Repository>
Fetch repositories of the specified type, owned by the given login
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/octocat_herder/repository.rb', line 156 def self.list(login, account_type, repository_type, conn = OctocatHerder::Connection.new) url_base = case account_type when "User" then "users" when "Organization" then "orgs" else raise ArgumentError.new("Unknown account type: #{account_type}") end raise ArgumentError.new( "Unknown repository type: #{repository_type}" ) unless ['all', 'private', 'public', 'member'].include?(repository_type) raise ArgumentError.new( "Must provide an authenticated OctocatHerder::Connection when listing private repositories." ) if !conn.authenticated_requests? && repository_type == 'private' repositories = conn.get( "/#{url_base}/#{CGI.escape(login)}/repos", :paginated => true, :params => { :type => repository_type } ) repositories.map do |repo| new(repo, conn) end end |
.list_all(login_name, account_type, conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::Repository> .list_private(login_name, account_type, conn) ⇒ Array<OctocatHerder::Repository> .list_public(login_name, account_type, conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::Repository> .list_member(login_name, account_type, conn = OctocatHerder::Connection.new) ⇒ Array<OctocatHerder::Repository>
Fetch all, private, public, or member repositories for the specified user.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/octocat_herder/repository.rb', line 36 def self.method_missing(id, *args) if id.id2name =~ /list_(.+)/ repository_type = Regexp.last_match(1) if ['all', 'private', 'public', 'member'].include? repository_type if repository_type == 'private' and args[2].nil? raise ArgumentError.new("Must specify a connection when listing private repositories.") end arguments = [args[0], args[1], repository_type] arguments << args[2] unless args[2].nil? return self.list(*arguments) end end raise NoMethodError.new("undefined method #{id.id2name} for #{self}:#{self.class}") end |
Instance Method Details
#closed_pull_requests ⇒ Array<OctocatHerder::PullRequest>
This is not cached, and will make at least one API request every time it is called.
The closed pull requests for the repository.
116 117 118 |
# File 'lib/octocat_herder/repository.rb', line 116 def closed_pull_requests OctocatHerder::PullRequest.find_closed_for_repository(owner_login, name, connection) end |
#open_pull_requests ⇒ Array<OctocatHerder::PullRequest>
This is not cached, and will make at least one API request every time it is called.
The open pull requests for the repository.
105 106 107 |
# File 'lib/octocat_herder/repository.rb', line 105 def open_pull_requests OctocatHerder::PullRequest.find_open_for_repository(owner_login, name, connection) end |
#owner ⇒ OctocatHerder::User
This is cached locally to the instance of OctocatHerder::Repository, but will make an additional API request to populate it initially.
The owner of the repository.
94 95 96 |
# File 'lib/octocat_herder/repository.rb', line 94 def owner @owner ||= OctocatHerder::User.fetch(owner_login, connection) end |
#owner_avatar_url ⇒ String
The URL to the avatar image of the owner of the repository.
74 75 76 |
# File 'lib/octocat_herder/repository.rb', line 74 def owner_avatar_url @raw['owner']['avatar_url'] end |
#owner_id ⇒ Integer
The ID number of the owner of the repository.
66 67 68 |
# File 'lib/octocat_herder/repository.rb', line 66 def owner_id @raw['owner']['id'] end |
#owner_login ⇒ String
The login name of the owner of the repository.
58 59 60 |
# File 'lib/octocat_herder/repository.rb', line 58 def owner_login @raw['owner']['login'] end |
#owner_url ⇒ String
The URL of the owner of the repository.
82 83 84 |
# File 'lib/octocat_herder/repository.rb', line 82 def owner_url @raw['owner']['url'] end |
#source ⇒ OctocatHerder::Repository?
The source repository that this one was forked from, or nil
if this repository is not a fork.
125 126 127 128 129 |
# File 'lib/octocat_herder/repository.rb', line 125 def source return nil unless @raw['source'] OctocatHerder::Repository.new(@raw['source'], connection) end |