lingfennan-github_api 0.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +741 -0
- data/lib/github_api.rb +93 -0
- data/lib/github_api/api.rb +398 -0
- data/lib/github_api/api/actions.rb +60 -0
- data/lib/github_api/api/arguments.rb +253 -0
- data/lib/github_api/api/config.rb +105 -0
- data/lib/github_api/api/config/property.rb +30 -0
- data/lib/github_api/api/config/property_set.rb +120 -0
- data/lib/github_api/api/factory.rb +33 -0
- data/lib/github_api/authorization.rb +75 -0
- data/lib/github_api/client.rb +77 -0
- data/lib/github_api/client/activity.rb +31 -0
- data/lib/github_api/client/activity/events.rb +233 -0
- data/lib/github_api/client/activity/feeds.rb +50 -0
- data/lib/github_api/client/activity/notifications.rb +181 -0
- data/lib/github_api/client/activity/starring.rb +130 -0
- data/lib/github_api/client/activity/watching.rb +176 -0
- data/lib/github_api/client/authorizations.rb +142 -0
- data/lib/github_api/client/authorizations/app.rb +98 -0
- data/lib/github_api/client/emojis.rb +19 -0
- data/lib/github_api/client/gists.rb +289 -0
- data/lib/github_api/client/gists/comments.rb +100 -0
- data/lib/github_api/client/git_data.rb +31 -0
- data/lib/github_api/client/git_data/blobs.rb +51 -0
- data/lib/github_api/client/git_data/commits.rb +101 -0
- data/lib/github_api/client/git_data/references.rb +150 -0
- data/lib/github_api/client/git_data/tags.rb +95 -0
- data/lib/github_api/client/git_data/trees.rb +113 -0
- data/lib/github_api/client/gitignore.rb +57 -0
- data/lib/github_api/client/issues.rb +248 -0
- data/lib/github_api/client/issues/assignees.rb +77 -0
- data/lib/github_api/client/issues/comments.rb +146 -0
- data/lib/github_api/client/issues/events.rb +50 -0
- data/lib/github_api/client/issues/labels.rb +189 -0
- data/lib/github_api/client/issues/milestones.rb +146 -0
- data/lib/github_api/client/markdown.rb +62 -0
- data/lib/github_api/client/meta.rb +19 -0
- data/lib/github_api/client/orgs.rb +127 -0
- data/lib/github_api/client/orgs/hooks.rb +182 -0
- data/lib/github_api/client/orgs/members.rb +142 -0
- data/lib/github_api/client/orgs/memberships.rb +131 -0
- data/lib/github_api/client/orgs/projects.rb +57 -0
- data/lib/github_api/client/orgs/teams.rb +407 -0
- data/lib/github_api/client/projects.rb +83 -0
- data/lib/github_api/client/projects/cards.rb +158 -0
- data/lib/github_api/client/projects/columns.rb +146 -0
- data/lib/github_api/client/pull_requests.rb +195 -0
- data/lib/github_api/client/pull_requests/comments.rb +140 -0
- data/lib/github_api/client/pull_requests/reviews.rb +158 -0
- data/lib/github_api/client/repos.rb +468 -0
- data/lib/github_api/client/repos/branches.rb +48 -0
- data/lib/github_api/client/repos/branches/protections.rb +75 -0
- data/lib/github_api/client/repos/collaborators.rb +84 -0
- data/lib/github_api/client/repos/comments.rb +125 -0
- data/lib/github_api/client/repos/commits.rb +80 -0
- data/lib/github_api/client/repos/contents.rb +246 -0
- data/lib/github_api/client/repos/deployments.rb +138 -0
- data/lib/github_api/client/repos/downloads.rb +62 -0
- data/lib/github_api/client/repos/forks.rb +48 -0
- data/lib/github_api/client/repos/hooks.rb +214 -0
- data/lib/github_api/client/repos/keys.rb +104 -0
- data/lib/github_api/client/repos/merging.rb +47 -0
- data/lib/github_api/client/repos/pages.rb +48 -0
- data/lib/github_api/client/repos/projects.rb +62 -0
- data/lib/github_api/client/repos/pub_sub_hubbub.rb +133 -0
- data/lib/github_api/client/repos/releases.rb +189 -0
- data/lib/github_api/client/repos/releases/assets.rb +136 -0
- data/lib/github_api/client/repos/releases/tags.rb +24 -0
- data/lib/github_api/client/repos/statistics.rb +89 -0
- data/lib/github_api/client/repos/statuses.rb +91 -0
- data/lib/github_api/client/say.rb +25 -0
- data/lib/github_api/client/scopes.rb +46 -0
- data/lib/github_api/client/search.rb +133 -0
- data/lib/github_api/client/search/legacy.rb +111 -0
- data/lib/github_api/client/users.rb +117 -0
- data/lib/github_api/client/users/emails.rb +65 -0
- data/lib/github_api/client/users/followers.rb +115 -0
- data/lib/github_api/client/users/keys.rb +104 -0
- data/lib/github_api/configuration.rb +70 -0
- data/lib/github_api/connection.rb +82 -0
- data/lib/github_api/constants.rb +61 -0
- data/lib/github_api/core_ext/array.rb +25 -0
- data/lib/github_api/core_ext/hash.rb +91 -0
- data/lib/github_api/core_ext/ordered_hash.rb +107 -0
- data/lib/github_api/deprecation.rb +39 -0
- data/lib/github_api/error.rb +32 -0
- data/lib/github_api/error/client_error.rb +89 -0
- data/lib/github_api/error/service_error.rb +223 -0
- data/lib/github_api/ext/faraday.rb +38 -0
- data/lib/github_api/mash.rb +7 -0
- data/lib/github_api/middleware.rb +37 -0
- data/lib/github_api/mime_type.rb +33 -0
- data/lib/github_api/normalizer.rb +23 -0
- data/lib/github_api/null_encoder.rb +25 -0
- data/lib/github_api/page_iterator.rb +138 -0
- data/lib/github_api/page_links.rb +63 -0
- data/lib/github_api/paged_request.rb +42 -0
- data/lib/github_api/pagination.rb +115 -0
- data/lib/github_api/parameter_filter.rb +35 -0
- data/lib/github_api/params_hash.rb +115 -0
- data/lib/github_api/rate_limit.rb +25 -0
- data/lib/github_api/request.rb +85 -0
- data/lib/github_api/request/basic_auth.rb +36 -0
- data/lib/github_api/request/jsonize.rb +54 -0
- data/lib/github_api/request/oauth2.rb +44 -0
- data/lib/github_api/request/verbs.rb +63 -0
- data/lib/github_api/response.rb +48 -0
- data/lib/github_api/response/atom_parser.rb +22 -0
- data/lib/github_api/response/follow_redirects.rb +140 -0
- data/lib/github_api/response/header.rb +87 -0
- data/lib/github_api/response/jsonize.rb +28 -0
- data/lib/github_api/response/mashify.rb +24 -0
- data/lib/github_api/response/raise_error.rb +22 -0
- data/lib/github_api/response/xmlize.rb +27 -0
- data/lib/github_api/response_wrapper.rb +161 -0
- data/lib/github_api/ssl_certs/cacerts.pem +2183 -0
- data/lib/github_api/utils/url.rb +63 -0
- data/lib/github_api/validations.rb +22 -0
- data/lib/github_api/validations/format.rb +26 -0
- data/lib/github_api/validations/presence.rb +32 -0
- data/lib/github_api/validations/required.rb +21 -0
- data/lib/github_api/validations/token.rb +41 -0
- data/lib/github_api/version.rb +5 -0
- metadata +338 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../../api'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
class Client::Search::Legacy < API
|
7
|
+
include Github::Utils::Url
|
8
|
+
|
9
|
+
# Search issues
|
10
|
+
#
|
11
|
+
# Find issues by state and keyword.
|
12
|
+
#
|
13
|
+
# @param [Hash] params
|
14
|
+
# @option params [String] :state
|
15
|
+
# Indicates the state of the issues to return. Can be either open or closed.
|
16
|
+
# @option params [String] :keyword
|
17
|
+
# The search term
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# github = Github.new
|
21
|
+
# github.search.legacy.issues 'owner', 'repo-name', 'open','api'
|
22
|
+
# github.search.legacy.issues owner: 'owner', repo: 'repo-name', state: 'open', keyword: 'api'
|
23
|
+
#
|
24
|
+
# @api public
|
25
|
+
def issues(*args)
|
26
|
+
required = %w[ owner repo state keyword ]
|
27
|
+
arguments(args, required: required)
|
28
|
+
|
29
|
+
get_request("/legacy/issues/search/#{arguments.owner}/#{arguments.repo}/#{arguments.state}/#{escape_uri(arguments.keyword)}", arguments.params)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Search repositories
|
33
|
+
#
|
34
|
+
# Find repositories by keyword.
|
35
|
+
#
|
36
|
+
# @param [Hash] params
|
37
|
+
# @option params [String] :keyword
|
38
|
+
# The search term
|
39
|
+
# @option params [String] :language
|
40
|
+
# Filter results by language
|
41
|
+
# @option params [String] :start_page
|
42
|
+
# The page number to fetch
|
43
|
+
# @option params [String] :sort
|
44
|
+
# The sort field. One of stars, forks, or updated.
|
45
|
+
# Default: results are sorted by best match.
|
46
|
+
# @option params [String] :order
|
47
|
+
# The sort field. if sort param is provided.
|
48
|
+
# Can be either asc or desc.
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
# github = Github.new
|
52
|
+
# github.search.legacy.repos 'api'
|
53
|
+
# github.search.legacy.repos keyword: 'api'
|
54
|
+
#
|
55
|
+
# @api public
|
56
|
+
def repos(*args)
|
57
|
+
arguments(args, required: [:keyword])
|
58
|
+
|
59
|
+
get_request("/legacy/repos/search/#{escape_uri(arguments.keyword)}", arguments.params)
|
60
|
+
end
|
61
|
+
alias :repositories :repos
|
62
|
+
|
63
|
+
# Search users
|
64
|
+
#
|
65
|
+
# Find users by keyword.
|
66
|
+
#
|
67
|
+
# @param [Hash] params
|
68
|
+
# @option params [String] :keyword
|
69
|
+
# The search term
|
70
|
+
# @option params [String] :start_page
|
71
|
+
# The page number to fetch
|
72
|
+
# @option params [String] :sort
|
73
|
+
# The sort field. One of stars, forks, or updated.
|
74
|
+
# Default: results are sorted by best match.
|
75
|
+
# @option params [String] :order
|
76
|
+
# The sort field. if sort param is provided.
|
77
|
+
# Can be either asc or desc.
|
78
|
+
#
|
79
|
+
# @example
|
80
|
+
# github = Github.new
|
81
|
+
# github.search.legacy.users 'user'
|
82
|
+
# github.search.legacy.users keyword: 'user'
|
83
|
+
#
|
84
|
+
# @api public
|
85
|
+
def users(*args)
|
86
|
+
arguments(args, required: [:keyword])
|
87
|
+
|
88
|
+
get_request("/legacy/user/search/#{escape_uri(arguments.keyword)}", arguments.params)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Search email
|
92
|
+
#
|
93
|
+
# This API call is added for compatibility reasons only. There’s no
|
94
|
+
# guarantee that full email searches will always be available.
|
95
|
+
#
|
96
|
+
# @param [Hash] params
|
97
|
+
# @option params [String] :email
|
98
|
+
# The email address
|
99
|
+
#
|
100
|
+
# @example
|
101
|
+
# github = Github.new
|
102
|
+
# github.search.email 'email-address'
|
103
|
+
# github.search.email email: 'email-address'
|
104
|
+
#
|
105
|
+
# @api public
|
106
|
+
def email(*args)
|
107
|
+
arguments(args, required: [:email])
|
108
|
+
get_request("/legacy/user/email/#{arguments.email}", arguments.params)
|
109
|
+
end
|
110
|
+
end # Search::Legacy
|
111
|
+
end # Github
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../api'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
class Client::Users < API
|
7
|
+
# Load all the modules after initializing Repos to avoid superclass mismatch
|
8
|
+
require_all 'github_api/client/users',
|
9
|
+
'emails',
|
10
|
+
'followers',
|
11
|
+
'keys'
|
12
|
+
|
13
|
+
VALID_USER_PARAMS_NAMES = %w[
|
14
|
+
name
|
15
|
+
email
|
16
|
+
blog
|
17
|
+
company
|
18
|
+
location
|
19
|
+
hireable
|
20
|
+
bio
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
# Access to Users::Emails API
|
24
|
+
namespace :emails
|
25
|
+
|
26
|
+
# Access to Users::Followers API
|
27
|
+
namespace :followers
|
28
|
+
|
29
|
+
# Access to Users::Keys API
|
30
|
+
namespace :keys
|
31
|
+
|
32
|
+
# List all users.
|
33
|
+
#
|
34
|
+
# This provides a dump of every user, in the order that they signed up
|
35
|
+
# for GitHub.
|
36
|
+
#
|
37
|
+
# @param [Hash] params
|
38
|
+
# @option [Integer] :since
|
39
|
+
# The integer ID of the last User that you’ve seen.
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# users = Github::Users.new
|
43
|
+
# users.list
|
44
|
+
#
|
45
|
+
# @api public
|
46
|
+
def list(*args)
|
47
|
+
arguments(args)
|
48
|
+
|
49
|
+
response = get_request("/users", arguments.params)
|
50
|
+
return response unless block_given?
|
51
|
+
response.each { |el| yield el }
|
52
|
+
end
|
53
|
+
alias :all :list
|
54
|
+
|
55
|
+
# Get a single unauthenticated user
|
56
|
+
#
|
57
|
+
# @example
|
58
|
+
# github = Github.new
|
59
|
+
# github.users.get user: 'user-name'
|
60
|
+
#
|
61
|
+
# Get the authenticated user
|
62
|
+
#
|
63
|
+
# @example
|
64
|
+
# github = Github.new oauth_token: '...'
|
65
|
+
# github.users.get
|
66
|
+
#
|
67
|
+
# @api public
|
68
|
+
def get(*args)
|
69
|
+
params = arguments(args).params
|
70
|
+
|
71
|
+
if user_name = params.delete('user')
|
72
|
+
get_request("/users/#{user_name}", params)
|
73
|
+
else
|
74
|
+
get_request("/user", params)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
alias :find :get
|
78
|
+
|
79
|
+
# Update the authenticated user
|
80
|
+
#
|
81
|
+
# @param [Hash] params
|
82
|
+
# @option params [String] :name
|
83
|
+
# Optional string
|
84
|
+
# @option params [String] :email
|
85
|
+
# Optional string - publically visible email address
|
86
|
+
# @option params [String] :blog
|
87
|
+
# Optional string
|
88
|
+
# @option params [String] :company
|
89
|
+
# Optional string
|
90
|
+
# @option params [String] :location
|
91
|
+
# Optional string
|
92
|
+
# @option params [String] :hireable
|
93
|
+
# Optional boolean
|
94
|
+
# @option params [String] :bio
|
95
|
+
# Optional string
|
96
|
+
#
|
97
|
+
# @example
|
98
|
+
# github = Github.new oauth_token: '..'
|
99
|
+
# github.users.update
|
100
|
+
# name: "monalisa octocat",
|
101
|
+
# email: "octocat@github.com",
|
102
|
+
# blog: "https://github.com/blog",
|
103
|
+
# company: "GitHub",
|
104
|
+
# location: "San Francisco",
|
105
|
+
# hireable: true,
|
106
|
+
# bio: "There once..."
|
107
|
+
#
|
108
|
+
# @api public
|
109
|
+
def update(*args)
|
110
|
+
arguments(args) do
|
111
|
+
permit VALID_USER_PARAMS_NAMES
|
112
|
+
end
|
113
|
+
|
114
|
+
patch_request("/user", arguments.params)
|
115
|
+
end
|
116
|
+
end # Users
|
117
|
+
end # Github
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
require_relative '../../api'
|
6
|
+
|
7
|
+
module Github
|
8
|
+
class Client::Users::Emails < API
|
9
|
+
|
10
|
+
# List email addresses for the authenticated user
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# github = Github.new oauth_token: '...'
|
14
|
+
# github.users.emails.list
|
15
|
+
# github.users.emails.list { |email| ... }
|
16
|
+
#
|
17
|
+
# @return [Hash]
|
18
|
+
#
|
19
|
+
# @api public
|
20
|
+
def list(*args)
|
21
|
+
arguments(args)
|
22
|
+
response = get_request("/user/emails", arguments.params)
|
23
|
+
return response unless block_given?
|
24
|
+
response.each { |el| yield el }
|
25
|
+
end
|
26
|
+
alias :all :list
|
27
|
+
|
28
|
+
# Add email address(es) for the authenticated user
|
29
|
+
#
|
30
|
+
# @param [Array[String]] emails
|
31
|
+
# You can include a single email address or an array of addresses
|
32
|
+
#
|
33
|
+
# @example
|
34
|
+
# github = Github.new oauth_token: '...'
|
35
|
+
# github.users.emails.add "octocat@github.com", "support@github.com"
|
36
|
+
#
|
37
|
+
# @api public
|
38
|
+
def add(*args)
|
39
|
+
arguments(args)
|
40
|
+
params = arguments.params
|
41
|
+
params['data'] = arguments.remaining unless arguments.remaining.empty?
|
42
|
+
|
43
|
+
post_request("/user/emails", params)
|
44
|
+
end
|
45
|
+
alias :<< :add
|
46
|
+
|
47
|
+
# Delete email address(es) for the authenticated user
|
48
|
+
#
|
49
|
+
# @param [Array[String]] emails
|
50
|
+
# You can include a single email address or an array of addresses
|
51
|
+
#
|
52
|
+
# @example
|
53
|
+
# github = Github.new oauth_token: '...'
|
54
|
+
# github.users.emails.delete "octocat@github.com", "support@github.com"
|
55
|
+
#
|
56
|
+
# @api public
|
57
|
+
def delete(*args)
|
58
|
+
arguments(args)
|
59
|
+
params = arguments.params
|
60
|
+
params['data'] = arguments.remaining unless arguments.remaining.empty?
|
61
|
+
|
62
|
+
delete_request("/user/emails", params)
|
63
|
+
end
|
64
|
+
end # Users::Emails
|
65
|
+
end # Github
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../../api'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
class Client::Users::Followers < API
|
7
|
+
|
8
|
+
# List a user's followers
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# github = Github.new
|
12
|
+
# github.users.followers.list 'user-name'
|
13
|
+
# github.users.followers.list 'user-name' { |user| ... }
|
14
|
+
#
|
15
|
+
# List the authenticated user's followers
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# github = Github.new oauth_token: '...'
|
19
|
+
# github.users.followers
|
20
|
+
# github.users.followers { |user| ... }
|
21
|
+
#
|
22
|
+
# @api public
|
23
|
+
def list(*args)
|
24
|
+
params = arguments(args).params
|
25
|
+
|
26
|
+
response = if user_name = arguments.remaining.first
|
27
|
+
get_request("/users/#{user_name}/followers", params)
|
28
|
+
else
|
29
|
+
get_request("/user/followers", params)
|
30
|
+
end
|
31
|
+
return response unless block_given?
|
32
|
+
response.each { |el| yield el }
|
33
|
+
end
|
34
|
+
alias :all :list
|
35
|
+
|
36
|
+
# List who a user is following
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# github = Github.new
|
40
|
+
# github.users.followers.following 'user-name'
|
41
|
+
# github.users.followers.following 'user-name' { |user| ... }
|
42
|
+
#
|
43
|
+
# List who the authenicated user is following
|
44
|
+
#
|
45
|
+
# @example
|
46
|
+
# github = Github.new oauth_token: '...'
|
47
|
+
# github.users.followers.following
|
48
|
+
#
|
49
|
+
# @api public
|
50
|
+
def following(*args)
|
51
|
+
params = arguments(args).params
|
52
|
+
|
53
|
+
response = if user_name = arguments.remaining.first
|
54
|
+
get_request("/users/#{user_name}/following", params)
|
55
|
+
else
|
56
|
+
get_request("/user/following", params)
|
57
|
+
end
|
58
|
+
return response unless block_given?
|
59
|
+
response.each { |el| yield el }
|
60
|
+
end
|
61
|
+
|
62
|
+
# Check if you are following a user
|
63
|
+
#
|
64
|
+
# @example
|
65
|
+
# github = Github.new oauth_token: '...'
|
66
|
+
# github.users.followers.following? 'user-name'
|
67
|
+
# github.users.followers.following? username: 'user-name'
|
68
|
+
#
|
69
|
+
# Check if one user follows another
|
70
|
+
#
|
71
|
+
# @example
|
72
|
+
# github = Github.new oauth_token: '...'
|
73
|
+
# github.users.followers.following? username: 'user-name',
|
74
|
+
# target_user: 'target-user-name'
|
75
|
+
#
|
76
|
+
# @api public
|
77
|
+
def following?(*args)
|
78
|
+
arguments(args, required: [:username])
|
79
|
+
params = arguments.params
|
80
|
+
if target_user = params.delete('target_user')
|
81
|
+
get_request("/users/#{arguments.username}/following/#{target_user}", params)
|
82
|
+
else
|
83
|
+
get_request("/user/following/#{arguments.username}", params)
|
84
|
+
end
|
85
|
+
true
|
86
|
+
rescue Github::Error::NotFound
|
87
|
+
false
|
88
|
+
end
|
89
|
+
|
90
|
+
# Follow a user
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# github = Github.new oauth_token: '...'
|
94
|
+
# github.users.followers.follow 'user-name'
|
95
|
+
# github.users.followers.follow username: 'user-name'
|
96
|
+
#
|
97
|
+
# @api public
|
98
|
+
def follow(*args)
|
99
|
+
arguments(args, required: [:username])
|
100
|
+
put_request("/user/following/#{arguments.username}", arguments.params)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Unfollow a user
|
104
|
+
#
|
105
|
+
# @example
|
106
|
+
# github = Github.new oauth_token: '...'
|
107
|
+
# github.users.followers.unfollow 'user-name'
|
108
|
+
# github.users.followers.unfollow username: 'user-name'
|
109
|
+
#
|
110
|
+
def unfollow(*args)
|
111
|
+
arguments(args, required: [:username])
|
112
|
+
delete_request("/user/following/#{arguments.username}", arguments.params)
|
113
|
+
end
|
114
|
+
end # Users::Followers
|
115
|
+
end # Github
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../../api'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
class Client::Users::Keys < API
|
7
|
+
|
8
|
+
VALID_KEY_PARAM_NAMES = %w[ title key ].freeze
|
9
|
+
|
10
|
+
# List public keys for the authenticated user
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# github = Github.new oauth_token: '...'
|
14
|
+
# github.users.keys.list
|
15
|
+
# github.users.keys.list { |key| ... }
|
16
|
+
#
|
17
|
+
# List public keys for the specified user
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# github.users.keys.list user: 'user-name'
|
21
|
+
# github.users.keys.list user: 'user-name' { |key| ... }
|
22
|
+
#
|
23
|
+
# @return [Hash]
|
24
|
+
#
|
25
|
+
# @api public
|
26
|
+
def list(*args)
|
27
|
+
params = arguments(args).params
|
28
|
+
response = if (user = params.delete('user'))
|
29
|
+
get_request("/users/#{user}/keys", params)
|
30
|
+
else
|
31
|
+
get_request("/user/keys", params)
|
32
|
+
end
|
33
|
+
return response unless block_given?
|
34
|
+
response.each { |el| yield el }
|
35
|
+
end
|
36
|
+
alias :all :list
|
37
|
+
|
38
|
+
# Get a single pulic key for the authenticated user
|
39
|
+
#
|
40
|
+
# @example
|
41
|
+
# github = Github.new oauth_token: '...'
|
42
|
+
# github.users.keys.get 'key-id'
|
43
|
+
#
|
44
|
+
# @api public
|
45
|
+
def get(*args)
|
46
|
+
arguments(args, required: [:id])
|
47
|
+
get_request("/user/keys/#{arguments.id}", arguments.params)
|
48
|
+
end
|
49
|
+
alias :find :get
|
50
|
+
|
51
|
+
# Create a public key for the authenticated user
|
52
|
+
#
|
53
|
+
# @param [Hash] params
|
54
|
+
# @option [String] :title
|
55
|
+
# Required string
|
56
|
+
# @option [String] :key
|
57
|
+
# Required string. sha key
|
58
|
+
#
|
59
|
+
# @example
|
60
|
+
# github = Github.new oauth_token: '...'
|
61
|
+
# github.users.keys.create "title": "octocat@octomac", "key": "ssh-rsa AAA..."
|
62
|
+
#
|
63
|
+
# @api public
|
64
|
+
def create(*args)
|
65
|
+
arguments(args) do
|
66
|
+
permit VALID_KEY_PARAM_NAMES
|
67
|
+
end
|
68
|
+
post_request("/user/keys", arguments.params)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Update a public key for the authenticated user
|
72
|
+
#
|
73
|
+
# @param [Hash] params
|
74
|
+
# @option [String] :title
|
75
|
+
# Required string
|
76
|
+
# @option [String] :key
|
77
|
+
# Required string. sha key
|
78
|
+
#
|
79
|
+
# @example
|
80
|
+
# github = Github.new oauth_token: '...'
|
81
|
+
# github.users.keys.update 'key-id', "title": "octocat@octomac",
|
82
|
+
# "key": "ssh-rsa AAA..."
|
83
|
+
#
|
84
|
+
# @api public
|
85
|
+
def update(*args)
|
86
|
+
arguments(args, required: [:id]) do
|
87
|
+
permit VALID_KEY_PARAM_NAMES
|
88
|
+
end
|
89
|
+
patch_request("/user/keys/#{arguments.id}", arguments.params)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Delete a public key for the authenticated user
|
93
|
+
#
|
94
|
+
# @example
|
95
|
+
# github = Github.new oauth_token: '...'
|
96
|
+
# github.users.keys.delete 'key-id'
|
97
|
+
#
|
98
|
+
# @api public
|
99
|
+
def delete(*args)
|
100
|
+
arguments(args, required: [:id])
|
101
|
+
delete_request("/user/keys/#{arguments.id}", arguments.params)
|
102
|
+
end
|
103
|
+
end # Users::Keys
|
104
|
+
end # Github
|