class GithubBackup::GithubRepositoryCollection
Attributes
client[R]
Public Class Methods
new(client)
click to toggle source
# File lib/github-backup/github_repository_collection.rb, line 5 def initialize(client) @client = client end
Public Instance Methods
gists(username)
click to toggle source
# File lib/github-backup/github_repository_collection.rb, line 22 def gists(username) first_page = if username_is_authenticated_user?(username) client.gists else client.gists(username) end all(first_page).map { |r| GithubBackup::Gist.new(r) } end
repos(username)
click to toggle source
# File lib/github-backup/github_repository_collection.rb, line 9 def repos(username) first_page = if username_is_authenticated_user?(username) client.repos elsif username_is_organisation?(username) client.org_repos(username) else client.repos(username) end all(first_page).map { |r| GithubBackup::Repository.new(r) } end
starred_gists(username)
click to toggle source
# File lib/github-backup/github_repository_collection.rb, line 33 def starred_gists(username) first_page = if username_is_authenticated_user?(username) client.starred_gists else [] # Can only list authenticated user's gists at the moment end return first_page if first_page.empty? all(first_page).map { |r| GithubBackup::Gist.new(r) } end
wikis(username)
click to toggle source
# File lib/github-backup/github_repository_collection.rb, line 45 def wikis(username) first_page = if username_is_authenticated_user?(username) client.repos elsif username_is_organisation?(username) client.org_repos(username) else client.repos(username) end all(first_page). select(&:has_wiki?). map { |r| GithubBackup::Wiki.new(r) } end
Private Instance Methods
all(first_page)
click to toggle source
# File lib/github-backup/github_repository_collection.rb, line 62 def all(first_page) repos = [] repos.concat(first_page) # Iterate over paginated response last_response = client.last_response unless last_response.rels[:next].nil? loop do last_response = last_response.rels[:next].get repos.concat(last_response.data) break if last_response.rels[:next].nil? end end repos end
username_is_authenticated_user?(username)
click to toggle source
# File lib/github-backup/github_repository_collection.rb, line 83 def username_is_authenticated_user?(username) return false unless client.token_authenticated? username == client.user.login end
username_is_organisation?(username)
click to toggle source
# File lib/github-backup/github_repository_collection.rb, line 79 def username_is_organisation?(username) client.user(username).type == 'Organization' end