Class: GitHubV3API::UsersAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/github_v3_api/users_api.rb

Overview

Provides access to the GitHub Users API (developer.github.com/v3/users/)

example:

api = GitHubV3API.new(ACCESS_TOKEN)

# get list of logged-in user
a_user = api.current
#=> returns an instance of GitHubV3API::User

a_user.
#=> 'jwilger'

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ UsersAPI

Typically not used directly. Use GitHubV3API#users instead.

connection

an instance of GitHubV3API



20
21
22
# File 'lib/github_v3_api/users_api.rb', line 20

def initialize(connection)
  @connection = connection
end

Instance Method Details

#currentObject

Returns a single GitHubV3API::User instance representing the currently logged in user



26
27
28
29
# File 'lib/github_v3_api/users_api.rb', line 26

def current
  user_data = @connection.get("/user")
  GitHubV3API::User.new(self, user_data)
end

#get(username) ⇒ Object

Returns a GitHubV3API::User instance for the specified username.

username

the string login of the user, e.g. “octocat”



34
35
36
37
# File 'lib/github_v3_api/users_api.rb', line 34

def get(username)
  user_data = @connection.get("/users/#{username}")
  GitHubV3API::User.new_with_all_data(self, user_data)
end