module Octokit::Client::Users

Methods for the Users API

@see developer.github.com/v3/users/

Public Instance Methods

add_email(email, options = {}) click to toggle source

Add email address to user.

Requires authenticated client.

@param email [String] Email address to add to the user. @return [Array<String>] Array of all email addresses of the user. @see developer.github.com/v3/users/emails/#add-email-addresses @example

@client.add_email('new_email@user.com')
# File lib/octokit/client/users.rb, line 312
def add_email(email, options = {})
  email = Array(email)
  post "user/emails", email
end
add_key(title, key, options = {}) click to toggle source

Add public key to user account.

Requires authenticated client.

@param title [String] Title to give reference to the public key. @param key [String] Public key. @return [Sawyer::Resource] Hash representing the newly added public key. @see developer.github.com/v3/users/keys/#create-a-public-key @example

@client.add_key('Personal projects key', 'ssh-rsa AAA...')
# File lib/octokit/client/users.rb, line 255
def add_key(title, key, options = {})
  post "user/keys", options.merge({:title => title, :key => key})
end
all_users(options = {}) click to toggle source

List all GitHub users

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

@param options [Hash] Optional options. @option options [Integer] :since The integer ID of the last User that

you’ve seen.

@see developer.github.com/v3/users/#get-all-users

@return [Array<Sawyer::Resource>] List of GitHub users.

# File lib/octokit/client/users.rb, line 21
def all_users(options = {})
  paginate "users", options
end
emails(options = {}) click to toggle source

List email addresses for a user.

Requires authenticated client.

@return [Array<String>] Array of email addresses. @see developer.github.com/v3/users/emails/#list-email-addresses-for-a-user @example

@client.emails
# File lib/octokit/client/users.rb, line 299
def emails(options = {})
  paginate "user/emails", options
end
exchange_code_for_token(code, app_id = client_id, app_secret = client_secret, options = {}) click to toggle source

Retrieve the access_token.

@param code [String] Authorization code generated by GitHub. @param app_id [String] Client Id we received when our application was registered with GitHub. Defaults to client_id. @param app_secret [String] Client Secret we received when our application was registered with GitHub. Defaults to client_secret. @return [Sawyer::Resource] Hash holding the access token. @see developer.github.com/v3/oauth/#web-application-flow @example

Octokit.exchange_code_for_token('aaaa', 'xxxx', 'yyyy', {:accept => 'application/json'})
# File lib/octokit/client/users.rb, line 46
def exchange_code_for_token(code, app_id = client_id, app_secret = client_secret, options = {})
  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
follow(user, options = {}) click to toggle source

Follow a user.

Requires authenticatied client.

@param user [String] Username of the user to follow. @return [Boolean] True if follow was successful, false otherwise. @see developer.github.com/v3/users/followers/#follow-a-user @example

@client.follow('holman')
# File lib/octokit/client/users.rb, line 149
def follow(user, options = {})
  boolean_from_response :put, "user/following/#{user}", options
end
followers(user=login, options = {}) click to toggle source

Get a user's followers.

@param user [Integer, String] GitHub user login or id of the user whose

list of followers you are getting.

@return [Array<Sawyer::Resource>] Array of hashes representing users

followers.

@see developer.github.com/v3/users/followers/#list-followers-of-a-user @example

Octokit.followers('pengwynn')
# File lib/octokit/client/users.rb, line 99
def followers(user=login, options = {})
  paginate "#{User.path user}/followers", options
end
following(user=login, options = {}) click to toggle source

Get list of users a user is following.

@param user [Intger, String] GitHub user login or id of the user who you

are getting the list of the people they follow.

@return [Array<Sawyer::Resource>] Array of hashes representing users a

user is following.

@see developer.github.com/v3/users/followers/#list-users-followed-by-another-user @example

Octokit.following('pengwynn')
# File lib/octokit/client/users.rb, line 112
def following(user=login, options = {})
  paginate "#{User.path user}/following", options
end
follows?(*args) click to toggle source

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

Requries an authenticated client.

@overload follows?(target)

@param target [String] GitHub login of the user that you want to
check if you are following.

@overload follows?(user, target)

@param user [Integer, String] GitHub user login or id of first user
@param target [String] GitHub login of the target user

@return [Boolean] True following target user, false otherwise. @see developer.github.com/v3/users/followers/#check-if-you-are-following-a-user @see developer.github.com/v3/users/followers/#check-if-one-user-follows-another @example

@client.follows?('pengwynn')

@example

@client.follows?('catsby', 'pengwynn')
# File lib/octokit/client/users.rb, line 134
def follows?(*args)
  target = args.pop
  user = args.first
  boolean_from_response :get, "#{User.path user}/following/#{target}"
end
key(key_id, options = {}) click to toggle source

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.

@param key_id [Integer] Key to retreive. @return [Sawyer::Resource] Hash representing the key. @see developer.github.com/v3/users/keys/#get-a-single-public-key @example

@client.key(1)

@example 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..."
# File lib/octokit/client/users.rb, line 217
def key(key_id, options = {})
  get "user/keys/#{key_id}", options
end
keys(options = {}) click to toggle source

Get list of public keys for user.

Requires authenticated client.

@return [Array<Sawyer::Resource>] Array of hashes representing public keys. @see developer.github.com/v3/users/keys/#list-your-public-keys @example

@client.keys
# File lib/octokit/client/users.rb, line 229
def keys(options = {})
  paginate "user/keys", options
end
remove_email(email) click to toggle source

Remove email from user.

Requires authenticated client.

@param email [String] Email address to remove. @return [Array<String>] Array of all email addresses of the user. @see developer.github.com/v3/users/emails/#delete-email-addresses @example

@client.remove_email('old_email@user.com')
# File lib/octokit/client/users.rb, line 326
def remove_email(email)
  email = Array(email)
  boolean_from_response :delete, "user/emails", email
end
remove_key(id, options = {}) click to toggle source

Remove a public key from user account.

Requires authenticated client.

@param id [String] Id of the public key to remove. @return [Boolean] True if removal was successful, false otherwise. @see developer.github.com/v3/users/keys/#delete-a-public-key @example

@client.remove_key(1)
# File lib/octokit/client/users.rb, line 287
def remove_key(id, options = {})
  boolean_from_response :delete, "user/keys/#{id}", options
end
starred(user=login, options = {}) click to toggle source

Get list of repos starred by a user.

@param user [Integer, String] GitHub user login of the user to get the

list of their starred repositories.

@param options [Hash] Optional options @option options [String] :sort (created) Sort: created or updated. @option options [String] :direction (desc) Direction: asc or desc. @return [Array<Sawyer::Resource>] Array of hashes representing repositories starred by user. @see developer.github.com/v3/activity/starring/#list-repositories-being-starred @example

Octokit.starred('pengwynn')
# File lib/octokit/client/users.rb, line 177
def starred(user=login, options = {})
  paginate user_path(user, 'starred'), options
end
starred?(repo, options = {}) click to toggle source

Check if you are starring a repo.

Requires authenticated client.

@param repo [String, Hash, Repository] A GitHub repository @return [Boolean] True if you are following the repo, false otherwise. @see developer.github.com/v3/activity/starring/#check-if-you-are-starring-a-repository @example

@client.starred?('pengwynn/octokit')
# File lib/octokit/client/users.rb, line 190
def starred?(repo, options = {})
  boolean_from_response :get, "user/starred/#{Repository.new(repo)}", options
end
subscriptions(user=login, options = {}) click to toggle source

List repositories being watched by a user.

@param user [Integer, String] GitHub user login or id. @return [Array<Sawyer::Resource>] Array of repositories. @see developer.github.com/v3/activity/watching/#list-repositories-being-watched @example

@client.subscriptions("pengwynn")
# File lib/octokit/client/users.rb, line 338
def subscriptions(user=login, options = {})
  paginate user_path(user, 'subscriptions'), options
end
Also aliased as: watched
unfollow(user, options = {}) click to toggle source

Unfollow a user.

Requires authenticated client.

@param user [String] Username of the user to unfollow. @return [Boolean] True if unfollow was successful, false otherwise. @see developer.github.com/v3/users/followers/#unfollow-a-user @example

@client.unfollow('holman')
# File lib/octokit/client/users.rb, line 162
def unfollow(user, options = {})
  boolean_from_response :delete, "user/following/#{user}", options
end
update_key(key_id, options = {}) click to toggle source

Update a public key

Requires authenticated client

@param key_id [Integer] Id of key to update. @param options [Hash] Hash containing attributes to update. @option options [String] :title @option options [String] :key @return [Sawyer::Resource] Hash representing the updated public key.

@deprecated This method is no longer supported in the API @see developer.github.com/v3/users/keys/#update-a-public-key @see developer.github.com/changes/2014-02-24-finer-grained-scopes-for-ssh-keys/ @example

@client.update_key(1, :title => 'new title', :key => "ssh-rsa BBB")
# File lib/octokit/client/users.rb, line 274
def update_key(key_id, options = {})
  patch "user/keys/#{key_id}", options
end
update_user(options) click to toggle source

Update the authenticated user

@param options [Hash] A customizable set of options. @option options [String] :name @option options [String] :email Publically visible email address. @option options [String] :blog @option options [String] :company @option options [String] :location @option options [Boolean] :hireable @option options [String] :bio @return [Sawyer::Resource] @see developer.github.com/v3/users/#update-the-authenticated-user @example

Octokit.update_user(:name => "Erik Michaels-Ober", :email => "sferik@gmail.com", :company => "Code for America", :location => "San Francisco", :hireable => false)
# File lib/octokit/client/users.rb, line 86
def update_user(options)
  patch "user", options
end
user(user=nil, options = {}) click to toggle source

Get a single user

@param user [Integer, String] GitHub user login or id. @return [Sawyer::Resource] @see developer.github.com/v3/users/#get-a-single-user @see developer.github.com/v3/users/#get-the-authenticated-user @example

Octokit.user("sferik")
# File lib/octokit/client/users.rb, line 33
def user(user=nil, options = {})
  get User.path(user), options
end
user_keys(user, options = {}) click to toggle source

Get list of public keys for user.

@param user [Integer, String] GitHub user login or id. @return [Array<Sawyer::Resource>] Array of hashes representing public keys. @see developer.github.com/v3/users/keys/#list-public-keys-for-a-user @example

@client.user_keys('pengwynn')
# File lib/octokit/client/users.rb, line 240
def user_keys(user, options = {})
  # TODO: Roll this into .keys
  paginate "#{User.path user}/keys", options
end
validate_credentials(options = {}) click to toggle source

Validate user username and password

@param options [Hash] User credentials @option options [String] :login GitHub login @option options [String] :password GitHub password @return [Boolean] True if credentials are valid

# File lib/octokit/client/users.rb, line 66
def validate_credentials(options = {})
  !self.class.new(options).user.nil?
rescue Octokit::Unauthorized
  false
end
watched(user=login, options = {})
Alias for: subscriptions