class Github::API

Service for all Github API call

Constants

GITHUB_API_URL

Public Class Methods

config() click to toggle source
# File lib/gitget/github_api.rb, line 16
def self.config
  return @config if @config

  @config = { username: ENV['GH_USERNAME'],
              token:    ENV['GH_TOKEN'] }
end
config=(credentials) click to toggle source
# File lib/gitget/github_api.rb, line 12
def self.config=(credentials)
  @config ? @config.update(credentials) : @config = credentials
end
repo_info(owner, repo) click to toggle source
# File lib/gitget/github_api.rb, line 28
def self.repo_info(owner, repo)
  route = '/repos/' + owner + '/' + repo
  github_api_get(route)
end
repo_stat(full_name, stat) click to toggle source
# File lib/gitget/github_api.rb, line 53
def self.repo_stat(full_name, stat)
  route = '/repos/' + full_name + '/stats/' + stat
  github_api_get(route)
end
user_followers(username) click to toggle source
# File lib/gitget/github_api.rb, line 33
def self.user_followers(username)
  route = '/users/' + username + '/followers'
  github_api_get(route)
end
user_following(username) click to toggle source
# File lib/gitget/github_api.rb, line 38
def self.user_following(username)
  route = '/users/' + username + '/following'
  github_api_get(route)
end
user_info(username) click to toggle source
# File lib/gitget/github_api.rb, line 23
def self.user_info(username)
  route = '/users/' + username
  github_api_get(route)
end
user_repos(username) click to toggle source
# File lib/gitget/github_api.rb, line 48
def self.user_repos(username)
  route = '/users/' + username + '/repos'
  github_api_get(route)
end
user_starred(username) click to toggle source
# File lib/gitget/github_api.rb, line 43
def self.user_starred(username)
  route = '/users/' + username + '/starred'
  github_api_get(route)
end

Private Class Methods

github_api_get(route) click to toggle source
# File lib/gitget/github_api.rb, line 73
def self.github_api_get(route)
  url = GITHUB_API_URL + route
  response = github_api_wait_cache(url)
  JSON.parse(response.to_s)
end
github_api_get_http(url) click to toggle source
# File lib/gitget/github_api.rb, line 60
def self.github_api_get_http(url)
  HTTP.basic_auth(user: config[:username], pass: config[:token]).get(url)
end
github_api_wait_cache(url) click to toggle source
# File lib/gitget/github_api.rb, line 64
def self.github_api_wait_cache(url)
  response = github_api_get_http(url)
  while response.headers['Status'].split(' ').first == '202'
    sleep(2)
    response = github_api_get_http(url)
  end
  response
end