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,142 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../api'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
# OAuth Authorizations API
|
7
|
+
class Client::Authorizations < API
|
8
|
+
|
9
|
+
require_all 'github_api/client/authorizations', 'app'
|
10
|
+
|
11
|
+
# Access to Authorizations::App API
|
12
|
+
namespace :app
|
13
|
+
|
14
|
+
# List authorizations
|
15
|
+
#
|
16
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#list-your-authorizations
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# github = Github.new basic_auth: 'login:password'
|
20
|
+
# github.auth.list
|
21
|
+
# github.auth.list { |auth| ... }
|
22
|
+
#
|
23
|
+
# @api public
|
24
|
+
def list(*args)
|
25
|
+
raise_authentication_error unless authenticated?
|
26
|
+
arguments(args)
|
27
|
+
|
28
|
+
response = get_request('/authorizations', arguments.params)
|
29
|
+
return response unless block_given?
|
30
|
+
response.each { |el| yield el }
|
31
|
+
end
|
32
|
+
alias_method :all, :list
|
33
|
+
|
34
|
+
# Get a single authorization
|
35
|
+
#
|
36
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#get-a-single-authorization
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# github = Github.new basic_auth: 'login:password'
|
40
|
+
# github.oauth.get 'authorization-id'
|
41
|
+
#
|
42
|
+
# @return [ResponseWrapper]
|
43
|
+
#
|
44
|
+
# @api public
|
45
|
+
def get(*args)
|
46
|
+
raise_authentication_error unless authenticated?
|
47
|
+
arguments(args, required: [:id])
|
48
|
+
|
49
|
+
get_request("/authorizations/#{arguments.id}", arguments.params)
|
50
|
+
end
|
51
|
+
alias_method :find, :get
|
52
|
+
|
53
|
+
# Create a new authorization
|
54
|
+
#
|
55
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization
|
56
|
+
#
|
57
|
+
# @param [Hash] params
|
58
|
+
# @option params [Array[String]] :scopes
|
59
|
+
# A list of scopes that this authorization is in.
|
60
|
+
# @option params [String] :note
|
61
|
+
# Required. A note to remind you what the OAuth token is for.
|
62
|
+
# @option params [String] :note_url
|
63
|
+
# A URL to remind you what the OAuth token is for.
|
64
|
+
# @option params [String] :client_id
|
65
|
+
# The 20 character OAuth app client key for which to create the token.
|
66
|
+
# @option params [String] :client_secret
|
67
|
+
# The 40 character OAuth app client secret for which to create the token.
|
68
|
+
# @option params [String] :fingerprint
|
69
|
+
# A unique string to distinguish an authorization from others
|
70
|
+
# created for the same client ID and user.
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# github = Github.new basic_auth: 'login:password'
|
74
|
+
# github.oauth.create scopes: ["public_repo"], note: 'amdmin script'
|
75
|
+
#
|
76
|
+
# @api public
|
77
|
+
def create(*args)
|
78
|
+
raise_authentication_error unless authenticated?
|
79
|
+
arguments(args) do
|
80
|
+
assert_required :note, :scopes
|
81
|
+
end
|
82
|
+
|
83
|
+
post_request('/authorizations', arguments.params)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Update an existing authorization
|
87
|
+
#
|
88
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#update-an-existing-authorization
|
89
|
+
#
|
90
|
+
# @param [Hash] inputs
|
91
|
+
# @option inputs [Array] :scopes
|
92
|
+
# Optional array - A list of scopes that this authorization is in.
|
93
|
+
# @option inputs [Array] :add_scopes
|
94
|
+
# Optional array - A list of scopes to add to this authorization.
|
95
|
+
# @option inputs [Array] :remove_scopes
|
96
|
+
# Optional array - A list of scopes to remove from this authorization.
|
97
|
+
# @option inputs [String] :note
|
98
|
+
# Optional string - A note to remind you what the OAuth token is for.
|
99
|
+
# @optoin inputs [String] :note_url
|
100
|
+
# Optional string - A URL to remind you what the OAuth token is for.
|
101
|
+
# @option params [String] :fingerprint
|
102
|
+
# A unique string to distinguish an authorization from others
|
103
|
+
# created for the same client ID and user.
|
104
|
+
#
|
105
|
+
# @example
|
106
|
+
# github = Github.new basic_auth: 'login:password'
|
107
|
+
# github.oauth.update "authorization-id", add_scopes: ["repo"]
|
108
|
+
#
|
109
|
+
# @api public
|
110
|
+
def update(*args)
|
111
|
+
raise_authentication_error unless authenticated?
|
112
|
+
arguments(args, required: [:id])
|
113
|
+
|
114
|
+
patch_request("/authorizations/#{arguments.id}", arguments.params)
|
115
|
+
end
|
116
|
+
alias_method :edit, :update
|
117
|
+
|
118
|
+
# Delete an authorization
|
119
|
+
#
|
120
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#delete-an-authorization
|
121
|
+
#
|
122
|
+
# @example
|
123
|
+
# github = Github.new
|
124
|
+
# github.oauth.delete 'authorization-id'
|
125
|
+
#
|
126
|
+
# @api public
|
127
|
+
def delete(*args)
|
128
|
+
raise_authentication_error unless authenticated?
|
129
|
+
arguments(args, required: [:id])
|
130
|
+
|
131
|
+
delete_request("/authorizations/#{arguments.id}", arguments.params)
|
132
|
+
end
|
133
|
+
alias_method :remove, :delete
|
134
|
+
|
135
|
+
protected
|
136
|
+
|
137
|
+
def raise_authentication_error
|
138
|
+
raise ArgumentError, 'You can only access your own tokens' \
|
139
|
+
' via Basic Authentication'
|
140
|
+
end
|
141
|
+
end # Client::Authorizations
|
142
|
+
end # Github
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../../api'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
class Client::Authorizations::App < Client::Authorizations
|
7
|
+
# Get-or-create an authorization for a specific app
|
8
|
+
#
|
9
|
+
# @see https://developer.github.com/v3/oauth_authorizations/#get-or-create-an-authorization-for-a-specific-app
|
10
|
+
#
|
11
|
+
# @param [Hash] params
|
12
|
+
# @option params [String] client_secret
|
13
|
+
# The 40 character OAuth app client secret associated with the client
|
14
|
+
# ID specified in the URL.
|
15
|
+
# @option params [Array] :scopes
|
16
|
+
# Optional array - A list of scopes that this authorization is in.
|
17
|
+
# @option params [String] :note
|
18
|
+
# Optional string - A note to remind you what the OAuth token is for.
|
19
|
+
# @option params [String] :note_url
|
20
|
+
# Optional string - A URL to remind you what the OAuth token is for.
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
# github = Github.new
|
24
|
+
# github.oauth.app.create 'client-id', client_secret: '...'
|
25
|
+
#
|
26
|
+
# @api public
|
27
|
+
def create(*args)
|
28
|
+
raise_authentication_error unless authenticated?
|
29
|
+
arguments(args, required: [:client_id])
|
30
|
+
|
31
|
+
if arguments.client_id
|
32
|
+
put_request("/authorizations/clients/#{arguments.client_id}", arguments.params)
|
33
|
+
else
|
34
|
+
raise raise_app_authentication_error
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Check if an access token is a valid authorization for an application
|
39
|
+
#
|
40
|
+
# @example
|
41
|
+
# github = Github.new basic_auth: "client_id:client_secret"
|
42
|
+
# github.oauth.app.check 'client_id', 'access-token'
|
43
|
+
#
|
44
|
+
# @api public
|
45
|
+
def check(*args)
|
46
|
+
raise_authentication_error unless authenticated?
|
47
|
+
params = arguments(args, required: [:client_id, :access_token]).params
|
48
|
+
|
49
|
+
if arguments.client_id
|
50
|
+
begin
|
51
|
+
get_request("/applications/#{arguments.client_id}/tokens/#{arguments.access_token}", params)
|
52
|
+
rescue Github::Error::NotFound
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
else
|
56
|
+
raise raise_app_authentication_error
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Revoke all authorizations for an application
|
61
|
+
#
|
62
|
+
# @example
|
63
|
+
# github = Github.new basic_auth: "client_id:client_secret"
|
64
|
+
# github.oauth.app.delete 'client-id'
|
65
|
+
#
|
66
|
+
# Revoke an authorization for an application
|
67
|
+
#
|
68
|
+
# @example
|
69
|
+
# github = Github.new basic_auth: "client_id:client_secret"
|
70
|
+
# github.oauth.app.delete 'client-id', 'access-token'
|
71
|
+
#
|
72
|
+
# @api public
|
73
|
+
def delete(*args)
|
74
|
+
raise_authentication_error unless authenticated?
|
75
|
+
params = arguments(args, required: [:client_id]).params
|
76
|
+
|
77
|
+
if arguments.client_id
|
78
|
+
if access_token = (params.delete('access_token') || args[1])
|
79
|
+
delete_request("/applications/#{arguments.client_id}/tokens/#{access_token}", params)
|
80
|
+
else
|
81
|
+
# Revokes all tokens
|
82
|
+
delete_request("/applications/#{arguments.client_id}/tokens", params)
|
83
|
+
end
|
84
|
+
else
|
85
|
+
raise raise_app_authentication_error
|
86
|
+
end
|
87
|
+
end
|
88
|
+
alias :remove :delete
|
89
|
+
alias :revoke :delete
|
90
|
+
|
91
|
+
protected
|
92
|
+
|
93
|
+
def raise_app_authentication_error
|
94
|
+
raise ArgumentError, 'To create authorization for the app, ' +
|
95
|
+
'you need to provide client_id argument and client_secret parameter'
|
96
|
+
end
|
97
|
+
end # Client::Authorizations::App
|
98
|
+
end # Github
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../api'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
class Client::Emojis < API
|
7
|
+
# Lists all the emojis.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# Github.emojis.list
|
11
|
+
#
|
12
|
+
# @api public
|
13
|
+
def list(*args)
|
14
|
+
arguments(args)
|
15
|
+
|
16
|
+
get_request("/emojis", arguments.params)
|
17
|
+
end
|
18
|
+
end # Client::Emojis
|
19
|
+
end # Github
|
@@ -0,0 +1,289 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../api'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
class Client::Gists < API
|
7
|
+
|
8
|
+
require_all 'github_api/client/gists', 'comments'
|
9
|
+
|
10
|
+
# Access to Gists::Comments API
|
11
|
+
namespace :comments
|
12
|
+
|
13
|
+
# List a user's gists
|
14
|
+
#
|
15
|
+
# @see https://developer.github.com/v3/gists/#list-a-users-gists
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# github = Github.new
|
19
|
+
# github.gists.list user: 'user-name'
|
20
|
+
#
|
21
|
+
# List the authenticated user’s gists or if called anonymously,
|
22
|
+
# this will returns all public gists
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# github = Github.new oauth_token: '...'
|
26
|
+
# github.gists.list
|
27
|
+
#
|
28
|
+
# List all public gists
|
29
|
+
#
|
30
|
+
# @see https://developer.github.com/v3/gists/#list-all-public-gists
|
31
|
+
#
|
32
|
+
# github = Github.new
|
33
|
+
# github.gists.list :public
|
34
|
+
#
|
35
|
+
# @return [Hash]
|
36
|
+
#
|
37
|
+
# @api public
|
38
|
+
def list(*args)
|
39
|
+
params = arguments(args).params
|
40
|
+
|
41
|
+
response = if (user = params.delete('user'))
|
42
|
+
get_request("/users/#{user}/gists", params)
|
43
|
+
elsif args.map(&:to_s).include?('public')
|
44
|
+
get_request("/gists/public", params)
|
45
|
+
else
|
46
|
+
get_request("/gists", params)
|
47
|
+
end
|
48
|
+
return response unless block_given?
|
49
|
+
response.each { |el| yield el }
|
50
|
+
end
|
51
|
+
alias_method :all, :list
|
52
|
+
|
53
|
+
# List the authenticated user's starred gists
|
54
|
+
#
|
55
|
+
# @see https://developer.github.com/v3/gists/#list-starred-gists
|
56
|
+
#
|
57
|
+
# @example
|
58
|
+
# github = Github.new oauth_token: '...'
|
59
|
+
# github.gists.starred
|
60
|
+
#
|
61
|
+
# @return [Hash]
|
62
|
+
#
|
63
|
+
# @api public
|
64
|
+
def starred(*args)
|
65
|
+
arguments(args)
|
66
|
+
response = get_request("/gists/starred", arguments.params)
|
67
|
+
return response unless block_given?
|
68
|
+
response.each { |el| yield el }
|
69
|
+
end
|
70
|
+
|
71
|
+
# Get a single gist
|
72
|
+
#
|
73
|
+
# @see https://developer.github.com/v3/gists/#get-a-single-gist
|
74
|
+
#
|
75
|
+
# @example
|
76
|
+
# github = Github.new
|
77
|
+
# github.gists.get 'gist-id'
|
78
|
+
#
|
79
|
+
# Get a specific revision of gist
|
80
|
+
#
|
81
|
+
# @see https://developer.github.com/v3/gists/#get-a-specific-revision-of-a-gist
|
82
|
+
#
|
83
|
+
# @example
|
84
|
+
# github = Github.new
|
85
|
+
# github.gists.get 'gist-id', sha: '
|
86
|
+
#
|
87
|
+
# @return [Hash]
|
88
|
+
#
|
89
|
+
# @api public
|
90
|
+
def get(*args)
|
91
|
+
arguments(args, required: [:id])
|
92
|
+
|
93
|
+
if (sha = arguments.params.delete('sha'))
|
94
|
+
get_request("/gists/#{arguments.id}/#{sha}")
|
95
|
+
else
|
96
|
+
get_request("/gists/#{arguments.id}", arguments.params)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
alias_method :find, :get
|
100
|
+
|
101
|
+
# Create a gist
|
102
|
+
#
|
103
|
+
# @see https://developer.github.com/v3/gists/#create-a-gist
|
104
|
+
#
|
105
|
+
# @param [Hash] params
|
106
|
+
# @option params [String] :description
|
107
|
+
# Optional string
|
108
|
+
# @option params [Boolean] :public
|
109
|
+
# Required boolean
|
110
|
+
# @option params [Hash] :files
|
111
|
+
# Required hash - Files that make up this gist.
|
112
|
+
# The key of which should be a required string filename and
|
113
|
+
# the value another required hash with parameters:
|
114
|
+
# @option files [String] :content
|
115
|
+
# Required string - File contents.
|
116
|
+
#
|
117
|
+
# @example
|
118
|
+
# github = Github.new
|
119
|
+
# github.gists.create
|
120
|
+
# description: 'the description for this gist',
|
121
|
+
# public: true,
|
122
|
+
# files: {
|
123
|
+
# 'file1.txt' => {
|
124
|
+
# content: 'String file contents'
|
125
|
+
# }
|
126
|
+
# }
|
127
|
+
#
|
128
|
+
# @return [Hash]
|
129
|
+
#
|
130
|
+
# @api public
|
131
|
+
def create(*args)
|
132
|
+
arguments(args)
|
133
|
+
|
134
|
+
post_request("/gists", arguments.params)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Edit a gist
|
138
|
+
#
|
139
|
+
# @see https://developer.github.com/v3/gists/#edit-a-gist
|
140
|
+
#
|
141
|
+
# @param [Hash] params
|
142
|
+
# @option [String] :description
|
143
|
+
# Optional string
|
144
|
+
# @option [Hash] :files
|
145
|
+
# Optional hash - Files that make up this gist.
|
146
|
+
# The key of which should be a optional string filename and
|
147
|
+
# the value another optional hash with parameters:
|
148
|
+
# @option [String] :content
|
149
|
+
# Updated string - Update file contents.
|
150
|
+
# @option [String] :filename
|
151
|
+
# Optional string - New name for this file.
|
152
|
+
#
|
153
|
+
# @xample
|
154
|
+
# github = Github.new oauth_token: '...'
|
155
|
+
# github.gists.edit 'gist-id',
|
156
|
+
# description: 'the description for this gist',
|
157
|
+
# files: {
|
158
|
+
# 'file1.txt' => {
|
159
|
+
# content: 'Updated file contents'
|
160
|
+
# },
|
161
|
+
# 'old_name.txt' => {
|
162
|
+
# filename: 'new_name.txt',
|
163
|
+
# content: 'modified contents'
|
164
|
+
# },
|
165
|
+
# 'new_file.txt' => {
|
166
|
+
# content: 'a new file contents'
|
167
|
+
# },
|
168
|
+
# 'delete_the_file.txt' => nil
|
169
|
+
# }
|
170
|
+
#
|
171
|
+
# @return [Hash]
|
172
|
+
#
|
173
|
+
# @api public
|
174
|
+
def edit(*args)
|
175
|
+
arguments(args, required: [:id])
|
176
|
+
|
177
|
+
patch_request("/gists/#{arguments.id}", arguments.params)
|
178
|
+
end
|
179
|
+
|
180
|
+
# List gist commits
|
181
|
+
#
|
182
|
+
# @see https://developer.github.com/v3/gists/#list-gist-commits
|
183
|
+
#
|
184
|
+
# @example
|
185
|
+
# github = Github.new
|
186
|
+
# github.gists.commits 'gist-id'
|
187
|
+
#
|
188
|
+
# @api public
|
189
|
+
def commits(*args)
|
190
|
+
arguments(args, required: [:id])
|
191
|
+
|
192
|
+
response = get_request("/gists/#{arguments.id}/commits")
|
193
|
+
return response unless block_given?
|
194
|
+
response.each { |el| yield el }
|
195
|
+
end
|
196
|
+
|
197
|
+
# Star a gist
|
198
|
+
#
|
199
|
+
# @see https://developer.github.com/v3/gists/#star-a-gist
|
200
|
+
#
|
201
|
+
# @example
|
202
|
+
# github = Github.new
|
203
|
+
# github.gists.star 'gist-id'
|
204
|
+
#
|
205
|
+
# @api public
|
206
|
+
def star(*args)
|
207
|
+
arguments(args, required: [:id])
|
208
|
+
|
209
|
+
put_request("/gists/#{arguments.id}/star", arguments.params)
|
210
|
+
end
|
211
|
+
|
212
|
+
# Unstar a gist
|
213
|
+
#
|
214
|
+
# @see https://developer.github.com/v3/gists/#unstar-a-gist
|
215
|
+
#
|
216
|
+
# @xample
|
217
|
+
# github = Github.new
|
218
|
+
# github.gists.unstar 'gist-id'
|
219
|
+
#
|
220
|
+
# @api public
|
221
|
+
def unstar(*args)
|
222
|
+
arguments(args, required: [:id])
|
223
|
+
|
224
|
+
delete_request("/gists/#{arguments.id}/star", arguments.params)
|
225
|
+
end
|
226
|
+
|
227
|
+
# Check if a gist is starred
|
228
|
+
#
|
229
|
+
# @see https://developer.github.com/v3/gists/#check-if-a-gist-is-starred
|
230
|
+
#
|
231
|
+
# @example
|
232
|
+
# github = Github.new
|
233
|
+
# github.gists.starred? 'gist-id'
|
234
|
+
#
|
235
|
+
# @api public
|
236
|
+
def starred?(*args)
|
237
|
+
arguments(args, required: [:id])
|
238
|
+
get_request("/gists/#{arguments.id}/star", arguments.params)
|
239
|
+
true
|
240
|
+
rescue Github::Error::NotFound
|
241
|
+
false
|
242
|
+
end
|
243
|
+
|
244
|
+
# Fork a gist
|
245
|
+
#
|
246
|
+
# @example
|
247
|
+
# github = Github.new
|
248
|
+
# github.gists.fork 'gist-id'
|
249
|
+
#
|
250
|
+
# @api public
|
251
|
+
def fork(*args)
|
252
|
+
arguments(args, required: [:id])
|
253
|
+
|
254
|
+
post_request("/gists/#{arguments.id}/forks", arguments.params)
|
255
|
+
end
|
256
|
+
|
257
|
+
# List gist forks
|
258
|
+
#
|
259
|
+
# @see https://developer.github.com/v3/gists/#list-gist-forks
|
260
|
+
#
|
261
|
+
# @example
|
262
|
+
# github = Github.new
|
263
|
+
# github.gists.forks 'gist-id'
|
264
|
+
#
|
265
|
+
# @api public
|
266
|
+
def forks(*args)
|
267
|
+
arguments(args, required: [:id])
|
268
|
+
|
269
|
+
response = get_request("/gists/#{arguments.id}/forks")
|
270
|
+
return response unless block_given?
|
271
|
+
response.each { |el| yield el }
|
272
|
+
end
|
273
|
+
|
274
|
+
# Delete a gist
|
275
|
+
#
|
276
|
+
# @see https://developer.github.com/v3/gists/#delete-a-gist
|
277
|
+
#
|
278
|
+
# @example
|
279
|
+
# github = Github.new
|
280
|
+
# github.gists.delete 'gist-id'
|
281
|
+
#
|
282
|
+
# @api public
|
283
|
+
def delete(*args)
|
284
|
+
arguments(args, required: [:id])
|
285
|
+
|
286
|
+
delete_request("/gists/#{arguments.id}", arguments.params)
|
287
|
+
end
|
288
|
+
end # Gists
|
289
|
+
end # Github
|