github_api2 1.0.0

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.
Files changed (127) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +770 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.md +741 -0
  5. data/lib/github_api2/api/actions.rb +60 -0
  6. data/lib/github_api2/api/arguments.rb +253 -0
  7. data/lib/github_api2/api/config/property.rb +30 -0
  8. data/lib/github_api2/api/config/property_set.rb +120 -0
  9. data/lib/github_api2/api/config.rb +105 -0
  10. data/lib/github_api2/api/factory.rb +33 -0
  11. data/lib/github_api2/api.rb +398 -0
  12. data/lib/github_api2/authorization.rb +75 -0
  13. data/lib/github_api2/client/activity/events.rb +233 -0
  14. data/lib/github_api2/client/activity/feeds.rb +50 -0
  15. data/lib/github_api2/client/activity/notifications.rb +181 -0
  16. data/lib/github_api2/client/activity/starring.rb +130 -0
  17. data/lib/github_api2/client/activity/watching.rb +176 -0
  18. data/lib/github_api2/client/activity.rb +31 -0
  19. data/lib/github_api2/client/authorizations/app.rb +98 -0
  20. data/lib/github_api2/client/authorizations.rb +142 -0
  21. data/lib/github_api2/client/emojis.rb +19 -0
  22. data/lib/github_api2/client/gists/comments.rb +100 -0
  23. data/lib/github_api2/client/gists.rb +289 -0
  24. data/lib/github_api2/client/git_data/blobs.rb +51 -0
  25. data/lib/github_api2/client/git_data/commits.rb +101 -0
  26. data/lib/github_api2/client/git_data/references.rb +150 -0
  27. data/lib/github_api2/client/git_data/tags.rb +95 -0
  28. data/lib/github_api2/client/git_data/trees.rb +113 -0
  29. data/lib/github_api2/client/git_data.rb +31 -0
  30. data/lib/github_api2/client/gitignore.rb +57 -0
  31. data/lib/github_api2/client/issues/assignees.rb +77 -0
  32. data/lib/github_api2/client/issues/comments.rb +146 -0
  33. data/lib/github_api2/client/issues/events.rb +50 -0
  34. data/lib/github_api2/client/issues/labels.rb +189 -0
  35. data/lib/github_api2/client/issues/milestones.rb +146 -0
  36. data/lib/github_api2/client/issues.rb +248 -0
  37. data/lib/github_api2/client/markdown.rb +62 -0
  38. data/lib/github_api2/client/meta.rb +19 -0
  39. data/lib/github_api2/client/orgs/hooks.rb +182 -0
  40. data/lib/github_api2/client/orgs/members.rb +142 -0
  41. data/lib/github_api2/client/orgs/memberships.rb +131 -0
  42. data/lib/github_api2/client/orgs/projects.rb +57 -0
  43. data/lib/github_api2/client/orgs/teams.rb +407 -0
  44. data/lib/github_api2/client/orgs.rb +127 -0
  45. data/lib/github_api2/client/projects/cards.rb +158 -0
  46. data/lib/github_api2/client/projects/columns.rb +146 -0
  47. data/lib/github_api2/client/projects.rb +83 -0
  48. data/lib/github_api2/client/pull_requests/comments.rb +140 -0
  49. data/lib/github_api2/client/pull_requests/reviews.rb +158 -0
  50. data/lib/github_api2/client/pull_requests.rb +195 -0
  51. data/lib/github_api2/client/repos/branches/protections.rb +75 -0
  52. data/lib/github_api2/client/repos/branches.rb +48 -0
  53. data/lib/github_api2/client/repos/collaborators.rb +84 -0
  54. data/lib/github_api2/client/repos/comments.rb +125 -0
  55. data/lib/github_api2/client/repos/commits.rb +80 -0
  56. data/lib/github_api2/client/repos/contents.rb +263 -0
  57. data/lib/github_api2/client/repos/deployments.rb +138 -0
  58. data/lib/github_api2/client/repos/downloads.rb +62 -0
  59. data/lib/github_api2/client/repos/forks.rb +50 -0
  60. data/lib/github_api2/client/repos/hooks.rb +214 -0
  61. data/lib/github_api2/client/repos/invitations.rb +41 -0
  62. data/lib/github_api2/client/repos/keys.rb +104 -0
  63. data/lib/github_api2/client/repos/merging.rb +47 -0
  64. data/lib/github_api2/client/repos/pages.rb +48 -0
  65. data/lib/github_api2/client/repos/projects.rb +62 -0
  66. data/lib/github_api2/client/repos/pub_sub_hubbub.rb +133 -0
  67. data/lib/github_api2/client/repos/releases/assets.rb +136 -0
  68. data/lib/github_api2/client/repos/releases/tags.rb +24 -0
  69. data/lib/github_api2/client/repos/releases.rb +189 -0
  70. data/lib/github_api2/client/repos/statistics.rb +89 -0
  71. data/lib/github_api2/client/repos/statuses.rb +91 -0
  72. data/lib/github_api2/client/repos.rb +473 -0
  73. data/lib/github_api2/client/say.rb +25 -0
  74. data/lib/github_api2/client/scopes.rb +46 -0
  75. data/lib/github_api2/client/search/legacy.rb +111 -0
  76. data/lib/github_api2/client/search.rb +133 -0
  77. data/lib/github_api2/client/users/emails.rb +65 -0
  78. data/lib/github_api2/client/users/followers.rb +115 -0
  79. data/lib/github_api2/client/users/keys.rb +104 -0
  80. data/lib/github_api2/client/users.rb +117 -0
  81. data/lib/github_api2/client.rb +77 -0
  82. data/lib/github_api2/configuration.rb +70 -0
  83. data/lib/github_api2/connection.rb +82 -0
  84. data/lib/github_api2/constants.rb +61 -0
  85. data/lib/github_api2/core_ext/array.rb +25 -0
  86. data/lib/github_api2/core_ext/hash.rb +91 -0
  87. data/lib/github_api2/deprecation.rb +39 -0
  88. data/lib/github_api2/error/client_error.rb +89 -0
  89. data/lib/github_api2/error/service_error.rb +223 -0
  90. data/lib/github_api2/error.rb +32 -0
  91. data/lib/github_api2/ext/faraday.rb +40 -0
  92. data/lib/github_api2/mash.rb +7 -0
  93. data/lib/github_api2/middleware.rb +37 -0
  94. data/lib/github_api2/mime_type.rb +33 -0
  95. data/lib/github_api2/normalizer.rb +23 -0
  96. data/lib/github_api2/null_encoder.rb +25 -0
  97. data/lib/github_api2/page_iterator.rb +138 -0
  98. data/lib/github_api2/page_links.rb +63 -0
  99. data/lib/github_api2/paged_request.rb +42 -0
  100. data/lib/github_api2/pagination.rb +115 -0
  101. data/lib/github_api2/parameter_filter.rb +35 -0
  102. data/lib/github_api2/params_hash.rb +115 -0
  103. data/lib/github_api2/rate_limit.rb +25 -0
  104. data/lib/github_api2/request/basic_auth.rb +36 -0
  105. data/lib/github_api2/request/jsonize.rb +54 -0
  106. data/lib/github_api2/request/oauth2.rb +45 -0
  107. data/lib/github_api2/request/verbs.rb +63 -0
  108. data/lib/github_api2/request.rb +84 -0
  109. data/lib/github_api2/response/atom_parser.rb +22 -0
  110. data/lib/github_api2/response/follow_redirects.rb +140 -0
  111. data/lib/github_api2/response/header.rb +87 -0
  112. data/lib/github_api2/response/jsonize.rb +28 -0
  113. data/lib/github_api2/response/mashify.rb +24 -0
  114. data/lib/github_api2/response/raise_error.rb +22 -0
  115. data/lib/github_api2/response/xmlize.rb +28 -0
  116. data/lib/github_api2/response.rb +48 -0
  117. data/lib/github_api2/response_wrapper.rb +161 -0
  118. data/lib/github_api2/ssl_certs/cacerts.pem +2183 -0
  119. data/lib/github_api2/utils/url.rb +63 -0
  120. data/lib/github_api2/validations/format.rb +26 -0
  121. data/lib/github_api2/validations/presence.rb +32 -0
  122. data/lib/github_api2/validations/required.rb +21 -0
  123. data/lib/github_api2/validations/token.rb +41 -0
  124. data/lib/github_api2/validations.rb +22 -0
  125. data/lib/github_api2/version.rb +5 -0
  126. data/lib/github_api2.rb +92 -0
  127. metadata +363 -0
@@ -0,0 +1,407 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ # All actions against teams require at a minimum an authenticated user
7
+ # who is a member of the owner's team in the :org being managed.
8
+ # Api calls that require explicit permissions are noted.
9
+ class Client::Orgs::Teams < API
10
+ # List user teams
11
+ #
12
+ # List all of the teams across all of the organizations
13
+ # to which the authenticated user belongs. This method
14
+ # requires user or repo scope when authenticating via OAuth.
15
+ #
16
+ # @example
17
+ # github = Github.new oauth_token: '...'
18
+ # github.orgs.teams.list
19
+ #
20
+ # List teams
21
+ #
22
+ # @see https://developer.github.com/v3/orgs/teams/#list-teams
23
+ #
24
+ # @example
25
+ # github = Github.new oauth_token: '...'
26
+ # github.orgs.teams.list org: 'org-name'
27
+ #
28
+ # @api public
29
+ def list(*args)
30
+ params = arguments(args).params
31
+
32
+ if (org = params.delete('org'))
33
+ response = get_request("/orgs/#{org}/teams", params)
34
+ else
35
+ response = get_request('/user/teams', params)
36
+ end
37
+ return response unless block_given?
38
+ response.each { |el| yield el }
39
+ end
40
+ alias_method :all, :list
41
+
42
+ # Get a team
43
+ #
44
+ # @see https://developer.github.com/v3/orgs/teams/#get-team
45
+ #
46
+ # @example
47
+ # github = Github.new oauth_token: '...'
48
+ # github.orgs.teams.get 'team-id'
49
+ #
50
+ # @api public
51
+ def get(*args)
52
+ arguments(args, required: [:id])
53
+
54
+ get_request("/teams/#{arguments.id}", arguments.params)
55
+ end
56
+ alias_method :find, :get
57
+
58
+ # Create a team
59
+ #
60
+ # In order to create a team, the authenticated user must be an owner of :org
61
+ #
62
+ # @see https://developer.github.com/v3/orgs/teams/#create-team
63
+ #
64
+ # @param [Hash] params
65
+ # @option params [String] :name
66
+ # Required. The name of the team
67
+ # @option params [String] :description
68
+ # The description of the team.
69
+ # @option params [Array[String]] :repo_names
70
+ # The repositories to add the team to.
71
+ # @option params [String] :privacy
72
+ # The level of privacy this team should have. Can be one of:
73
+ # * secret - only visible to organization owners and
74
+ # members of this team.
75
+ # * closed - visible to all members of this organization.
76
+ # Default: secret
77
+ # @option params [String] :permission
78
+ # The permission to grant the team. Can be one of:
79
+ # * pull - team members can pull, but not push or
80
+ # administor this repositories.
81
+ # * push - team members can pull and push,
82
+ # but not administer this repositores.
83
+ # * admin - team members can pull, push and
84
+ # administor these repositories.
85
+ # Default: pull
86
+ #
87
+ # @example
88
+ # github = Github.new oauth_token: '...'
89
+ # github.orgs.teams.create 'org-name',
90
+ # name: "new team",
91
+ # permission: "push",
92
+ # repo_names: [
93
+ # "github/dotfiles"
94
+ # ]
95
+ #
96
+ # @api public
97
+ def create(*args)
98
+ arguments(args, required: [:org_name]) do
99
+ assert_required %w(name)
100
+ end
101
+
102
+ post_request("/orgs/#{arguments.org_name}/teams", arguments.params)
103
+ end
104
+
105
+ # Edit a team
106
+ #
107
+ # In order to edit a team, the authenticated user must be an owner
108
+ # of the org that the team is associated with.
109
+ #
110
+ # @see https://developer.github.com/v3/orgs/teams/#edit-team
111
+ #
112
+ # @param [Hash] params
113
+ # @option params [String] :name
114
+ # The repositories to add the team to.
115
+ # @option params [String] :description
116
+ # The description of the team.
117
+ # @option params [String] :privacy
118
+ # The level of privacy this team should have. Can be one of:
119
+ # * secret - only visible to organization owners and
120
+ # members of this team.
121
+ # * closed - visible to all members of this organization.
122
+ # Default: secret
123
+ # @option params [String] :permission
124
+ # The permission to grant the team. Can be one of:
125
+ # * pull - team members can pull, but not push or
126
+ # administor this repositories.
127
+ # * push - team members can pull and push,
128
+ # but not administer this repositores.
129
+ # * admin - team members can pull, push and
130
+ # administer these repositories.
131
+ # Default: pull
132
+ #
133
+ # @example
134
+ # github = Github.new oauth_token: '...'
135
+ # github.orgs.teams.edit 'team-id',
136
+ # name: "new team name",
137
+ # permission: "push"
138
+ #
139
+ # @api public
140
+ def edit(*args)
141
+ arguments(args, required: [:id]) do
142
+ assert_required %w(name)
143
+ end
144
+
145
+ patch_request("/teams/#{arguments.id}", arguments.params)
146
+ end
147
+
148
+ # Delete a team
149
+ #
150
+ # @see https://developer.github.com/v3/orgs/teams/#delete-team
151
+ #
152
+ # In order to delete a team, the authenticated user must be an owner
153
+ # of the org that the team is associated with
154
+ #
155
+ # @example
156
+ # github = Github.new oauth_token: '...'
157
+ # github.orgs.teams.delete 'team-id'
158
+ #
159
+ # @api public
160
+ def delete(*args)
161
+ arguments(args, required: [:id])
162
+
163
+ delete_request("/teams/#{arguments.id}", arguments.params)
164
+ end
165
+ alias_method :remove, :delete
166
+
167
+ # List team members
168
+ #
169
+ # In order to list members in a team, the authenticated user
170
+ # must be a member of the team.
171
+ #
172
+ # @see https://developer.github.com/v3/orgs/teams/#list-team-members
173
+ #
174
+ # @param [Integer] :team_id
175
+ #
176
+ # @example
177
+ # github = Github.new oauth_token: '...'
178
+ # github.orgs.teams.list_members 'team-id'
179
+ # github.orgs.teams.list_members 'team-id' { |member| ... }
180
+ #
181
+ # @api public
182
+ def list_members(*args)
183
+ arguments(args, required: [:team_id])
184
+
185
+ response = get_request("/teams/#{arguments.team_id}/members", arguments.params)
186
+ return response unless block_given?
187
+ response.each { |el| yield el }
188
+ end
189
+ alias_method :all_members, :list_members
190
+
191
+ # Check if a user is a member of a team
192
+ #
193
+ # @see https://developer.github.com/v3/orgs/teams/#get-team-member
194
+ #
195
+ # @param [Integer] :team_id
196
+ # @param [String] :username
197
+ #
198
+ # @example
199
+ # github = Github.new oauth_token: '...'
200
+ # github.orgs.teams.team_member? 'team-id', 'user-name'
201
+ #
202
+ # @api public
203
+ def team_member?(*args)
204
+ arguments(args, required: [:team_id, :user])
205
+
206
+ response = get_request("/teams/#{arguments.team_id}/members/#{arguments.user}", arguments.params)
207
+ response.status == 204
208
+ rescue Github::Error::NotFound
209
+ false
210
+ end
211
+
212
+ # Add a team member
213
+ #
214
+ # In order to add a user to a team, the authenticated user must
215
+ # have 'admin' permissions to the team or be an owner of the org
216
+ # that the team is associated with.
217
+ #
218
+ # @example
219
+ # github = Github.new oauth_token: '...'
220
+ # github.orgs.teams.add_member 'team-id', 'user-name'
221
+ #
222
+ # @api public
223
+ def add_member(*args)
224
+ arguments(args, required: [:id, :user])
225
+
226
+ put_request("/teams/#{arguments.id}/members/#{arguments.user}",
227
+ arguments.params)
228
+ end
229
+ alias_method :add_team_member, :add_member
230
+
231
+ # Remove a team member
232
+ #
233
+ # @see https://developer.github.com/v3/orgs/teams/#remove-team-member
234
+ #
235
+ # In order to remove a user from a team, the authenticated user must
236
+ # have 'admin' permissions to the team or be an owner of the org that
237
+ # the team is associated with.
238
+ # note: This does not delete the user, it just remove them from the team.
239
+ #
240
+ # @example
241
+ # github = Github.new oauth_token: '...'
242
+ # github.orgs.teams.remove_member 'team-id', 'user-name'
243
+ #
244
+ # @api public
245
+ def remove_member(*args)
246
+ arguments(args, required: [:id, :user])
247
+
248
+ delete_request("/teams/#{arguments.id}/members/#{arguments.user}",
249
+ arguments.params)
250
+ end
251
+ alias_method :remove_team_member, :remove_member
252
+
253
+ # Get team membership
254
+ #
255
+ # In order to get a user's membership with a team,
256
+ # the team must be visible to the authenticated user.
257
+ #
258
+ # @see https://developer.github.com/v3/orgs/teams/#get-team-membership
259
+ #
260
+ # @param [Integer] :team_id
261
+ # @param [String] :username
262
+ #
263
+ # @example
264
+ # github = Github.new oauth_token: '...'
265
+ # github.orgs.teams.team_membership 'team-id', 'username'
266
+ #
267
+ # @api public
268
+ def team_membership(*args)
269
+ arguments(args, required: [:team_id, :username])
270
+
271
+ get_request("/teams/#{arguments.team_id}/memberships/#{arguments.username}",
272
+ arguments.params)
273
+ end
274
+
275
+ # Add a team membership
276
+ #
277
+ # In order to add a user to a team, the authenticated user must
278
+ # have 'admin' permissions to the team or be an owner of the org
279
+ # that the team is associated with.
280
+ #
281
+ # @see https://developer.github.com/v3/orgs/teams/#add-team-membership
282
+ #
283
+ # @param [Integer] :team_id
284
+ # @param [String] :username
285
+ # @param [Hash] :params
286
+ # @option params [String] :role
287
+ # The role that this user should have in the team. Can be one of:
288
+ # * member - a normal member of the team.
289
+ # * maintainer - a team maintainer. Able to add/remove
290
+ # other team members, promote other team members to
291
+ # team maintainer, and edit the team's name and description.
292
+ # Default: member
293
+ #
294
+ # @example
295
+ # github = Github.new oauth_token: '...'
296
+ # github.orgs.teams.add_membership 'team-id', 'user-name'
297
+ #
298
+ # @api public
299
+ def add_membership(*args)
300
+ arguments(args, required: [:team_id, :user])
301
+
302
+ put_request("/teams/#{arguments.team_id}/memberships/#{arguments.user}",
303
+ arguments.params)
304
+ end
305
+ alias_method :add_team_membership, :add_membership
306
+
307
+ # Remove a team membership
308
+ #
309
+ # In order to remove a user from a team, the authenticated user must
310
+ # have 'admin' permissions to the team or be an owner of the org that
311
+ # the team is associated with.
312
+ # note: This does not delete the user, it just remove them from the team.
313
+ #
314
+ # @see https://developer.github.com/v3/orgs/teams/#remove-team-membership
315
+ #
316
+ # @example
317
+ # github = Github.new oauth_token: '...'
318
+ # github.orgs.teams.remove_membership 'team-id', 'user-name'
319
+ #
320
+ # @api public
321
+ def remove_membership(*args)
322
+ arguments(args, required: [:team_id, :user])
323
+
324
+ delete_request("/teams/#{arguments.team_id}/memberships/#{arguments.user}",
325
+ arguments.params)
326
+ end
327
+ alias_method :remove_team_membership, :remove_membership
328
+
329
+ # List team repositories
330
+ #
331
+ # @see https://developer.github.com/v3/orgs/teams/#list-team-repos
332
+ #
333
+ # @example
334
+ # github = Github.new oauth_token: '...'
335
+ # github.orgs.teams.list_repos 'team-id'
336
+ #
337
+ # @api public
338
+ def list_repos(*args)
339
+ arguments(args, required: [:id])
340
+
341
+ response = get_request("/teams/#{arguments.id}/repos", arguments.params)
342
+ return response unless block_given?
343
+ response.each { |el| yield el }
344
+ end
345
+ alias_method :repos, :list_repos
346
+
347
+ # Check if a repository belongs to a team
348
+ #
349
+ # @see https://developer.github.com/v3/orgs/teams/#get-team-repo
350
+ #
351
+ # @example
352
+ # github = Github.new oauth_token: '...'
353
+ # github.orgs.teams.team_repo? 'team-id', 'user-name', 'repo-name'
354
+ #
355
+ # @api public
356
+ def team_repo?(*args)
357
+ arguments(args, required: [:id, :user, :repo])
358
+
359
+ response = get_request("/teams/#{arguments.id}/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
360
+ response.status == 204
361
+ rescue Github::Error::NotFound
362
+ false
363
+ end
364
+ alias_method :team_repository?, :team_repo?
365
+
366
+ # Add a team repository
367
+ #
368
+ # In order to add a repo to a team, the authenticated user must be
369
+ # an owner of the org that the team is associated with. Also, the repo
370
+ # must be owned by the organization, or a direct for of a repo owned
371
+ # by the organization.
372
+ #
373
+ # @see https://developer.github.com/v3/orgs/teams/#add-team-repo
374
+ #
375
+ # @example
376
+ # github = Github.new oauth_token: '...'
377
+ # github.orgs.teams.add_repo 'team-id', 'user-name', 'repo-name'
378
+ #
379
+ # @api public
380
+ def add_repo(*args)
381
+ arguments(args, required: [:id, :user, :repo])
382
+
383
+ put_request("/teams/#{arguments.id}/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
384
+ end
385
+ alias_method :add_repository, :add_repo
386
+
387
+ # Remove a team repository
388
+ #
389
+ # In order to add a repo to a team, the authenticated user must be
390
+ # an owner of the org that the team is associated with.
391
+ # note: This does not delete the repo, it just removes it from the team.
392
+ #
393
+ # @see https://developer.github.com/v3/orgs/teams/#remove-team-repo
394
+ #
395
+ # @example
396
+ # github = Github.new oauth_token: '...'
397
+ # github.orgs.teams.remove_repo 'team-id', 'user-name', 'repo-name'
398
+ #
399
+ # @api public
400
+ def remove_repo(*args)
401
+ arguments(args, required: [:id, :user, :repo])
402
+
403
+ delete_request("/teams/#{arguments.id}/repos/#{arguments.user}/#{arguments.repo}", arguments.params)
404
+ end
405
+ alias_method :remove_repository, :remove_repo
406
+ end # Client::Orgs::Teams
407
+ end # Github
@@ -0,0 +1,127 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../api'
4
+
5
+ module Github
6
+ # Organizations API
7
+ class Client::Orgs < API
8
+
9
+ require_all 'github_api2/client/orgs',
10
+ 'hooks',
11
+ 'members',
12
+ 'memberships',
13
+ 'projects',
14
+ 'teams'
15
+
16
+ # Access to Client::Orgs::Hooks API
17
+ namespace :hooks
18
+
19
+ # Access to Client::Orgs::Members API
20
+ namespace :members
21
+
22
+ # Access to Client::Orgs::Memberships API
23
+ namespace :memberships
24
+
25
+ # Access to Client::Orgs::Projects API
26
+ namespace :projects
27
+
28
+ # Access to Client::Orgs::Teams API
29
+ namespace :teams
30
+
31
+ # List all organizations
32
+ #
33
+ # Lists all organizations, in the order that they were created on GitHub.
34
+ #
35
+ # @see https://developer.github.com/v3/orgs/#list-all-organizations
36
+ #
37
+ # @param [Hash] params
38
+ # @option params [String] :since
39
+ # The integer ID of the last Organization that you've seen.
40
+ #
41
+ # @example
42
+ # github = Github.new
43
+ # github.orgs.list :every
44
+ #
45
+ # List all public organizations for a user.
46
+ #
47
+ # @see https://developer.github.com/v3/orgs/#list-user-organizations
48
+ #
49
+ # @example
50
+ # github = Github.new
51
+ # github.orgs.list user: 'user-name'
52
+ #
53
+ # List public and private organizations for the authenticated user.
54
+ #
55
+ # @example
56
+ # github = Github.new oauth_token: '..'
57
+ # github.orgs.list
58
+ #
59
+ # @api public
60
+ def list(*args)
61
+ params = arguments(args).params
62
+
63
+ if (user_name = params.delete('user'))
64
+ response = get_request("/users/#{user_name}/orgs", params)
65
+ elsif args.map(&:to_s).include?('every')
66
+ response = get_request('/organizations', params)
67
+ else
68
+ # For the authenticated user
69
+ response = get_request('/user/orgs', params)
70
+ end
71
+ return response unless block_given?
72
+ response.each { |el| yield el }
73
+ end
74
+ alias_method :all, :list
75
+
76
+ # Get properties for a single organization
77
+ #
78
+ # @see https://developer.github.com/v3/orgs/#get-an-organization
79
+ #
80
+ # @example
81
+ # github = Github.new
82
+ # github.orgs.get 'github'
83
+ #
84
+ # @api public
85
+ def get(*args)
86
+ arguments(args, required: [:org_name])
87
+
88
+ get_request("/orgs/#{arguments.org_name}", arguments.params)
89
+ end
90
+ alias_method :find, :get
91
+
92
+ # Edit organization
93
+ #
94
+ # @see https://developer.github.com/v3/orgs/#edit-an-organization
95
+ #
96
+ # @param [Hash] params
97
+ # @option params [String] :billing_email
98
+ # Billing email address. This address is not publicized.
99
+ # @option params [String] :company
100
+ # The company name
101
+ # @option params [String] :email
102
+ # The publicly visible email address
103
+ # @option params [String] :location
104
+ # The location
105
+ # @option params [String] :name
106
+ # The shorthand name of the company.
107
+ # @option params [String] :description
108
+ # The description of the company.
109
+ #
110
+ # @example
111
+ # github = Github.new oauth_token: '...'
112
+ # github.orgs.edit 'github',
113
+ # billing_email: "support@github.com",
114
+ # blog: "https://github.com/blog",
115
+ # company: "GitHub",
116
+ # email: "support@github.com",
117
+ # location: "San Francisco",
118
+ # name: "github"
119
+ #
120
+ # @api public
121
+ def edit(*args)
122
+ arguments(args, required: [:org_name])
123
+
124
+ patch_request("/orgs/#{arguments.org_name}", arguments.params)
125
+ end
126
+ end # Orgs
127
+ end # Github
@@ -0,0 +1,158 @@
1
+ # frozen_string_literal: true
2
+ # encoding: utf-8
3
+
4
+ require_relative '../../api'
5
+
6
+ module Github
7
+ class Client::Projects::Cards < API
8
+ REQUIRED_MOVE_CARD_PARAMS = %w(position).freeze
9
+
10
+ # List project cards for a column
11
+ #
12
+ # @example
13
+ # github = Github.new
14
+ # github.projects.cards.list :column_id
15
+ #
16
+ # @see https://developer.github.com/v3/projects/cards/#list-project-cards
17
+ #
18
+ # @api public
19
+ def list(*args)
20
+ arguments(args, required: [:column_id])
21
+ params = arguments.params
22
+
23
+ params["accept"] ||= ::Github::Client::Projects::PREVIEW_MEDIA
24
+
25
+ response = get_request("/projects/columns/#{arguments.column_id}/cards", params)
26
+
27
+ return response unless block_given?
28
+ response.each { |el| yield el }
29
+ end
30
+ alias all list
31
+
32
+ # Get a project card
33
+ #
34
+ # @example
35
+ # github = Github.new
36
+ # github.projects.cards.get :card_id
37
+ #
38
+ # @see https://developer.github.com/v3/projects/cards/#get-a-project-card
39
+ #
40
+ # @api public
41
+ def get(*args)
42
+ arguments(args, required: [:card_id])
43
+ params = arguments.params
44
+
45
+ params["accept"] ||= ::Github::Client::Projects::PREVIEW_MEDIA
46
+
47
+ get_request("/projects/columns/cards/#{arguments.card_id}", params)
48
+ end
49
+ alias find get
50
+
51
+ # Create a project card for a column
52
+ #
53
+ # @param [Hash] params
54
+ # @option params [String] :note
55
+ # The card's note content. Only valid for cards without another type of
56
+ # content, so this must be omitted if content_id and content_type are
57
+ # specified.
58
+ # @option params [Integer] :content_id
59
+ # The id of the Issue to associate with this card.
60
+ # @option params [String] :content_type
61
+ # The type of content to associate with this card. Can only be "Issue" at
62
+ # this time.
63
+ #
64
+ # @example
65
+ # github = Github.new
66
+ # github.projects.cards.create :column_id, note: 'Card Note'
67
+ #
68
+ # @example
69
+ # github = Github.new
70
+ # github.projects.cards.create :column_id, content_id: <content-id>, content_type: 'content-type'
71
+ #
72
+ # @see https://developer.github.com/v3/projects/cards/#create-a-project-card
73
+ #
74
+ # @api public
75
+ def create(*args)
76
+ arguments(args, required: [:column_id])
77
+ params = arguments.params
78
+
79
+ params["accept"] ||= ::Github::Client::Projects::PREVIEW_MEDIA
80
+
81
+ post_request("/projects/columns/#{arguments.column_id}/cards", params)
82
+ end
83
+
84
+ # Update a project card
85
+ #
86
+ # @param [Hash] params
87
+ # @option params [String] :note
88
+ # The card's note content. Only valid for cards without another type of
89
+ # content, so this cannot be specified if the card already has a
90
+ # content_id and content_type.
91
+ #
92
+ # @example
93
+ # github = Github.new
94
+ # github.projects.cards.update :card_id, note: 'New card note'
95
+ #
96
+ # @see https://developer.github.com/v3/projects/cards/#update-a-project-card
97
+ #
98
+ # @api public
99
+ def update(*args)
100
+ arguments(args, required: [:card_id])
101
+ params = arguments.params
102
+
103
+ params["accept"] ||= ::Github::Client::Projects::PREVIEW_MEDIA
104
+
105
+ patch_request("/projects/columns/cards/#{arguments.card_id}", params)
106
+ end
107
+ alias edit update
108
+
109
+ # Delete a project card
110
+ #
111
+ # @example
112
+ # github = Github.new
113
+ # github.projects.cards.delete :card_id
114
+ #
115
+ # @see https://developer.github.com/v3/projects/cards/#delete-a-project-card
116
+ #
117
+ # @api public
118
+ def delete(*args)
119
+ arguments(args, required: [:card_id])
120
+ params = arguments.params
121
+
122
+ params["accept"] ||= ::Github::Client::Projects::PREVIEW_MEDIA
123
+
124
+ delete_request("/projects/columns/cards/#{arguments.card_id}", params)
125
+ end
126
+ alias remove delete
127
+
128
+ # Move a project card
129
+ #
130
+ # @param [Hash] params
131
+ # @option params [String] :position
132
+ # Required. Required. Can be one of 'first', 'last', or
133
+ # 'after:<column-id>', where <column-id> is the id value of a column in
134
+ # the same project.
135
+ #
136
+ # @example
137
+ # github = Github.new
138
+ # github.projects.cards.move :card_id, position: 'bottom'
139
+ #
140
+ # @example
141
+ # github = Github.new
142
+ # github.projects.cards.move :card_id, position: 'after:<card-id>', column_id: <column-id>
143
+ #
144
+ # @see https://developer.github.com/v3/projects/cards/#move-a-project-card
145
+ #
146
+ # @api public
147
+ def move(*args)
148
+ arguments(args, required: [:card_id]) do
149
+ assert_required REQUIRED_MOVE_CARD_PARAMS
150
+ end
151
+ params = arguments.params
152
+
153
+ params["accept"] ||= ::Github::Client::Projects::PREVIEW_MEDIA
154
+
155
+ post_request("/projects/columns/cards/#{arguments.card_id}/moves", params)
156
+ end
157
+ end
158
+ end