class GitHub::Client

Attributes

access_token[R]
login[R]

Public Class Methods

new(login=nil, access_token=nil) click to toggle source
# File lib/github/client.rb, line 9
def initialize(login=nil, access_token=nil)
  @login = login
  @access_token = access_token
end

Public Instance Methods

emails() click to toggle source

Get emails for authenticated user

# File lib/github/client.rb, line 23
def emails
  get "/user/emails", auth_params
end
events(username) click to toggle source
# File lib/github/client.rb, line 35
def events(username)
  get "/users/#{username}/events"
end
followers(username) click to toggle source
# File lib/github/client.rb, line 27
def followers(username)
  get "/users/#{username}/followers"
end
following(username) click to toggle source
# File lib/github/client.rb, line 31
def following(username)
  get "/users/#{username}/following"
end
repos(username) click to toggle source
# File lib/github/client.rb, line 39
def repos(username)
  get "/users/#{username}/repos"
end
user(username) click to toggle source
# File lib/github/client.rb, line 14
def user(username)
  get "/users/#{username}"
end
users() click to toggle source
# File lib/github/client.rb, line 18
def users
  get "/users"
end

Private Instance Methods

auth_params() click to toggle source
# File lib/github/client.rb, line 51
def auth_params
  @login.nil? ? {} : { login: @login, access_token: @access_token }
end
get(url, params={}) click to toggle source
# File lib/github/client.rb, line 45
def get(url, params={})
  response = self.class.get url, query: params
  handle_response(response)
  response.parsed_response
end
handle_response(response) click to toggle source
# File lib/github/client.rb, line 55
def handle_response(response)
  case response.code
  when 401 then raise Unauthorized
  when 403 then raise RateLimitExceeded
  when 404 then raise NotFound
  when 400..500 then raise ClientError
  when 500..600 then raise ServerError, response.code
  else
    response
  end
end