class Reponaut::GitHub::Client

Attributes

username[R]

Public Class Methods

new(username) click to toggle source
# File lib/reponaut/github.rb, line 15
def initialize(username)
  @username = username
end

Public Instance Methods

method_missing(symbol, *args) click to toggle source
Calls superclass method
# File lib/reponaut/github.rb, line 27
def method_missing(symbol, *args)
  if self.class.respond_to?(symbol)
    self.class.send(symbol, *args)
  else
    super
  end
end
repos() click to toggle source
# File lib/reponaut/github.rb, line 19
def repos
  repo_data.map { |e| Repository.new(self, e) }
end
to_s() click to toggle source
# File lib/reponaut/github.rb, line 23
def to_s
  username
end

Private Instance Methods

mock_repo_data() click to toggle source
# File lib/reponaut/github.rb, line 65
def mock_repo_data
  raise RateLimitExceededError if ENV['REPONAUT_RATE_LIMIT'] == 'on'
  path = File.expand_path("../../../spec/fixtures/cassettes/#{username}.yml", __FILE__)
  raw_data = IO.read(path)
  data = YAML.load(raw_data)
  raise NoSuchUserError, username if data['http_interactions'][0]['response']['status']['code'] == 404
  JSON.parse(data['http_interactions'][0]['response']['body']['string'])
end
parse_linked_data(resp, acc) click to toggle source
# File lib/reponaut/github.rb, line 50
def parse_linked_data(resp, acc)
  return acc unless resp.headers.include?('link')
  links = resp.headers['link'].split(/,/).map { |l| l.strip }
  next_url = links.find { |l| l =~ link_url_re }
  return acc unless next_url
  next_url = next_url.match(link_url_re).captures.first
  resp = request_repo_data(next_url)
  acc += JSON.parse(resp.body)
  parse_linked_data(resp, acc)
end
real_repo_data() click to toggle source
# File lib/reponaut/github.rb, line 37
def real_repo_data
  resp = request_repo_data("/users/#{username}/repos")
  body = JSON.parse(resp.body)
  parse_linked_data(resp, body)
end
request_repo_data(url) click to toggle source
# File lib/reponaut/github.rb, line 43
def request_repo_data(url)
  resp = get(url)
  raise NoSuchUserError, username if resp.code == 404
  raise RateLimitExceededError if resp.code == 403
  resp
end