class Circlemator::GithubRepo

Public Class Methods

new(user:, repo:, github_auth_token:, **_opts) click to toggle source
# File lib/circlemator/github_repo.rb, line 22
def initialize(user:, repo:, github_auth_token:, **_opts)
  @user = user
  @repo = repo
  @auth_token = github_auth_token
end

Public Instance Methods

get(path, opts = {}) click to toggle source
# File lib/circlemator/github_repo.rb, line 28
def get(path, opts = {})
  self.class.get(fix_path(path), opts.merge(basic_auth: auth))
end
post(path, opts = {}) click to toggle source
# File lib/circlemator/github_repo.rb, line 36
def post(path, opts = {})
  self.class.post(fix_path(path), opts.merge(basic_auth: auth))
end
put(path, opts = {}) click to toggle source
# File lib/circlemator/github_repo.rb, line 32
def put(path, opts = {})
  self.class.put(fix_path(path), opts.merge(basic_auth: auth))
end

Private Instance Methods

auth() click to toggle source
# File lib/circlemator/github_repo.rb, line 55
def auth
  { username: @auth_token, password: 'x-oauth-basic' }
end
fix_path(path) click to toggle source
# File lib/circlemator/github_repo.rb, line 42
def fix_path(path)
  case path
  when %r(\A#{self.class.base_uri}(/#{@user}/#{@repo}.*)\z)
    $1
  when %r(\A#{self.class.base_uri})
    raise WrongRepo.new(path, "#{@user}/#{@repo}")
  when %r(\A/.*)
    "/#{@user}/#{@repo}#{path}"
  else
    raise InvalidPath, path
  end
end