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
-
#create_key(title, key) ⇒ Hash
Create a public key.
-
#delete_key(id) ⇒ Boolean
Remove a public key from a user’s account.
-
#emails ⇒ Array
Get all emails for an authenticated user.
-
#follow(username) ⇒ Boolean
Follow a user.
-
#followers(username = nil) ⇒ Array
List a user’s followers.
-
#following(username) ⇒ Array
List users who a specific user is following.
-
#following?(username) ⇒ Boolean
Check if an authenticated user is following another user.
-
#follows?(username, target_username) ⇒ Boolean
Checks to see if a user is following another user.
-
#key(id) ⇒ Hash
Get a public key.
-
#keys(username = nil) ⇒ Array
Get a list of public keys for a user.
-
#notifications(options = {}) ⇒ Array
List notifications.
-
#organizations(username = nil) ⇒ Array
List public organizations for a user.
-
#repo_notifications(owner, repo, options = {}) ⇒ Array
List notifications for a repository.
-
#starring(username = nil) ⇒ Array
List repositories a user is starring.
-
#starring?(owner, repo) ⇒ Boolean
Check if you are starring a repository.
-
#unfollow(username) ⇒ Boolean
Unfollow a user.
-
#update_key(id, title, key) ⇒ Hash
Update a public key.
-
#user(username = nil) ⇒ Hash
Returns a single user.
-
#users ⇒ Array
Returns a list of all GitHub users.
-
#watching(username = nil) ⇒ Array
List repositories a user is watching.
Instance Method Details
#create_key(title, key) ⇒ Hash
Create a public key.
Requires authentication.
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.
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 |
#emails ⇒ Array
Get all emails for an authenticated user.
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.
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.
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.
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.
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.
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.
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.
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.
213 214 215 |
# File 'lib/github_api_v3/client/users.rb', line 213 def notifications(={}) get "/notifications", auth_params.merge() end |
#organizations(username = nil) ⇒ Array
List public organizations for a user.
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.
231 232 233 |
# File 'lib/github_api_v3/client/users.rb', line 231 def repo_notifications(owner, repo, ={}) get "/repos/#{owner}/#{repo}/notifications", auth_params end |
#starring(username = nil) ⇒ Array
List repositories a user is starring.
Can be used unauthenticated or authenticated.
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.
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.
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.
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.
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 |
#users ⇒ Array
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.
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 |