Created
April 11, 2017 07:06
-
-
Save alexkojin/9cdd69218bbae3a590d8ed0a93c3851f to your computer and use it in GitHub Desktop.
Github Api wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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