class Gigest::GithubConnection

Public Class Methods

new(auth_params) click to toggle source
# File lib/gigest/github/github_connection.rb, line 3
def initialize(auth_params)
  @connection = Octokit::Client.new(auth_params)
end

Public Instance Methods

details_for(account) click to toggle source
# File lib/gigest/github/github_connection.rb, line 13
def details_for(account)
  details = @connection.user(account)

  {
    name: details[:name],
    type: details[:type],
    avatar_url: details._rels[:avatar].href,
    company: details[:company],
    location: details[:location],
    html_url: details._rels[:html].href
  }
end
exists?(account) click to toggle source
# File lib/gigest/github/github_connection.rb, line 7
def exists?(account)
  @connection.user(account) ? true : false
rescue Octokit::NotFound
  false
end
gemfile_for(repository_name) click to toggle source
# File lib/gigest/github/github_connection.rb, line 40
def gemfile_for(repository_name)
  decode(file_blob(repository_name, "Gemfile"))
rescue Octokit::NotFound, StandardError
  nil
end
repositories_for(account) click to toggle source
# File lib/gigest/github/github_connection.rb, line 26
def repositories_for(account)
  all_repositories  = []

  page = 0
  loop do
    repositories = @connection.repositories(account, page: page+=1)
    break if repositories.empty?

    all_repositories += repositories.map { |repository| GithubRepo.new(repository, gemfile_for(repository.full_name)) }
  end

  all_repositories
end

Private Instance Methods

decode(blob) click to toggle source
# File lib/gigest/github/github_connection.rb, line 48
def decode(blob)
  Base64.decode64(blob)
end
file_blob(repository_name, file) click to toggle source
# File lib/gigest/github/github_connection.rb, line 52
def file_blob(repository_name, file)
  @connection.contents(repository_name, path: file).content
end