Skip to content

Instantly share code, notes, and snippets.

@alexkojin
Created April 11, 2017 07:06
Show Gist options
  • Save alexkojin/9cdd69218bbae3a590d8ed0a93c3851f to your computer and use it in GitHub Desktop.
Save alexkojin/9cdd69218bbae3a590d8ed0a93c3851f to your computer and use it in GitHub Desktop.
Github Api wrapper
class Repo::Github
attr_accessor :account, :client
def initialize(account)
@account = account
end
def client
@client ||= Octokit::Client.new(access_token: account.access_token)
end
def repositories
client.repositories.map{|rep| GithubRep.new(rep.to_h) }
end
# Get a single repository
# @param repo is "username/repo_name_slug"
def repository(repo)
GithubRep.new(client.repository(repo).to_h)
end
end
class GithubRep < OpenStruct
def uid
full_name
end
def params_to_save
{
title: name,
repo_name: name,
description: description,
repo_id: id,
repo_username: owner[:login],
repo_url: html_url
}
end
def archive_zip_url
# remove a branch and set zipball archive format
archive_url.gsub(/\{\/ref\}/, '').gsub(/\{archive_format\}/, 'zipball')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment