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:



170
171
172
# File 'lib/github_api_v3/client/users.rb', line 170

def create_key(title, key)
  post '/user/keys', auth_params, {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.



197
198
199
# File 'lib/github_api_v3/client/users.rb', line 197

def delete_key(id)
  boolean_delete "/user/keys/#{id}", auth_params
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', auth_params
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_put "/user/following/#{username}", auth_params
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:



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

def followers(username=nil)
  if username
    get "/users/#{username}/followers"
  else
    get '/user/followers', auth_params
  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:



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

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.



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

def following?(username)
  response = self.class.get "/user/following/#{username}", query: auth_params
  response.code == 204
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
71
# File 'lib/github_api_v3/client/users.rb', line 68

def follows?(username, target_username)
  response = self.class.get "/users/#{username}/following/#{target_username}"
  response.code == 204
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:



156
157
158
# File 'lib/github_api_v3/client/users.rb', line 156

def key(id)
  get "/user/keys/#{id}", auth_params
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.



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

def keys(username=nil)
  if username
    get "/users/#{username}/keys"
  else
    get '/user/keys', auth_params
  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:



213
214
215
# File 'lib/github_api_v3/client/users.rb', line 213

def notifications(options={})
  get "/notifications", auth_params.merge(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:



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

def organizations(username=nil)
  if username
    get "/users/#{username}/orgs"
  else
    get "/user/orgs", auth_params
  end
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:



231
232
233
# File 'lib/github_api_v3/client/users.rb', line 231

def repo_notifications(owner, repo, options={})
  get "/repos/#{owner}/#{repo}/notifications", auth_params
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:



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

def starring(username=nil)
  if username
    get "/users/#{username}/starred"
  else
    get "/user/starred", auth_params
  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:



264
265
266
# File 'lib/github_api_v3/client/users.rb', line 264

def starring?(owner, repo)
  boolean_get "/user/starred/#{owner}/#{repo}", auth_params
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.



126
127
128
# File 'lib/github_api_v3/client/users.rb', line 126

def unfollow(username)
  boolean_delete "/user/following/#{username}", auth_params
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:



185
186
187
# File 'lib/github_api_v3/client/users.rb', line 185

def update_key(id, title, key)
  patch "/user/keys/#{id}", auth_params, {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', auth_params
  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:



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

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