Module: GitHub::Client::Users

Included in:
GitHub::Client
Defined in:
lib/github_api_v3/client/users.rb

Overview

Contains methods for the Users API.

Instance Method Summary collapse

Instance Method Details

#create_key(title, key) ⇒ Hash

Create a public key.

Requires authentication.

Examples:

client.create_key('octocat@octomac', 'ssh-rsa AAA...')

Parameters:

  • title (String)

    The title of the public key.

  • key (String)

    The actual public key.

Returns:

  • (Hash)

    The public key’s data.

See Also:



168
169
170
# File 'lib/github_api_v3/client/users.rb', line 168

def create_key(title, key)
  post '/user/keys', body: {title: title, key: key}
end

#delete_key(id) ⇒ Boolean

Remove a public key from a user’s account.

Requires authentication.

Examples:

client.delete_key(123)

Parameters:

  • id (Integer)

    The id of the integer to delete.

Returns:

  • (Boolean)

    True if success, false if not.



195
196
197
# File 'lib/github_api_v3/client/users.rb', line 195

def delete_key(id)
  boolean_request :delete, "/user/keys/#{id}"
end

#emailsArray

Get all emails for an authenticated user.

Examples:

client = GitHub::Client.new(login: 'username', access_token: 'abcdefghijklmnopqrstuvwxyz12345')
client.emails # => ["[email protected]", "[email protected]"]

Returns:

  • (Array)

See Also:



43
44
45
# File 'lib/github_api_v3/client/users.rb', line 43

def emails
  get '/user/emails'
end

#follow(username) ⇒ Boolean

Follow a user.

Requires authentication.

Examples:

client.follow('caseyscarborough')

Parameters:

  • username (String)

    Username of the user to follow.

Returns:

  • (Boolean)

    True on success.

See Also:



56
57
58
# File 'lib/github_api_v3/client/users.rb', line 56

def follow(username)
  boolean_request :put, "/user/following/#{username}"
end

#followers(username = nil) ⇒ Array

List a user’s followers.

If username is left blank, returns the currently authenticated user’s list of followers.

Examples:

GitHub.followers('caseyscarborough')
# Get authenticated user's followers
client.followers

Parameters:

  • username (String) (defaults to: nil)

    The username to get a list of followers for.

Returns:

  • (Array)

    Array of hashes of each user.

See Also:



85
86
87
88
89
90
91
# File 'lib/github_api_v3/client/users.rb', line 85

def followers(username=nil)
  if username
    get "/users/#{username}/followers"
  else
    get '/user/followers'
  end
end

#following(username) ⇒ Array

List users who a specific user is following.

Examples:

GitHub.following('caseyscarborough')

Parameters:

  • username (String)

    The username of the user to get the list of users they arefollowing.

Returns:

  • (Array)

    Array of hashes of each user.

See Also:



100
101
102
# File 'lib/github_api_v3/client/users.rb', line 100

def following(username)
  get "/users/#{username}/following"
end

#following?(username) ⇒ Boolean

Check if an authenticated user is following another user.

Requires the user to be authenticated.

Examples:

client.following?('caseyscarborough')

Parameters:

  • username (String)

    The username of the user to check against.

Returns:

  • (Boolean)

    True if user does follow the target user, false if not.



112
113
114
# File 'lib/github_api_v3/client/users.rb', line 112

def following?(username)
  boolean_request :get, "/user/following/#{username}"
end

#follows?(username, target_username) ⇒ Boolean

Checks to see if a user is following another user.

Examples:

GitHub.follows?('caseyscarborough', 'matz')

Parameters:

  • username (String)

    The user following.

  • target_username (String)

    The target user.

Returns:

  • (Boolean)

    True if user does follow target user.

See Also:



68
69
70
# File 'lib/github_api_v3/client/users.rb', line 68

def follows?(username, target_username)
  boolean_request :get, "/users/#{username}/following/#{target_username}"
end

#key(id) ⇒ Hash

Get a public key.

Requires authentication.

Examples:

client.key(123)

Parameters:

  • id (Integer)

    The id of the key to retrieve.

Returns:



154
155
156
# File 'lib/github_api_v3/client/users.rb', line 154

def key(id)
  get "/user/keys/#{id}"
end

#keys(username = nil) ⇒ Array

Get a list of public keys for a user.

If username left blank, get currently authenticated user’s keys.

Examples:

GitHub.keys('username')
client.keys

Parameters:

  • username (String) (defaults to: nil)

    The username to get public keys for.

Returns:

  • (Array)

    Array of hashes of public keys.



138
139
140
141
142
143
144
# File 'lib/github_api_v3/client/users.rb', line 138

def keys(username=nil)
  if username
    get "/users/#{username}/keys"
  else
    get '/user/keys'
  end
end

#notifications(options = {}) ⇒ Array

List notifications.

Requires authentication.

Examples:

client.notifications

Parameters:

  • options (Hash) (defaults to: {})

    Optional parameters.

Options Hash (options):

  • :all (Boolean)

    Show notifications marked as read.

  • :participating (Boolean)

    Show only notifications that the user is participating in or mentioned in.

  • :time (String)

    Only show notifications since a given time. Should be in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ), such as: “2012-10-09T23:39:01Z”.

Returns:

  • (Array)

    List of notifications.

See Also:



211
212
213
# File 'lib/github_api_v3/client/users.rb', line 211

def notifications(options={})
  get "/notifications", params: options
end

#organizations(username = nil) ⇒ Array

List public organizations for a user.

Examples:

GitHub.organizations('caseyscarborough')
client.organizations

Parameters:

  • username (String) (defaults to: nil)

    The target user’s username.

Returns:

  • (Array)

    List of organizations.

See Also:



292
293
294
295
296
297
298
# File 'lib/github_api_v3/client/users.rb', line 292

def organizations(username=nil)
  if username
    get "/users/#{username}/orgs"
  else
    get "/user/orgs"
  end
end

#rate_limitHash

Get the current client’s rate limit info.

Examples:

Unauthenticated client’s rate limit.

GitHub.rate_limit

Authenticated client’s rate limit.

client.rate_limit

Returns:

  • (Hash)

    The rate limit information.

See Also:



308
309
310
# File 'lib/github_api_v3/client/users.rb', line 308

def rate_limit
  get "/rate_limit"
end

#repo_notifications(owner, repo, options = {}) ⇒ Array

List notifications for a repository.

Requires authentication.

Examples:

client.repo_notifications('caseyscarborough','github')

Parameters:

  • owner (String)

    Repository owner.

  • repo (String)

    Repository name.

  • options (Hash) (defaults to: {})

    Optional parameters.

Options Hash (options):

  • :all (Boolean)

    Show notifications marked as read.

  • :participating (Boolean)

    Show only notifications that the user is participating in or mentioned in.

  • :time (String)

    Only show notifications since a given time. Should be in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ), such as: “2012-10-09T23:39:01Z”.

Returns:

  • (Array)

    List of notifications.

See Also:



229
230
231
# File 'lib/github_api_v3/client/users.rb', line 229

def repo_notifications(owner, repo, options={})
  get "/repos/#{owner}/#{repo}/notifications"
end

#starring(username = nil) ⇒ Array

List repositories a user is starring.

Can be used unauthenticated or authenticated.

Examples:

GitHub.starring('caseyscarborough')
client.starring

Parameters:

  • username (String) (defaults to: nil)

    The target user’s username.

Returns:

  • (Array)

See Also:



244
245
246
247
248
249
250
# File 'lib/github_api_v3/client/users.rb', line 244

def starring(username=nil)
  if username
    get "/users/#{username}/starred"
  else
    get "/user/starred"
  end
end

#starring?(owner, repo) ⇒ Boolean

Check if you are starring a repository.

Requires authentication.

Examples:

client.starring?('caseyscarborough','github')

Parameters:

  • owner (String)

    Repository owner.

  • repo (String)

    Repository name.

Returns:

  • (Boolean)

    True if successful, false if not.

See Also:



262
263
264
# File 'lib/github_api_v3/client/users.rb', line 262

def starring?(owner, repo)
  boolean_request :get, "/user/starred/#{owner}/#{repo}"
end

#unfollow(username) ⇒ Boolean

Unfollow a user.

Requires authentication.

Examples:

client.unfollow('matz')

Parameters:

  • username (String)

    The username of the user to unfollow.

Returns:

  • (Boolean)

    True if successful, false otherwise.



124
125
126
# File 'lib/github_api_v3/client/users.rb', line 124

def unfollow(username)
  boolean_request :delete, "/user/following/#{username}"
end

#update_key(id, title, key) ⇒ Hash

Update a public key

Requires authentication.

Examples:

client.update_key(1, 'octocat@octomac', 'ssh-rsa AAA...')

Parameters:

  • id (Integer)

    The ID of the public key to update.

  • title (String)

    The title of the public key.

  • key (String)

    The actual public key.

Returns:

  • (Hash)

    The public key’s data.

See Also:



183
184
185
# File 'lib/github_api_v3/client/users.rb', line 183

def update_key(id, title, key)
  patch "/user/keys/#{id}", body: {title: title, key: key}
end

#user(username = nil) ⇒ Hash

Returns a single user.

If called without the username parameter, it will return the currently authenticated user.

Examples:

GitHub.user('caseyscarborough')

Parameters:

  • username (String) (defaults to: nil)

    A GitHub username.

Returns:

See Also:



20
21
22
23
24
25
26
# File 'lib/github_api_v3/client/users.rb', line 20

def user(username=nil)
  if username
    get "/users/#{username}"
  else
    get '/user'
  end
end

#usersArray

Returns a list of all GitHub users.



32
33
34
# File 'lib/github_api_v3/client/users.rb', line 32

def users
  get '/users'
end

#watching(username = nil) ⇒ Array

List repositories a user is watching.

Examples:

GitHub.watching('caseyscarborough')
client.watching

Parameters:

  • username (String) (defaults to: nil)

    The target user’s usernmae.

Returns:

  • (Array)

See Also:



275
276
277
278
279
280
281
# File 'lib/github_api_v3/client/users.rb', line 275

def watching(username=nil)
  if username
    get "/users/#{username}/subscriptions"
  else
    get "/user/subscriptions"
  end
end