Module: Octokit::Client::Users

Included in:
Octokit::Client
Defined in:
lib/octokit/client/users.rb

Instance Method Summary (collapse)

Instance Method Details

- (Hashie::Mash) access_token(code, app_id, app_secret, options = {})

Retrieve the access_token.

Examples:

@client.access_token('aaaa', 'xxxx', 'yyyy', {:accept => 'application/json'})

Parameters:

  • code (String)

    Authorization code generated by GitHub.

  • app_id (String)

    Client Id we received when our application was registered with GitHub.

  • app_secret (String)

    Client Secret we received when our application was registered with GitHub.

Returns:

  • (Hashie::Mash)

    Hash holding the access token.

See Also:



57
58
59
60
# File 'lib/octokit/client/users.rb', line 57

def access_token(code, app_id, app_secret, options = {})
  post("login/oauth/access_token", options.merge({:endpoint => Octokit.web_endpoint, :code => code,
    :client_id => app_id, :client_secret => app_secret}))
end

- (Array<String>) add_email(email, options = {})

Add email address to user.

Requires authenticated client.

Examples:

@client.add_email('new_email@user.com')

Parameters:

  • email (String)

    Email address to add to the user.

Returns:

  • (Array<String>)

    Array of all email addresses of the user.

See Also:



320
321
322
# File 'lib/octokit/client/users.rb', line 320

def add_email(email, options={})
  post("user/emails", options.merge({:email => email}))
end

- (Hashie::Mash) add_key(title, key, options = {})

Add public key to user account.

Requires authenticated client.

Examples:

@client.add_key('Personal projects key', 'ssh-rsa AAA...')

Parameters:

  • title (String)

    Title to give reference to the public key.

  • key (String)

    Public key.

Returns:

  • (Hashie::Mash)

    Hash representing the newly added public key.

See Also:



263
264
265
# File 'lib/octokit/client/users.rb', line 263

def add_key(title, key, options={})
  post("user/keys", options.merge({:title => title, :key => key}))
end

- (Array) all_users(options = {})

List all GitHub users

This provides a dump of every user, in the order that they signed up for GitHub.

Parameters:

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

    Optional options.

Options Hash (options):

  • :since (Integer)

    The integer ID of the last User that you’ve seen.

Returns:

  • (Array)

    List of GitHub users.

See Also:



28
29
30
# File 'lib/octokit/client/users.rb', line 28

def all_users(options={})
  get "users", options
end

- (Array<String>) emails(options = {})

List email addresses for a user.

Requires authenticated client.

Examples:

@client.emails

Returns:

  • (Array<String>)

    Array of email addresses.

See Also:



306
307
308
# File 'lib/octokit/client/users.rb', line 306

def emails(options={})
  get("user/emails", options)
end

- (Boolean) follow(user, options = {})

Follow a user.

Requires authenticatied client.

Examples:

@client.follow('holman')

Parameters:

  • user (String)

    Username of the user to follow.

Returns:

  • (Boolean)

    True if follow was successful, false otherwise.

See Also:



141
142
143
# File 'lib/octokit/client/users.rb', line 141

def follow(user, options={})
  boolean_from_response(:put, "user/following/#{user}", options)
end

- (Array<Hashie::Mash>) followers(user = login, options = {})

Get a user's followers.

Examples:

Octokit.followers('pengwynn')

Parameters:

  • user (String) (defaults to: login)

    Username of the user whose list of followers you are getting.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing users followers.

See Also:



98
99
100
# File 'lib/octokit/client/users.rb', line 98

def followers(user=, options={})
  get("users/#{user}/followers", options)
end

- (Array<Hashie::Mash>) following(user = login, options = {})

Get list of users a user is following.

Examples:

Octokit.following('pengwynn')

Parameters:

  • user (String) (defaults to: login)

    Username of the user who you are getting the list of the people they follow.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing users a user is following.

See Also:



109
110
111
# File 'lib/octokit/client/users.rb', line 109

def following(user=, options={})
  get("users/#{user}/following", options)
end

- (Boolean) follows?(*args)

Check if you are following a user.

Requries an authenticated client.

Examples:

@client.follows?('pengwynn')

Parameters:

  • user (String)

    Username of the user that you want to check if you are following.

Returns:

  • (Boolean)

    True if you are following the user, false otherwise.

See Also:



123
124
125
126
127
128
129
# File 'lib/octokit/client/users.rb', line 123

def follows?(*args)
  target = args.pop
  user = args.first
  user ||= 
  return if user.nil?
  boolean_from_response(:get, "user/following/#{target}")
end

- (Hashie::Mash) key(key_id, options = {})

Get a public key.

Note, when using dot notation to retrieve the values, ruby will return the hash key for the public keys value instead of the actual value, use symbol or key string to retrieve the value. See example.

Requires authenticated client.

Examples:

@client.key(1)

Retrieve public key contents

public_key = @client.key(1)
public_key.key
# => Error

public_key[:key]
# => "ssh-rsa AAA..."

public_key['key']
# => "ssh-rsa AAA..."

Parameters:

  • key_id (Integer)

    Key to retreive.

Returns:

  • (Hashie::Mash)

    Hash representing the key.

See Also:



222
223
224
# File 'lib/octokit/client/users.rb', line 222

def key(key_id, options={})
  get("user/keys/#{key_id}", options)
end

- (Array<Hashie::Mash>) keys(options = {})

Get list of public keys for user.

Requires authenticated client.

Examples:

@client.keys

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing public keys.

See Also:



235
236
237
# File 'lib/octokit/client/users.rb', line 235

def keys(options={})
  get("user/keys", options)
end

- (Array<String>) remove_email(email, options = {})

Remove email from user.

Requires authenticated client.

Examples:

@client.remove_email('old_email@user.com')

Parameters:

  • email (String)

    Email address to remove.

Returns:

  • (Array<String>)

    Array of all email addresses of the user.

See Also:



334
335
336
# File 'lib/octokit/client/users.rb', line 334

def remove_email(email, options={})
  boolean_from_response(:delete, "user/emails", options.merge({:email => email}))
end

- (Boolean) remove_key(id, options = {})

Remove a public key from user account.

Requires authenticated client.

Examples:

@client.remove_key(1)

Parameters:

  • id (String)

    Id of the public key to remove.

Returns:

  • (Boolean)

    True if removal was successful, false otherwise.

See Also:



293
294
295
# File 'lib/octokit/client/users.rb', line 293

def remove_key(id, options={})
  boolean_from_response(:delete, "user/keys/#{id}", options)
end

- (Array<Hashie::Mash>) search_users(search, options = {})

Search for user.

Examples:

Octokit.search_users('pengwynn')

Parameters:

  • search (String)

    User to search for.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing users.

See Also:



12
13
14
# File 'lib/octokit/client/users.rb', line 12

def search_users(search, options={})
  get("legacy/user/search/#{search}", options)['users']
end

- (Array<Hashie::Mash>) starred(user = login, options = {})

Get list of repos starred by a user.

Examples:

Octokit.starred('pengwynn')

Parameters:

  • user (String) (defaults to: login)

    Username of the user to get the list of their starred repositories.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing repositories starred by user.

See Also:



166
167
168
# File 'lib/octokit/client/users.rb', line 166

def starred(user=, options={})
  get("users/#{user}/starred", options)
end

- (Boolean) starred?(user, repo, options = {})

Check if you are starring a repo.

Requires authenticated client.

Examples:

@client.starred?('pengwynn', 'octokit')

Parameters:

  • user (String)

    Username of repository owner.

  • repo (String)

    Name of the repository.

Returns:

  • (Boolean)

    True if you are following the repo, false otherwise.

See Also:



181
182
183
# File 'lib/octokit/client/users.rb', line 181

def starred?(user, repo, options={})
  boolean_from_response(:get, "user/starred/#{user}/#{repo}", options)
end

- (Array<Hashie::Mashie>) subscriptions(user = login, options = {})

List repositories being watched by a user.

Examples:

@client.subscriptions("pengwynn")

Parameters:

  • user (String) (defaults to: login)

    User's GitHub username.

Returns:

  • (Array<Hashie::Mashie>)

    Array of repositories.

See Also:



348
349
350
# File 'lib/octokit/client/users.rb', line 348

def subscriptions(user=, options={})
  get("users/#{user}/subscriptions", options)
end

- (Boolean) unfollow(user, options = {})

Unfollow a user.

Requires authenticated client.

Examples:

@client.unfollow('holman')

Parameters:

  • user (String)

    Username of the user to unfollow.

Returns:

  • (Boolean)

    True if unfollow was successful, false otherwise.

See Also:



155
156
157
# File 'lib/octokit/client/users.rb', line 155

def unfollow(user, options={})
  boolean_from_response(:delete, "user/following/#{user}", options)
end

- (Hashie::Mash) update_key(key_id, options = {})

Update a public key

Requires authenticated client

Examples:

@client.update_key(1, :title => 'new title', :key => "ssh-rsa BBB")

Parameters:

  • key_id (Integer)

    Id of key to update.

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

    Hash containing attributes to update.

Options Hash (options):

  • :title (String)
  • :key (String)

Returns:

  • (Hashie::Mash)

    Hash representing the updated public key.

See Also:



279
280
281
# File 'lib/octokit/client/users.rb', line 279

def update_key(key_id, options={})
  patch("/user/keys/#{key_id}", options)
end

- (Hashie::Mash) update_user(options)

Update the authenticated user

Examples:

Octokit.user(:name => "Erik Michaels-Ober", :email => "sferik@gmail.com", :company => "Code for America", :location => "San Francisco", :hireable => false)

Parameters:

  • options (Hash)

    A customizable set of options.

Options Hash (options):

  • :name (String)
  • :email (String)

    Publically visible email address.

  • :blog (String)
  • :company (String)
  • :location (String)
  • :hireable (Boolean)
  • :bio (String)

Returns:

  • (Hashie::Mash)


87
88
89
# File 'lib/octokit/client/users.rb', line 87

def update_user(options)
  patch("user", options)
end

- (Hashie::Mash) user(user = nil)

Get a single user

Examples:

Octokit.user("sferik")

Parameters:

  • user (String) (defaults to: nil)

    A GitHub user name.

Returns:

  • (Hashie::Mash)

See Also:



39
40
41
42
43
44
45
# File 'lib/octokit/client/users.rb', line 39

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

- (Array<Hashie::Mash>) user_keys(user, options = {})

Get list of public keys for user.

Requires authenticated client.

Examples:

@client.user_keys('pengwynn'

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing public keys.

See Also:



248
249
250
# File 'lib/octokit/client/users.rb', line 248

def user_keys(user, options={})
  get("users/#{user}/keys", options)
end

- (Boolean) validate_credentials(options = {})

Validate user username and password

Parameters:

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

    User credentials

Options Hash (options):

  • :login (String)

    GitHub login

  • :password (String)

    GitHub password

Returns:

  • (Boolean)

    True if credentials are valid



68
69
70
71
72
# File 'lib/octokit/client/users.rb', line 68

def validate_credentials(options = {})
  !self.class.new(options).user.nil?
rescue Octokit::Unauthorized
  false
end

- (Array<Hashie::Mash>) watched(user = login, options = {})

Get list of repos watched by a user.

Legacy, using github.beta media type. Use `Users#starred` instead.

Examples:

Octokit.watched('pengwynn')

Parameters:

  • user (String) (defaults to: login)

    Username of the user to get the list of repositories they are watching.

Returns:

  • (Array<Hashie::Mash>)

    Array of hashes representing repositories watched by user.

See Also:



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

def watched(user=, options={})
  get("users/#{user}/watched", options)
end