Module: Octokit::Client::Users

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

Overview

Methods for the Users API

See Also:

Instance Method Summary (collapse)

Instance Method Details

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

Add email address to user.

Requires authenticated client.

Examples:

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

See Also:



311
312
313
314
# File 'lib/octokit/client/users.rb', line 311

def add_email(email, options = {})
  email = Array(email)
  post "user/emails", email
end

- (Sawyer::Resource) add_key(title, key, options = {})

Add public key to user account.

Requires authenticated client.

Examples:

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

See Also:



254
255
256
# File 'lib/octokit/client/users.rb', line 254

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

- (Array<Sawyer::Resource>) all_users(options = {})

List all GitHub users

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

Options Hash (options):

  • :since (Integer)

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

See Also:



21
22
23
# File 'lib/octokit/client/users.rb', line 21

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

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

List email addresses for a user.

Requires authenticated client.



298
299
300
# File 'lib/octokit/client/users.rb', line 298

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

- (Sawyer::Resource) exchange_code_for_token(code, app_id = client_id, app_secret = client_secret, options = {})

Retrieve the access_token.

Examples:

Octokit.exchange_code_for_token('aaaa', 'xxxx', 'yyyy', {:accept => 'application/json'})

See Also:



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/octokit/client/users.rb', line 46

def exchange_code_for_token(code, app_id = client_id, app_secret = client_secret, options = {})
  options.merge!({
    :code => code,
    :client_id => app_id,
    :client_secret => app_secret,
    :headers => {
      :content_type => 'application/json',
      :accept       => 'application/json'
    }
  })
  post "#{web_endpoint}login/oauth/access_token", options
end

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

Follow a user.

Requires authenticatied client.

Examples:

@client.follow('holman')

See Also:



148
149
150
# File 'lib/octokit/client/users.rb', line 148

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

- (Array<Sawyer::Resource>) followers(user = login, options = {})

Get a user's followers.

Examples:

Octokit.followers('pengwynn')

See Also:



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

def followers(user=, options = {})
  paginate "#{User.path user}/followers", options
end

- (Array<Sawyer::Resource>) following(user = login, options = {})

Get list of users a user is following.



111
112
113
# File 'lib/octokit/client/users.rb', line 111

def following(user=, options = {})
  paginate "#{User.path user}/following", options
end

- (Boolean) follows?(target) - (Boolean) follows?(user, target)

Check if you are following a user. Alternatively, check if a given user is following a target user.

Requries an authenticated client.

Examples:

@client.follows?('pengwynn')
@client.follows?('catsby', 'pengwynn')

Overloads:

  • - (Boolean) follows?(target)

    check if you are following.

See Also:



133
134
135
136
137
# File 'lib/octokit/client/users.rb', line 133

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

- (Sawyer::Resource) 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..."

See Also:



216
217
218
# File 'lib/octokit/client/users.rb', line 216

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

- (Array<Sawyer::Resource>) keys(options = {})

Get list of public keys for user.

Requires authenticated client.



228
229
230
# File 'lib/octokit/client/users.rb', line 228

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

- (Array<String>) remove_email(email)

Remove email from user.

Requires authenticated client.

Examples:

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

See Also:



325
326
327
328
# File 'lib/octokit/client/users.rb', line 325

def remove_email(email)
  email = Array(email)
  boolean_from_response :delete, "user/emails", email
end

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

Remove a public key from user account.

Requires authenticated client.

Examples:

@client.remove_key(1)

See Also:



286
287
288
# File 'lib/octokit/client/users.rb', line 286

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

- (Array<Sawyer::Resource>) starred(user = login, options = {})

Get list of repos starred by a user.

Examples:

Octokit.starred('pengwynn')

Options Hash (options):

  • :sort (String) — default: created

    Sort: created or updated.

  • :direction (String) — default: desc

    Direction: asc or desc.

See Also:



176
177
178
# File 'lib/octokit/client/users.rb', line 176

def starred(user=, options = {})
  paginate user_path(user, 'starred'), options
end

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

Check if you are starring a repo.

Requires authenticated client.



189
190
191
# File 'lib/octokit/client/users.rb', line 189

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

- (Array<Sawyer::Resource>) subscriptions(user = login, options = {}) Also known as: watched

List repositories being watched by a user.

Examples:

@client.subscriptions("pengwynn")

See Also:



337
338
339
# File 'lib/octokit/client/users.rb', line 337

def subscriptions(user=, options = {})
  paginate user_path(user, 'subscriptions'), options
end

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

Unfollow a user.

Requires authenticated client.

Examples:

@client.unfollow('holman')

See Also:



161
162
163
# File 'lib/octokit/client/users.rb', line 161

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

- (Sawyer::Resource) update_key(key_id, options = {})

Deprecated.

This method is no longer supported in the API

Update a public key

Requires authenticated client

Examples:

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

Options Hash (options):

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

See Also:



273
274
275
# File 'lib/octokit/client/users.rb', line 273

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

- (Sawyer::Resource) update_user(options)

Update the authenticated user

Examples:

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

Options Hash (options):

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

    Publically visible email address.

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

See Also:



85
86
87
# File 'lib/octokit/client/users.rb', line 85

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

- (Sawyer::Resource) user(user = nil, options = {})

Get a single user



33
34
35
# File 'lib/octokit/client/users.rb', line 33

def user(user=nil, options = {})
  get User.path(user), options
end

- (Array<Sawyer::Resource>) user_keys(user, options = {})

Get list of public keys for user.

Examples:

@client.user_keys('pengwynn')

See Also:



239
240
241
242
# File 'lib/octokit/client/users.rb', line 239

def user_keys(user, options = {})
  # TODO: Roll this into .keys
  paginate "#{User.path user}/keys", options
end

- (Boolean) validate_credentials(options = {})

Validate user username and password

Options Hash (options):

  • :login (String)

    GitHub login

  • :password (String)

    GitHub password



65
66
67
68
69
# File 'lib/octokit/client/users.rb', line 65

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