octodoggy 4.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/CONTRIBUTING.md +22 -0
- data/LICENSE.md +20 -0
- data/README.md +714 -0
- data/Rakefile +22 -0
- data/lib/ext/sawyer/relation.rb +10 -0
- data/lib/octokit.rb +59 -0
- data/lib/octokit/arguments.rb +14 -0
- data/lib/octokit/authentication.rb +82 -0
- data/lib/octokit/client.rb +238 -0
- data/lib/octokit/client/authorizations.rb +244 -0
- data/lib/octokit/client/commit_comments.rb +95 -0
- data/lib/octokit/client/commits.rb +239 -0
- data/lib/octokit/client/contents.rb +162 -0
- data/lib/octokit/client/deployments.rb +62 -0
- data/lib/octokit/client/downloads.rb +50 -0
- data/lib/octokit/client/emojis.rb +18 -0
- data/lib/octokit/client/events.rb +151 -0
- data/lib/octokit/client/feeds.rb +33 -0
- data/lib/octokit/client/gists.rb +233 -0
- data/lib/octokit/client/gitignore.rb +43 -0
- data/lib/octokit/client/hooks.rb +297 -0
- data/lib/octokit/client/integrations.rb +77 -0
- data/lib/octokit/client/issues.rb +321 -0
- data/lib/octokit/client/labels.rb +156 -0
- data/lib/octokit/client/legacy_search.rb +42 -0
- data/lib/octokit/client/licenses.rb +45 -0
- data/lib/octokit/client/markdown.rb +27 -0
- data/lib/octokit/client/meta.rb +21 -0
- data/lib/octokit/client/milestones.rb +87 -0
- data/lib/octokit/client/notifications.rb +171 -0
- data/lib/octokit/client/objects.rb +141 -0
- data/lib/octokit/client/organizations.rb +768 -0
- data/lib/octokit/client/pages.rb +63 -0
- data/lib/octokit/client/projects.rb +314 -0
- data/lib/octokit/client/pub_sub_hubbub.rb +111 -0
- data/lib/octokit/client/pull_requests.rb +301 -0
- data/lib/octokit/client/rate_limit.rb +54 -0
- data/lib/octokit/client/reactions.rb +158 -0
- data/lib/octokit/client/refs.rb +118 -0
- data/lib/octokit/client/releases.rb +163 -0
- data/lib/octokit/client/repositories.rb +654 -0
- data/lib/octokit/client/repository_invitations.rb +103 -0
- data/lib/octokit/client/reviews.rb +174 -0
- data/lib/octokit/client/say.rb +19 -0
- data/lib/octokit/client/search.rb +76 -0
- data/lib/octokit/client/service_status.rb +38 -0
- data/lib/octokit/client/source_import.rb +161 -0
- data/lib/octokit/client/stats.rb +105 -0
- data/lib/octokit/client/statuses.rb +47 -0
- data/lib/octokit/client/traffic.rb +69 -0
- data/lib/octokit/client/users.rb +354 -0
- data/lib/octokit/configurable.rb +147 -0
- data/lib/octokit/connection.rb +199 -0
- data/lib/octokit/default.rb +166 -0
- data/lib/octokit/enterprise_admin_client.rb +40 -0
- data/lib/octokit/enterprise_admin_client/admin_stats.rb +120 -0
- data/lib/octokit/enterprise_admin_client/license.rb +18 -0
- data/lib/octokit/enterprise_admin_client/orgs.rb +27 -0
- data/lib/octokit/enterprise_admin_client/search_indexing.rb +83 -0
- data/lib/octokit/enterprise_admin_client/users.rb +128 -0
- data/lib/octokit/enterprise_management_console_client.rb +50 -0
- data/lib/octokit/enterprise_management_console_client/management_console.rb +176 -0
- data/lib/octokit/error.rb +286 -0
- data/lib/octokit/gist.rb +36 -0
- data/lib/octokit/middleware/follow_redirects.rb +131 -0
- data/lib/octokit/organization.rb +17 -0
- data/lib/octokit/preview.rb +38 -0
- data/lib/octokit/rate_limit.rb +33 -0
- data/lib/octokit/repo_arguments.rb +19 -0
- data/lib/octokit/repository.rb +93 -0
- data/lib/octokit/response/feed_parser.rb +21 -0
- data/lib/octokit/response/raise_error.rb +21 -0
- data/lib/octokit/user.rb +19 -0
- data/lib/octokit/version.rb +17 -0
- data/lib/octokit/warnable.rb +17 -0
- data/octokit.gemspec +22 -0
- metadata +160 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
module Octokit
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for the Pages API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/repos/pages/
|
7
|
+
module Pages
|
8
|
+
|
9
|
+
# List Pages information for a repository
|
10
|
+
#
|
11
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
12
|
+
# @return Sawyer::Resource A GitHub Pages resource
|
13
|
+
# @see https://developer.github.com/v3/repos/pages/#get-information-about-a-pages-site
|
14
|
+
def pages(repo, options = {})
|
15
|
+
get "#{Repository.path repo}/pages", options
|
16
|
+
end
|
17
|
+
|
18
|
+
# Get a specific Pages build by ID
|
19
|
+
#
|
20
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
21
|
+
# @param id [Integer, String] Build ID
|
22
|
+
# @return [Sawyer::Resource] Pages build information
|
23
|
+
# @see https://developer.github.com/v3/repos/pages/#list-a-specific-pages-build
|
24
|
+
# @example
|
25
|
+
# Octokit.pages_build("github/developer.github.com", 5472601)
|
26
|
+
def pages_build(repo, id, options = {})
|
27
|
+
opts = ensure_api_media_type(:pages, options)
|
28
|
+
get "#{Repository.path repo}/pages/builds/#{id}", opts
|
29
|
+
end
|
30
|
+
|
31
|
+
# List Pages builds for a repository
|
32
|
+
#
|
33
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
34
|
+
# @return [Array<Sawyer::Resource>] A list of build history for a repository.
|
35
|
+
# @see https://developer.github.com/v3/repos/pages/#list-pages-builds
|
36
|
+
def pages_builds(repo, options = {})
|
37
|
+
get "#{Repository.path repo}/pages/builds", options
|
38
|
+
end
|
39
|
+
alias :list_pages_builds :pages_builds
|
40
|
+
|
41
|
+
# List the latest Pages build information for a repository
|
42
|
+
#
|
43
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
44
|
+
# @return Sawyer::Resource A GitHub Pages resource about a build
|
45
|
+
# @see https://developer.github.com/v3/repos/pages/#list-latest-pages-build
|
46
|
+
def latest_pages_build(repo, options = {})
|
47
|
+
get "#{Repository.path repo}/pages/builds/latest", options
|
48
|
+
end
|
49
|
+
|
50
|
+
# Request a page build for the latest revision of the default branch
|
51
|
+
#
|
52
|
+
# You can only request builds for your repositories
|
53
|
+
#
|
54
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
55
|
+
# @return [Sawyer::Resource] Request result
|
56
|
+
# @see https://developer.github.com/v3/repos/pages/#request-a-page-build
|
57
|
+
def request_page_build(repo, options = {})
|
58
|
+
opts = ensure_api_media_type(:pages, options)
|
59
|
+
post "#{Repository.path repo}/pages/builds", opts
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,314 @@
|
|
1
|
+
module Octokit
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for Projects API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/repos/projects
|
7
|
+
module Projects
|
8
|
+
|
9
|
+
# List projects for a repository
|
10
|
+
#
|
11
|
+
# Requires authenticated client
|
12
|
+
#
|
13
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
14
|
+
# @return [Array<Sawyer::Resource>] Repository projects
|
15
|
+
# @see https://developer.github.com/v3/projects/#list-repository-projects
|
16
|
+
# @example
|
17
|
+
# @client.projects('octokit/octokit.rb')
|
18
|
+
def projects(repo, options = {})
|
19
|
+
opts = ensure_api_media_type(:projects, options)
|
20
|
+
paginate "#{Repository.path repo}/projects", opts
|
21
|
+
end
|
22
|
+
|
23
|
+
# Create a project
|
24
|
+
#
|
25
|
+
# Requires authenticated client
|
26
|
+
#
|
27
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
28
|
+
# @param name [String] Project name
|
29
|
+
# @option options [String] :body Body of the project
|
30
|
+
# @return [Sawyer::Resource] Fresh new project
|
31
|
+
# @see https://developer.github.com/v3/projects/#create-a-repository-project
|
32
|
+
# @example Create project with only a name
|
33
|
+
# @client.create_project('octokit/octokit.rb', 'implement new APIs')
|
34
|
+
#
|
35
|
+
# @example Create project with name and body
|
36
|
+
# @client.create_project('octokit/octokit.rb', 'bugs be gone', body: 'Fix all the bugs @joeyw creates')
|
37
|
+
def create_project(repo, name, options = {})
|
38
|
+
opts = ensure_api_media_type(:projects, options)
|
39
|
+
opts[:name] = name
|
40
|
+
post "#{Repository.path repo}/projects", opts
|
41
|
+
end
|
42
|
+
|
43
|
+
# List organization projects
|
44
|
+
#
|
45
|
+
# Requires authenticated client
|
46
|
+
#
|
47
|
+
# @param org [String] A GitHub organization
|
48
|
+
# @return [Array<Sawyer::Resource>] Organization projects
|
49
|
+
# @see https://developer.github.com/v3/projects/#list-organization-projects
|
50
|
+
# @example
|
51
|
+
# @client.org_projects("octokit")
|
52
|
+
def org_projects(org, options = {})
|
53
|
+
opts = ensure_api_media_type(:projects, options)
|
54
|
+
get "orgs/#{org}/projects", opts
|
55
|
+
end
|
56
|
+
alias :organization_projects :org_projects
|
57
|
+
|
58
|
+
# Create organization project
|
59
|
+
#
|
60
|
+
# Requires authenticated client
|
61
|
+
#
|
62
|
+
# @param org [String] A GitHub organization
|
63
|
+
# @param name [String] Project name
|
64
|
+
# @option options [String] :body Project body
|
65
|
+
# @return [Sawyer::Resource] Organization project
|
66
|
+
# @see https://developer.github.com/v3/projects/#create-an-organization-project
|
67
|
+
# @example Create with only a name
|
68
|
+
# @client.create_org_project("octocat", "make more octocats")
|
69
|
+
# @example Create a project with name and body
|
70
|
+
# @client.create_org_project("octokit", "octocan", body: 'Improve clients')
|
71
|
+
def create_org_project(org, name, options = {})
|
72
|
+
opts = ensure_api_media_type(:projects, options)
|
73
|
+
opts[:name] = name
|
74
|
+
post "orgs/#{org}/projects", opts
|
75
|
+
end
|
76
|
+
alias :create_organization_project :create_org_project
|
77
|
+
|
78
|
+
# Get a project by id
|
79
|
+
#
|
80
|
+
# @param id [Integer] Project id
|
81
|
+
# @return [Sawyer::Resource] Project
|
82
|
+
# @see https://developer.github.com/v3/projects/#get-a-project
|
83
|
+
# @example
|
84
|
+
# Octokit.project(123942)
|
85
|
+
def project(id, options = {})
|
86
|
+
opts = ensure_api_media_type(:projects, options)
|
87
|
+
get "projects/#{id}", opts
|
88
|
+
end
|
89
|
+
|
90
|
+
# Update a project
|
91
|
+
#
|
92
|
+
# Requires authenticated client
|
93
|
+
#
|
94
|
+
# @param id [Integer] Project id
|
95
|
+
# @option options [String] :name Project name
|
96
|
+
# @option options [String] :body Project body
|
97
|
+
# @return [Sawyer::Resource] Project
|
98
|
+
# @see https://developer.github.com/v3/projects/#update-a-project
|
99
|
+
# @example Update project name
|
100
|
+
# @client.update_project(123942, name: 'New name')
|
101
|
+
def update_project(id, options = {})
|
102
|
+
opts = ensure_api_media_type(:projects, options)
|
103
|
+
patch "projects/#{id}", opts
|
104
|
+
end
|
105
|
+
|
106
|
+
# Delete a project
|
107
|
+
#
|
108
|
+
# Requires authenticated client
|
109
|
+
#
|
110
|
+
# @param id [Integer] Project id
|
111
|
+
# @return [Boolean] Result of deletion
|
112
|
+
# @see https://developer.github.com/v3/projects/#delete-a-project
|
113
|
+
# @example
|
114
|
+
# @client.delete_project(123942)
|
115
|
+
def delete_project(id, options = {})
|
116
|
+
opts = ensure_api_media_type(:projects, options)
|
117
|
+
boolean_from_response :delete, "projects/#{id}", opts
|
118
|
+
end
|
119
|
+
|
120
|
+
# List project columns
|
121
|
+
#
|
122
|
+
# @param id [Integer] Project id
|
123
|
+
# @return [Array<Sawyer::Resource>] List of project columns
|
124
|
+
# @see https://developer.github.com/v3/projects/columns/#list-project-columns
|
125
|
+
# @example
|
126
|
+
# @client.project_columns(123942)
|
127
|
+
def project_columns(id, options = {})
|
128
|
+
opts = ensure_api_media_type(:projects, options)
|
129
|
+
paginate "projects/#{id}/columns", opts
|
130
|
+
end
|
131
|
+
|
132
|
+
# Create a project column
|
133
|
+
#
|
134
|
+
# Requires authenticated client
|
135
|
+
#
|
136
|
+
# @param id [Integer] Project column id
|
137
|
+
# @param name [String] New column name
|
138
|
+
# @return [Sawyer::Resource] Newly created column
|
139
|
+
# @see https://developer.github.com/v3/projects/columns/#create-a-project-column
|
140
|
+
# @example
|
141
|
+
# @client.create_project_column(123942, "To Dones")
|
142
|
+
def create_project_column(id, name, options = {})
|
143
|
+
opts = ensure_api_media_type(:projects, options)
|
144
|
+
opts[:name] = name
|
145
|
+
post "projects/#{id}/columns", opts
|
146
|
+
end
|
147
|
+
|
148
|
+
# Get a project column by ID
|
149
|
+
#
|
150
|
+
# @param id [Integer] Project column id
|
151
|
+
# @return [Sawyer::Resource] Project column
|
152
|
+
# @see https://developer.github.com/v3/projects/columns/#get-a-project-column
|
153
|
+
# @example
|
154
|
+
# Octokit.project_column(30294)
|
155
|
+
def project_column(id, options = {})
|
156
|
+
opts = ensure_api_media_type(:projects, options)
|
157
|
+
get "projects/columns/#{id}", opts
|
158
|
+
end
|
159
|
+
|
160
|
+
# Update a project column
|
161
|
+
#
|
162
|
+
# Requires authenticated client
|
163
|
+
#
|
164
|
+
# @param id [Integer] Project column id
|
165
|
+
# @param name [String] New column name
|
166
|
+
# @return [Sawyer::Resource] Updated column
|
167
|
+
# @see https://developer.github.com/v3/projects/columns/#update-a-project-column
|
168
|
+
# @example
|
169
|
+
# @client.update_project_column(30294, "new column name")
|
170
|
+
def update_project_column(id, name, options = {})
|
171
|
+
opts = ensure_api_media_type(:projects, options)
|
172
|
+
opts[:name] = name
|
173
|
+
patch "projects/columns/#{id}", opts
|
174
|
+
end
|
175
|
+
|
176
|
+
# Delete a project column
|
177
|
+
#
|
178
|
+
# Requires authenticated client
|
179
|
+
#
|
180
|
+
# @param id [Integer] Project column id
|
181
|
+
# @return [Boolean] Result of deletion request, true when deleted
|
182
|
+
# @see https://developer.github.com/v3/projects/columns/#delete-a-project-column
|
183
|
+
# @example
|
184
|
+
# @client.delete_project_column(30294)
|
185
|
+
def delete_project_column(id, options = {})
|
186
|
+
opts = ensure_api_media_type(:projects, options)
|
187
|
+
boolean_from_response :delete, "projects/columns/#{id}", opts
|
188
|
+
end
|
189
|
+
|
190
|
+
# Move a project column
|
191
|
+
#
|
192
|
+
# Requires authenticated client
|
193
|
+
#
|
194
|
+
# @param id [Integer] Project column id
|
195
|
+
# @param position [String] New position for the column. Can be one of
|
196
|
+
# <tt>first</tt>, <tt>last</tt>, or <tt>after:<column-id></tt>, where
|
197
|
+
# <tt><column-id></tt> is the id value of a column in the same project.
|
198
|
+
# @return [Sawyer::Resource] Result
|
199
|
+
# @see https://developer.github.com/v3/projects/columns/#move-a-project-column
|
200
|
+
# @example
|
201
|
+
# @client.move_project_column(30294, "last")
|
202
|
+
def move_project_column(id, position, options = {})
|
203
|
+
opts = ensure_api_media_type(:projects, options)
|
204
|
+
opts[:position] = position
|
205
|
+
post "projects/columns/#{id}/moves", opts
|
206
|
+
end
|
207
|
+
|
208
|
+
# List columns cards
|
209
|
+
#
|
210
|
+
# Requires authenticated client
|
211
|
+
#
|
212
|
+
# @param id [Integer] Project column id
|
213
|
+
# @return [Array<Sawyer::Resource>] Cards in the column
|
214
|
+
# @see https://developer.github.com/v3/projects/cards/#list-project-cards
|
215
|
+
# @example
|
216
|
+
# @client.column_cards(30294)
|
217
|
+
def column_cards(id, options = {})
|
218
|
+
opts = ensure_api_media_type(:projects, options)
|
219
|
+
paginate "projects/columns/#{id}/cards", opts
|
220
|
+
end
|
221
|
+
|
222
|
+
# Create project card
|
223
|
+
#
|
224
|
+
# Requires authenticated client
|
225
|
+
#
|
226
|
+
# @param id [Integer] Project column id
|
227
|
+
# @option options [String] :note Card contents for a note type
|
228
|
+
# @option options [Integer] :content_id Issue ID for the card contents
|
229
|
+
# @option options [String] :content_type Type of content to associate
|
230
|
+
# with the card. <tt>Issue</tt> is presently the only avaiable value
|
231
|
+
# @note If :note is supplied, :content_id and :content_type must be
|
232
|
+
# excluded. Similarly, if :content_id is supplied, :content_type must
|
233
|
+
# be set and :note must not be included.
|
234
|
+
# @return [Sawyer::Resource] Newly created card
|
235
|
+
# @see https://developer.github.com/v3/projects/cards/#create-a-project-card
|
236
|
+
# @example Create a project card with a note
|
237
|
+
# @client.create_project_card(123495, note: 'New note card')
|
238
|
+
# @example Create a project card for an repository issue
|
239
|
+
# @client.create_project_card(123495, content_id: 1, content_type: 'Issue')
|
240
|
+
def create_project_card(id, options = {})
|
241
|
+
opts = ensure_api_media_type(:projects, options)
|
242
|
+
post "projects/columns/#{id}/cards", opts
|
243
|
+
end
|
244
|
+
|
245
|
+
# Get a project card
|
246
|
+
#
|
247
|
+
# Requires authenticated client
|
248
|
+
#
|
249
|
+
# @param id [Integer] Project card id
|
250
|
+
# @return [Sawyer::Resource] Project card
|
251
|
+
# @see https://developer.github.com/v3/projects/cards/#get-a-project-card
|
252
|
+
# @example
|
253
|
+
# @client.project_card(123495)
|
254
|
+
def project_card(id, options = {})
|
255
|
+
opts = ensure_api_media_type(:projects, options)
|
256
|
+
get "projects/columns/cards/#{id}", opts
|
257
|
+
end
|
258
|
+
|
259
|
+
# Update a project card
|
260
|
+
#
|
261
|
+
# Requires authenticated client
|
262
|
+
#
|
263
|
+
# @param id [Integer] Project card id
|
264
|
+
# @option options [String] :note The card's note content. Only valid for
|
265
|
+
# cards without another type of content, so this cannot be specified if
|
266
|
+
# the card already has a content_id and content_type.
|
267
|
+
# @return [Sawyer::Resource] Updated project card
|
268
|
+
# @see https://developer.github.com/v3/projects/cards/#update-a-project-card
|
269
|
+
# @example
|
270
|
+
# @client.update_project_card(12345, note: 'new note')
|
271
|
+
def update_project_card(id, options = {})
|
272
|
+
opts = ensure_api_media_type(:projects, options)
|
273
|
+
patch "projects/columns/cards/#{id}", opts
|
274
|
+
end
|
275
|
+
|
276
|
+
# Move a project card
|
277
|
+
#
|
278
|
+
# Requires authenticated client
|
279
|
+
#
|
280
|
+
# @param id [Integer] Project card id
|
281
|
+
# @param position [String] Can be one of <tt>top</tt>, <tt>bottom</tt>,
|
282
|
+
# or <tt>after:<card-id></tt>, where <card-id> is the id value of a
|
283
|
+
# card in the same column, or in the new column specified by column_id.
|
284
|
+
# @option options [Integer] :column_id The column id to move the card to,
|
285
|
+
# must be column in same project
|
286
|
+
# @return [Sawyer::Resource] Empty sawyer resource
|
287
|
+
# @see https://developer.github.com/v3/projects/cards/#move-a-project-card
|
288
|
+
# @example Move a card to the bottom of the same column
|
289
|
+
# @client.move_project_card(123495, 'bottom')
|
290
|
+
# @example Move a card to the top of another column
|
291
|
+
# @client.move_project_card(123495, 'top', column_id: 59402)
|
292
|
+
def move_project_card(id, position, options = {})
|
293
|
+
opts = ensure_api_media_type(:projects, options)
|
294
|
+
opts[:position] = position
|
295
|
+
post "projects/columns/cards/#{id}/moves", opts
|
296
|
+
end
|
297
|
+
|
298
|
+
# Delete a project card
|
299
|
+
#
|
300
|
+
# Requires authenticated client
|
301
|
+
#
|
302
|
+
# @param id [Integer] Project card id
|
303
|
+
# @return [Boolean] True of deleted, false otherwise
|
304
|
+
# @see https://developer.github.com/v3/projects/cards/#delete-a-project-card
|
305
|
+
# @example
|
306
|
+
# @client.delete_project_card(123495)
|
307
|
+
def delete_project_card(id, options = {})
|
308
|
+
opts = ensure_api_media_type(:projects, options)
|
309
|
+
boolean_from_response :delete, "projects/columns/cards/#{id}", opts
|
310
|
+
end
|
311
|
+
|
312
|
+
end # Projects
|
313
|
+
end
|
314
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module Octokit
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for the PubSubHubbub API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/repos/hooks/#pubsubhubbub
|
7
|
+
module PubSubHubbub
|
8
|
+
|
9
|
+
# Subscribe to a pubsub topic
|
10
|
+
#
|
11
|
+
# @param topic [String] A recoginized and supported pubsub topic
|
12
|
+
# @param callback [String] A callback url to be posted to when the topic event is fired
|
13
|
+
# @param secret [String] An optional shared secret used to generate a SHA1 HMAC of the outgoing body content
|
14
|
+
# @return [Boolean] true if the subscribe was successful, otherwise an error is raised
|
15
|
+
# @see https://developer.github.com/v3/repos/hooks/#subscribing
|
16
|
+
# @example Subscribe to push events from one of your repositories, having an email sent when fired
|
17
|
+
# client = Octokit::Client.new(:oauth_token = "token")
|
18
|
+
# client.subscribe("https://github.com/joshk/devise_imapable/events/push", "github://Email?address=josh.kalderimis@gmail.com")
|
19
|
+
def subscribe(topic, callback, secret = nil)
|
20
|
+
options = {
|
21
|
+
:"hub.callback" => callback,
|
22
|
+
:"hub.mode" => "subscribe",
|
23
|
+
:"hub.topic" => topic
|
24
|
+
}
|
25
|
+
options.merge!(:"hub.secret" => secret) unless secret.nil?
|
26
|
+
|
27
|
+
response = pub_sub_hubbub_request(options)
|
28
|
+
|
29
|
+
response.status == 204
|
30
|
+
end
|
31
|
+
|
32
|
+
# Unsubscribe from a pubsub topic
|
33
|
+
#
|
34
|
+
# @param topic [String] A recoginized pubsub topic
|
35
|
+
# @param callback [String] A callback url to be unsubscribed from
|
36
|
+
# @return [Boolean] true if the unsubscribe was successful, otherwise an error is raised
|
37
|
+
# @see https://developer.github.com/v3/repos/hooks/#subscribing
|
38
|
+
# @example Unsubscribe to push events from one of your repositories, no longer having an email sent when fired
|
39
|
+
# client = Octokit::Client.new(:oauth_token = "token")
|
40
|
+
# client.unsubscribe("https://github.com/joshk/devise_imapable/events/push", "github://Email?address=josh.kalderimis@gmail.com")
|
41
|
+
def unsubscribe(topic, callback)
|
42
|
+
options = {
|
43
|
+
:"hub.callback" => callback,
|
44
|
+
:"hub.mode" => "unsubscribe",
|
45
|
+
:"hub.topic" => topic
|
46
|
+
}
|
47
|
+
response = pub_sub_hubbub_request(options)
|
48
|
+
|
49
|
+
response.status == 204
|
50
|
+
end
|
51
|
+
|
52
|
+
# Subscribe to a repository through pubsub
|
53
|
+
#
|
54
|
+
# @param repo [String, Repository, Hash] A GitHub repository
|
55
|
+
# @param service_name [String] service name owner
|
56
|
+
# @param service_arguments [Hash] params that will be passed by subscribed hook.
|
57
|
+
# List of services is available @ https://github.com/github/github-services/tree/master/docs.
|
58
|
+
# Please refer Data node for complete list of arguments.
|
59
|
+
# @param secret [String] An optional shared secret used to generate a SHA1 HMAC of the outgoing body content
|
60
|
+
# @return [Boolean] True if subscription successful, false otherwise
|
61
|
+
# @see https://developer.github.com/v3/repos/hooks/#subscribing
|
62
|
+
# @example Subscribe to push events to one of your repositories to Travis-CI
|
63
|
+
# client = Octokit::Client.new(:oauth_token = "token")
|
64
|
+
# client.subscribe_service_hook('joshk/device_imapable', 'Travis', { :token => "test", :domain => "domain", :user => "user" })
|
65
|
+
def subscribe_service_hook(repo, service_name, service_arguments = {}, secret = nil)
|
66
|
+
topic = "#{Octokit.web_endpoint}#{Repository.new(repo)}/events/push"
|
67
|
+
callback = "github://#{service_name}?#{service_arguments.collect{ |k,v| [ k,v ].map{ |p| URI.encode_www_form_component(p) }.join("=") }.join("&") }"
|
68
|
+
subscribe(topic, callback, secret)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Unsubscribe repository through pubsub
|
72
|
+
#
|
73
|
+
# @param repo [String, Repository, Hash] A GitHub repository
|
74
|
+
# @param service_name [String] service name owner
|
75
|
+
# List of services is available @ https://github.com/github/github-services/tree/master/docs.
|
76
|
+
# @see https://developer.github.com/v3/repos/hooks/#subscribing
|
77
|
+
# @example Subscribe to push events to one of your repositories to Travis-CI
|
78
|
+
# client = Octokit::Client.new(:oauth_token = "token")
|
79
|
+
# client.unsubscribe_service_hook('joshk/device_imapable', 'Travis')
|
80
|
+
def unsubscribe_service_hook(repo, service_name)
|
81
|
+
topic = "#{Octokit.web_endpoint}#{Repository.new(repo)}/events/push"
|
82
|
+
callback = "github://#{service_name}"
|
83
|
+
unsubscribe(topic, callback)
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def pub_sub_hubbub_request(options = {})
|
89
|
+
# This method is janky, bypass normal stack so we don't
|
90
|
+
# serialize request as JSON
|
91
|
+
conn = Faraday.new(:url => @api_endpoint) do |http|
|
92
|
+
http.headers[:user_agent] = user_agent
|
93
|
+
if basic_authenticated?
|
94
|
+
http.basic_auth(@login, @password)
|
95
|
+
elsif token_authenticated?
|
96
|
+
http.authorization 'token', @access_token
|
97
|
+
end
|
98
|
+
http.request :url_encoded
|
99
|
+
http.use Octokit::Response::RaiseError
|
100
|
+
http.adapter Faraday.default_adapter
|
101
|
+
end
|
102
|
+
|
103
|
+
conn.post do |req|
|
104
|
+
req.url "hub"
|
105
|
+
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
106
|
+
req.body = options
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|