Module: Octokit::Client::Users
- Included in:
- Octokit::Client
- Defined in:
- lib/octokit/client/users.rb
Overview
Methods for the Users API
Instance Method Summary collapse
-
#add_email(email, options = {}) ⇒ Array<String>
Add email address to user.
-
#add_key(title, key, options = {}) ⇒ Sawyer::Resource
Add public key to user account.
-
#all_users(options = {}) ⇒ Array<Sawyer::Resource>
List all GitHub users.
-
#emails(options = {}) ⇒ Array<String>
List email addresses for a user.
-
#exchange_code_for_token(code, app_id = client_id, app_secret = client_secret, options = {}) ⇒ Sawyer::Resource
Retrieve the access_token.
-
#follow(user, options = {}) ⇒ Boolean
Follow a user.
-
#followers(user = login, options = {}) ⇒ Array<Sawyer::Resource>
Get a user’s followers.
-
#following(user = login, options = {}) ⇒ Array<Sawyer::Resource>
Get list of users a user is following.
-
#follows?(*args) ⇒ Boolean
Check if you are following a user.
-
#key(key_id, options = {}) ⇒ Sawyer::Resource
Get a public key.
-
#keys(options = {}) ⇒ Array<Sawyer::Resource>
Get list of public keys for user.
-
#remove_email(email) ⇒ Array<String>
Remove email from user.
-
#remove_key(id, options = {}) ⇒ Boolean
Remove a public key from user account.
-
#starred(user = login, options = {}) ⇒ Array<Sawyer::Resource>
Get list of repos starred by a user.
-
#starred?(user, repo, options = {}) ⇒ Boolean
Check if you are starring a repo.
-
#subscriptions(user = login, options = {}) ⇒ Array<Sawyer::Resource>
(also: #watched)
List repositories being watched by a user.
-
#unfollow(user, options = {}) ⇒ Boolean
Unfollow a user.
-
#update_key(key_id, options = {}) ⇒ Sawyer::Resource
Update a public key.
-
#update_user(options) ⇒ Sawyer::Resource
Update the authenticated user.
-
#user(user = nil, options = {}) ⇒ Sawyer::Resource
Get a single user.
-
#user_keys(user, options = {}) ⇒ Array<Sawyer::Resource>
Get list of public keys for user.
-
#validate_credentials(options = {}) ⇒ Boolean
Validate user username and password.
Instance Method Details
#add_email(email, options = {}) ⇒ Array<String>
Add email address to user.
Requires authenticated client.
307 308 309 310 |
# File 'lib/octokit/client/users.rb', line 307 def add_email(email, = {}) email = Array(email) post "user/emails", email end |
#add_key(title, key, options = {}) ⇒ Sawyer::Resource
Add public key to user account.
Requires authenticated client.
253 254 255 |
# File 'lib/octokit/client/users.rb', line 253 def add_key(title, key, = {}) post "user/keys", .merge({:title => title, :key => key}) end |
#all_users(options = {}) ⇒ Array<Sawyer::Resource>
List all GitHub users
This provides a dump of every user, in the order that they signed up for GitHub.
21 22 23 |
# File 'lib/octokit/client/users.rb', line 21 def all_users( = {}) get "users", end |
#emails(options = {}) ⇒ Array<String>
List email addresses for a user.
Requires authenticated client.
294 295 296 |
# File 'lib/octokit/client/users.rb', line 294 def emails( = {}) paginate "user/emails", end |
#exchange_code_for_token(code, app_id = client_id, app_secret = client_secret, options = {}) ⇒ Sawyer::Resource
Retrieve the access_token.
49 50 51 52 53 54 55 56 |
# File 'lib/octokit/client/users.rb', line 49 def exchange_code_for_token(code, app_id = client_id, app_secret = client_secret, = {}) .merge!({ :code => code, :client_id => app_id, :client_secret => app_secret }) post "#{web_endpoint}login/oauth/access_token", end |
#follow(user, options = {}) ⇒ Boolean
Follow a user.
Requires authenticatied client.
145 146 147 |
# File 'lib/octokit/client/users.rb', line 145 def follow(user, = {}) boolean_from_response :put, "user/following/#{user}", end |
#followers(user = login, options = {}) ⇒ Array<Sawyer::Resource>
Get a user’s followers.
94 95 96 |
# File 'lib/octokit/client/users.rb', line 94 def followers(user=login, = {}) get "users/#{user}/followers", end |
#following(user = login, options = {}) ⇒ Array<Sawyer::Resource>
Get list of users a user is following.
105 106 107 |
# File 'lib/octokit/client/users.rb', line 105 def following(user=login, = {}) get "users/#{user}/following", end |
#follows?(target) ⇒ Boolean #follows?(user, target) ⇒ Boolean
Check if you are following a user. Alternatively, check if a given user is following a target user.
Requries an authenticated client.
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/octokit/client/users.rb', line 125 def follows?(*args) target = args.pop user = args.first if user.nil? url = "user/following/#{target}" else url = "users/#{user}/following/#{target}" end boolean_from_response :get, url end |
#key(key_id, options = {}) ⇒ Sawyer::Resource
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.
214 215 216 |
# File 'lib/octokit/client/users.rb', line 214 def key(key_id, = {}) get "user/keys/#{key_id}", end |
#keys(options = {}) ⇒ Array<Sawyer::Resource>
Get list of public keys for user.
Requires authenticated client.
226 227 228 |
# File 'lib/octokit/client/users.rb', line 226 def keys( = {}) paginate "user/keys", end |
#remove_email(email) ⇒ Array<String>
Remove email from user.
Requires authenticated client.
321 322 323 324 |
# File 'lib/octokit/client/users.rb', line 321 def remove_email(email) email = Array(email) boolean_from_response :delete, "user/emails", email end |
#remove_key(id, options = {}) ⇒ Boolean
Remove a public key from user account.
Requires authenticated client.
282 283 284 |
# File 'lib/octokit/client/users.rb', line 282 def remove_key(id, = {}) boolean_from_response :delete, "user/keys/#{id}", end |
#starred(user = login, options = {}) ⇒ Array<Sawyer::Resource>
Get list of repos starred by a user.
172 173 174 175 |
# File 'lib/octokit/client/users.rb', line 172 def starred(user=login, = {}) path = user_authenticated? ? "user/starred" : "users/#{user}/starred" paginate path, end |
#starred?(user, repo, options = {}) ⇒ Boolean
Check if you are starring a repo.
Requires authenticated client.
187 188 189 |
# File 'lib/octokit/client/users.rb', line 187 def starred?(user, repo, = {}) boolean_from_response :get, "user/starred/#{user}/#{repo}", end |
#subscriptions(user = login, options = {}) ⇒ Array<Sawyer::Resource> Also known as: watched
List repositories being watched by a user.
336 337 338 339 |
# File 'lib/octokit/client/users.rb', line 336 def subscriptions(user=login, = {}) path = user_authenticated? ? "user/subscriptions" : "users/#{user}/subscriptions" paginate path, end |
#unfollow(user, options = {}) ⇒ Boolean
Unfollow a user.
Requires authenticated client.
158 159 160 |
# File 'lib/octokit/client/users.rb', line 158 def unfollow(user, = {}) boolean_from_response :delete, "user/following/#{user}", end |
#update_key(key_id, options = {}) ⇒ Sawyer::Resource
Update a public key
Requires authenticated client
269 270 271 |
# File 'lib/octokit/client/users.rb', line 269 def update_key(key_id, = {}) patch "user/keys/#{key_id}", end |
#update_user(options) ⇒ Sawyer::Resource
Update the authenticated user
83 84 85 |
# File 'lib/octokit/client/users.rb', line 83 def update_user() patch "user", end |
#user(user = nil, options = {}) ⇒ Sawyer::Resource
Get a single user
32 33 34 35 36 37 38 |
# File 'lib/octokit/client/users.rb', line 32 def user(user=nil, = {}) if user get "users/#{user}", else get 'user', end end |
#user_keys(user, options = {}) ⇒ Array<Sawyer::Resource>
Get list of public keys for user.
Requires authenticated client.
238 239 240 241 |
# File 'lib/octokit/client/users.rb', line 238 def user_keys(user, = {}) # TODO: Roll this into .keys paginate "users/#{user}/keys", end |
#validate_credentials(options = {}) ⇒ Boolean
Validate user username and password
64 65 66 67 68 |
# File 'lib/octokit/client/users.rb', line 64 def validate_credentials( = {}) !self.class.new().user.nil? rescue Octokit::Unauthorized false end |