comparison venv/lib/python2.7/site-packages/github/AuthenticatedUser.py @ 0:d67268158946 draft

planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author bcclaywell
date Mon, 12 Oct 2015 17:43:33 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d67268158946
1 # -*- coding: utf-8 -*-
2
3 # ########################## Copyrights and license ############################
4 # #
5 # Copyright 2012 Steve English <steve.english@navetas.com> #
6 # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> #
7 # Copyright 2012 Zearin <zearin@gonk.net> #
8 # Copyright 2013 AKFish <akfish@gmail.com> #
9 # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> #
10 # #
11 # This file is part of PyGithub. http://jacquev6.github.com/PyGithub/ #
12 # #
13 # PyGithub is free software: you can redistribute it and/or modify it under #
14 # the terms of the GNU Lesser General Public License as published by the Free #
15 # Software Foundation, either version 3 of the License, or (at your option) #
16 # any later version. #
17 # #
18 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
20 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
21 # details. #
22 # #
23 # You should have received a copy of the GNU Lesser General Public License #
24 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
25 # #
26 # ##############################################################################
27
28 import datetime
29
30 import github.GithubObject
31 import github.PaginatedList
32
33 import github.Gist
34 import github.Repository
35 import github.NamedUser
36 import github.Plan
37 import github.Organization
38 import github.UserKey
39 import github.Issue
40 import github.Event
41 import github.Authorization
42 import github.Notification
43
44
45 class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
46 """
47 This class represents AuthenticatedUsers as returned for example by http://developer.github.com/v3/todo
48 """
49
50 @property
51 def avatar_url(self):
52 """
53 :type: string
54 """
55 self._completeIfNotSet(self._avatar_url)
56 return self._avatar_url.value
57
58 @property
59 def bio(self):
60 """
61 :type: string
62 """
63 self._completeIfNotSet(self._bio)
64 return self._bio.value
65
66 @property
67 def blog(self):
68 """
69 :type: string
70 """
71 self._completeIfNotSet(self._blog)
72 return self._blog.value
73
74 @property
75 def collaborators(self):
76 """
77 :type: integer
78 """
79 self._completeIfNotSet(self._collaborators)
80 return self._collaborators.value
81
82 @property
83 def company(self):
84 """
85 :type: string
86 """
87 self._completeIfNotSet(self._company)
88 return self._company.value
89
90 @property
91 def created_at(self):
92 """
93 :type: datetime.datetime
94 """
95 self._completeIfNotSet(self._created_at)
96 return self._created_at.value
97
98 @property
99 def disk_usage(self):
100 """
101 :type: integer
102 """
103 self._completeIfNotSet(self._disk_usage)
104 return self._disk_usage.value
105
106 @property
107 def email(self):
108 """
109 :type: string
110 """
111 self._completeIfNotSet(self._email)
112 return self._email.value
113
114 @property
115 def events_url(self):
116 """
117 :type: string
118 """
119 self._completeIfNotSet(self._events_url)
120 return self._events_url.value
121
122 @property
123 def followers(self):
124 """
125 :type: integer
126 """
127 self._completeIfNotSet(self._followers)
128 return self._followers.value
129
130 @property
131 def followers_url(self):
132 """
133 :type: string
134 """
135 self._completeIfNotSet(self._followers_url)
136 return self._followers_url.value
137
138 @property
139 def following(self):
140 """
141 :type: integer
142 """
143 self._completeIfNotSet(self._following)
144 return self._following.value
145
146 @property
147 def following_url(self):
148 """
149 :type: string
150 """
151 self._completeIfNotSet(self._following_url)
152 return self._following_url.value
153
154 @property
155 def gists_url(self):
156 """
157 :type: string
158 """
159 self._completeIfNotSet(self._gists_url)
160 return self._gists_url.value
161
162 @property
163 def gravatar_id(self):
164 """
165 :type: string
166 """
167 self._completeIfNotSet(self._gravatar_id)
168 return self._gravatar_id.value
169
170 @property
171 def hireable(self):
172 """
173 :type: bool
174 """
175 self._completeIfNotSet(self._hireable)
176 return self._hireable.value
177
178 @property
179 def html_url(self):
180 """
181 :type: string
182 """
183 self._completeIfNotSet(self._html_url)
184 return self._html_url.value
185
186 @property
187 def id(self):
188 """
189 :type: integer
190 """
191 self._completeIfNotSet(self._id)
192 return self._id.value
193
194 @property
195 def location(self):
196 """
197 :type: string
198 """
199 self._completeIfNotSet(self._location)
200 return self._location.value
201
202 @property
203 def login(self):
204 """
205 :type: string
206 """
207 self._completeIfNotSet(self._login)
208 return self._login.value
209
210 @property
211 def name(self):
212 """
213 :type: string
214 """
215 self._completeIfNotSet(self._name)
216 return self._name.value
217
218 @property
219 def organizations_url(self):
220 """
221 :type: string
222 """
223 self._completeIfNotSet(self._organizations_url)
224 return self._organizations_url.value
225
226 @property
227 def owned_private_repos(self):
228 """
229 :type: integer
230 """
231 self._completeIfNotSet(self._owned_private_repos)
232 return self._owned_private_repos.value
233
234 @property
235 def plan(self):
236 """
237 :type: :class:`github.Plan.Plan`
238 """
239 self._completeIfNotSet(self._plan)
240 return self._plan.value
241
242 @property
243 def private_gists(self):
244 """
245 :type: integer
246 """
247 self._completeIfNotSet(self._private_gists)
248 return self._private_gists.value
249
250 @property
251 def public_gists(self):
252 """
253 :type: integer
254 """
255 self._completeIfNotSet(self._public_gists)
256 return self._public_gists.value
257
258 @property
259 def public_repos(self):
260 """
261 :type: integer
262 """
263 self._completeIfNotSet(self._public_repos)
264 return self._public_repos.value
265
266 @property
267 def received_events_url(self):
268 """
269 :type: string
270 """
271 self._completeIfNotSet(self._received_events_url)
272 return self._received_events_url.value
273
274 @property
275 def repos_url(self):
276 """
277 :type: string
278 """
279 self._completeIfNotSet(self._repos_url)
280 return self._repos_url.value
281
282 @property
283 def site_admin(self):
284 """
285 :type: bool
286 """
287 self._completeIfNotSet(self._site_admin)
288 return self._site_admin.value
289
290 @property
291 def starred_url(self):
292 """
293 :type: string
294 """
295 self._completeIfNotSet(self._starred_url)
296 return self._starred_url.value
297
298 @property
299 def subscriptions_url(self):
300 """
301 :type: string
302 """
303 self._completeIfNotSet(self._subscriptions_url)
304 return self._subscriptions_url.value
305
306 @property
307 def total_private_repos(self):
308 """
309 :type: integer
310 """
311 self._completeIfNotSet(self._total_private_repos)
312 return self._total_private_repos.value
313
314 @property
315 def type(self):
316 """
317 :type: string
318 """
319 self._completeIfNotSet(self._type)
320 return self._type.value
321
322 @property
323 def updated_at(self):
324 """
325 :type: datetime.datetime
326 """
327 self._completeIfNotSet(self._updated_at)
328 return self._updated_at.value
329
330 @property
331 def url(self):
332 """
333 :type: string
334 """
335 self._completeIfNotSet(self._url)
336 return self._url.value
337
338 def add_to_emails(self, *emails):
339 """
340 :calls: `POST /user/emails <http://developer.github.com/v3/users/emails>`_
341 :param email: string
342 :rtype: None
343 """
344 assert all(isinstance(element, (str, unicode)) for element in emails), emails
345 post_parameters = emails
346 headers, data = self._requester.requestJsonAndCheck(
347 "POST",
348 "/user/emails",
349 input=post_parameters
350 )
351
352 def add_to_following(self, following):
353 """
354 :calls: `PUT /user/following/:user <http://developer.github.com/v3/users/followers>`_
355 :param following: :class:`github.NamedUser.NamedUser`
356 :rtype: None
357 """
358 assert isinstance(following, github.NamedUser.NamedUser), following
359 headers, data = self._requester.requestJsonAndCheck(
360 "PUT",
361 "/user/following/" + following._identity
362 )
363
364 def add_to_starred(self, starred):
365 """
366 :calls: `PUT /user/starred/:owner/:repo <http://developer.github.com/v3/activity/starring>`_
367 :param starred: :class:`github.Repository.Repository`
368 :rtype: None
369 """
370 assert isinstance(starred, github.Repository.Repository), starred
371 headers, data = self._requester.requestJsonAndCheck(
372 "PUT",
373 "/user/starred/" + starred._identity
374 )
375
376 def add_to_subscriptions(self, subscription):
377 """
378 :calls: `PUT /user/subscriptions/:owner/:repo <http://developer.github.com/v3/activity/watching>`_
379 :param subscription: :class:`github.Repository.Repository`
380 :rtype: None
381 """
382 assert isinstance(subscription, github.Repository.Repository), subscription
383 headers, data = self._requester.requestJsonAndCheck(
384 "PUT",
385 "/user/subscriptions/" + subscription._identity
386 )
387
388 def add_to_watched(self, watched):
389 """
390 :calls: `PUT /user/watched/:owner/:repo <http://developer.github.com/v3/activity/starring>`_
391 :param watched: :class:`github.Repository.Repository`
392 :rtype: None
393 """
394 assert isinstance(watched, github.Repository.Repository), watched
395 headers, data = self._requester.requestJsonAndCheck(
396 "PUT",
397 "/user/watched/" + watched._identity
398 )
399
400 def create_authorization(self, scopes=github.GithubObject.NotSet, note=github.GithubObject.NotSet, note_url=github.GithubObject.NotSet, client_id=github.GithubObject.NotSet, client_secret=github.GithubObject.NotSet, onetime_password=None):
401 """
402 :calls: `POST /authorizations <http://developer.github.com/v3/oauth>`_
403 :param scopes: list of string
404 :param note: string
405 :param note_url: string
406 :param client_id: string
407 :param client_secret: string
408 :param onetime_password: string
409 :rtype: :class:`github.Authorization.Authorization`
410 """
411 assert scopes is github.GithubObject.NotSet or all(isinstance(element, (str, unicode)) for element in scopes), scopes
412 assert note is github.GithubObject.NotSet or isinstance(note, (str, unicode)), note
413 assert note_url is github.GithubObject.NotSet or isinstance(note_url, (str, unicode)), note_url
414 assert client_id is github.GithubObject.NotSet or isinstance(client_id, (str, unicode)), client_id
415 assert client_secret is github.GithubObject.NotSet or isinstance(client_secret, (str, unicode)), client_secret
416 assert onetime_password is None or isinstance(onetime_password, (str, unicode)), onetime_password
417 post_parameters = dict()
418 if scopes is not github.GithubObject.NotSet:
419 post_parameters["scopes"] = scopes
420 if note is not github.GithubObject.NotSet:
421 post_parameters["note"] = note
422 if note_url is not github.GithubObject.NotSet:
423 post_parameters["note_url"] = note_url
424 if client_id is not github.GithubObject.NotSet:
425 post_parameters["client_id"] = client_id
426 if client_secret is not github.GithubObject.NotSet:
427 post_parameters["client_secret"] = client_secret
428 if onetime_password is not None:
429 request_header = {'X-GitHub-OTP': onetime_password} # pragma no cover (Should be covered)
430 else:
431 request_header = None
432 headers, data = self._requester.requestJsonAndCheck(
433 "POST",
434 "/authorizations",
435 input=post_parameters,
436 headers=request_header,
437 )
438 return github.Authorization.Authorization(self._requester, headers, data, completed=True)
439
440 def create_fork(self, repo):
441 """
442 :calls: `POST /repos/:owner/:repo/forks <http://developer.github.com/v3/repos/forks>`_
443 :param repo: :class:`github.Repository.Repository`
444 :rtype: :class:`github.Repository.Repository`
445 """
446 assert isinstance(repo, github.Repository.Repository), repo
447 headers, data = self._requester.requestJsonAndCheck(
448 "POST",
449 "/repos/" + repo.owner.login + "/" + repo.name + "/forks"
450 )
451 return github.Repository.Repository(self._requester, headers, data, completed=True)
452
453 def create_gist(self, public, files, description=github.GithubObject.NotSet):
454 """
455 :calls: `POST /gists <http://developer.github.com/v3/gists>`_
456 :param public: bool
457 :param files: dict of string to :class:`github.InputFileContent.InputFileContent`
458 :param description: string
459 :rtype: :class:`github.Gist.Gist`
460 """
461 assert isinstance(public, bool), public
462 assert all(isinstance(element, github.InputFileContent) for element in files.itervalues()), files
463 assert description is github.GithubObject.NotSet or isinstance(description, (str, unicode)), description
464 post_parameters = {
465 "public": public,
466 "files": dict((key, value._identity) for key, value in files.iteritems()),
467 }
468 if description is not github.GithubObject.NotSet:
469 post_parameters["description"] = description
470 headers, data = self._requester.requestJsonAndCheck(
471 "POST",
472 "/gists",
473 input=post_parameters
474 )
475 return github.Gist.Gist(self._requester, headers, data, completed=True)
476
477 def create_key(self, title, key):
478 """
479 :calls: `POST /user/keys <http://developer.github.com/v3/users/keys>`_
480 :param title: string
481 :param key: string
482 :rtype: :class:`github.UserKey.UserKey`
483 """
484 assert isinstance(title, (str, unicode)), title
485 assert isinstance(key, (str, unicode)), key
486 post_parameters = {
487 "title": title,
488 "key": key,
489 }
490 headers, data = self._requester.requestJsonAndCheck(
491 "POST",
492 "/user/keys",
493 input=post_parameters
494 )
495 return github.UserKey.UserKey(self._requester, headers, data, completed=True)
496
497 def create_repo(self, name, description=github.GithubObject.NotSet, homepage=github.GithubObject.NotSet, private=github.GithubObject.NotSet, has_issues=github.GithubObject.NotSet, has_wiki=github.GithubObject.NotSet, has_downloads=github.GithubObject.NotSet, auto_init=github.GithubObject.NotSet, gitignore_template=github.GithubObject.NotSet):
498 """
499 :calls: `POST /user/repos <http://developer.github.com/v3/repos>`_
500 :param name: string
501 :param description: string
502 :param homepage: string
503 :param private: bool
504 :param has_issues: bool
505 :param has_wiki: bool
506 :param has_downloads: bool
507 :param auto_init: bool
508 :param gitignore_template: string
509 :rtype: :class:`github.Repository.Repository`
510 """
511 assert isinstance(name, (str, unicode)), name
512 assert description is github.GithubObject.NotSet or isinstance(description, (str, unicode)), description
513 assert homepage is github.GithubObject.NotSet or isinstance(homepage, (str, unicode)), homepage
514 assert private is github.GithubObject.NotSet or isinstance(private, bool), private
515 assert has_issues is github.GithubObject.NotSet or isinstance(has_issues, bool), has_issues
516 assert has_wiki is github.GithubObject.NotSet or isinstance(has_wiki, bool), has_wiki
517 assert has_downloads is github.GithubObject.NotSet or isinstance(has_downloads, bool), has_downloads
518 assert auto_init is github.GithubObject.NotSet or isinstance(auto_init, bool), auto_init
519 assert gitignore_template is github.GithubObject.NotSet or isinstance(gitignore_template, (str, unicode)), gitignore_template
520 post_parameters = {
521 "name": name,
522 }
523 if description is not github.GithubObject.NotSet:
524 post_parameters["description"] = description
525 if homepage is not github.GithubObject.NotSet:
526 post_parameters["homepage"] = homepage
527 if private is not github.GithubObject.NotSet:
528 post_parameters["private"] = private
529 if has_issues is not github.GithubObject.NotSet:
530 post_parameters["has_issues"] = has_issues
531 if has_wiki is not github.GithubObject.NotSet:
532 post_parameters["has_wiki"] = has_wiki
533 if has_downloads is not github.GithubObject.NotSet:
534 post_parameters["has_downloads"] = has_downloads
535 if auto_init is not github.GithubObject.NotSet:
536 post_parameters["auto_init"] = auto_init
537 if gitignore_template is not github.GithubObject.NotSet:
538 post_parameters["gitignore_template"] = gitignore_template
539 headers, data = self._requester.requestJsonAndCheck(
540 "POST",
541 "/user/repos",
542 input=post_parameters
543 )
544 return github.Repository.Repository(self._requester, headers, data, completed=True)
545
546 def edit(self, name=github.GithubObject.NotSet, email=github.GithubObject.NotSet, blog=github.GithubObject.NotSet, company=github.GithubObject.NotSet, location=github.GithubObject.NotSet, hireable=github.GithubObject.NotSet, bio=github.GithubObject.NotSet):
547 """
548 :calls: `PATCH /user <http://developer.github.com/v3/users>`_
549 :param name: string
550 :param email: string
551 :param blog: string
552 :param company: string
553 :param location: string
554 :param hireable: bool
555 :param bio: string
556 :rtype: None
557 """
558 assert name is github.GithubObject.NotSet or isinstance(name, (str, unicode)), name
559 assert email is github.GithubObject.NotSet or isinstance(email, (str, unicode)), email
560 assert blog is github.GithubObject.NotSet or isinstance(blog, (str, unicode)), blog
561 assert company is github.GithubObject.NotSet or isinstance(company, (str, unicode)), company
562 assert location is github.GithubObject.NotSet or isinstance(location, (str, unicode)), location
563 assert hireable is github.GithubObject.NotSet or isinstance(hireable, bool), hireable
564 assert bio is github.GithubObject.NotSet or isinstance(bio, (str, unicode)), bio
565 post_parameters = dict()
566 if name is not github.GithubObject.NotSet:
567 post_parameters["name"] = name
568 if email is not github.GithubObject.NotSet:
569 post_parameters["email"] = email
570 if blog is not github.GithubObject.NotSet:
571 post_parameters["blog"] = blog
572 if company is not github.GithubObject.NotSet:
573 post_parameters["company"] = company
574 if location is not github.GithubObject.NotSet:
575 post_parameters["location"] = location
576 if hireable is not github.GithubObject.NotSet:
577 post_parameters["hireable"] = hireable
578 if bio is not github.GithubObject.NotSet:
579 post_parameters["bio"] = bio
580 headers, data = self._requester.requestJsonAndCheck(
581 "PATCH",
582 "/user",
583 input=post_parameters
584 )
585 self._useAttributes(data)
586
587 def get_authorization(self, id):
588 """
589 :calls: `GET /authorizations/:id <http://developer.github.com/v3/oauth>`_
590 :param id: integer
591 :rtype: :class:`github.Authorization.Authorization`
592 """
593 assert isinstance(id, (int, long)), id
594 headers, data = self._requester.requestJsonAndCheck(
595 "GET",
596 "/authorizations/" + str(id)
597 )
598 return github.Authorization.Authorization(self._requester, headers, data, completed=True)
599
600 def get_authorizations(self):
601 """
602 :calls: `GET /authorizations <http://developer.github.com/v3/oauth>`_
603 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Authorization.Authorization`
604 """
605 return github.PaginatedList.PaginatedList(
606 github.Authorization.Authorization,
607 self._requester,
608 "/authorizations",
609 None
610 )
611
612 def get_emails(self):
613 """
614 :calls: `GET /user/emails <http://developer.github.com/v3/users/emails>`_
615 :rtype: list of string
616 """
617 headers, data = self._requester.requestJsonAndCheck(
618 "GET",
619 "/user/emails"
620 )
621 return data
622
623 def get_events(self):
624 """
625 :calls: `GET /events <http://developer.github.com/v3/activity/events>`_
626 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event`
627 """
628 return github.PaginatedList.PaginatedList(
629 github.Event.Event,
630 self._requester,
631 "/events",
632 None
633 )
634
635 def get_followers(self):
636 """
637 :calls: `GET /user/followers <http://developer.github.com/v3/users/followers>`_
638 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
639 """
640 return github.PaginatedList.PaginatedList(
641 github.NamedUser.NamedUser,
642 self._requester,
643 "/user/followers",
644 None
645 )
646
647 def get_following(self):
648 """
649 :calls: `GET /user/following <http://developer.github.com/v3/users/followers>`_
650 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
651 """
652 return github.PaginatedList.PaginatedList(
653 github.NamedUser.NamedUser,
654 self._requester,
655 "/user/following",
656 None
657 )
658
659 def get_gists(self):
660 """
661 :calls: `GET /gists <http://developer.github.com/v3/gists>`_
662 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist`
663 """
664 return github.PaginatedList.PaginatedList(
665 github.Gist.Gist,
666 self._requester,
667 "/gists",
668 None
669 )
670
671 def get_issues(self, filter=github.GithubObject.NotSet, state=github.GithubObject.NotSet, labels=github.GithubObject.NotSet, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet, since=github.GithubObject.NotSet):
672 """
673 :calls: `GET /issues <http://developer.github.com/v3/issues>`_
674 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue`
675 :param filter: string
676 :param state: string
677 :param labels: list of :class:`github.Label.Label`
678 :param sort: string
679 :param direction: string
680 :param since: datetime.datetime
681 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue`
682 """
683 assert filter is github.GithubObject.NotSet or isinstance(filter, (str, unicode)), filter
684 assert state is github.GithubObject.NotSet or isinstance(state, (str, unicode)), state
685 assert labels is github.GithubObject.NotSet or all(isinstance(element, github.Label.Label) for element in labels), labels
686 assert sort is github.GithubObject.NotSet or isinstance(sort, (str, unicode)), sort
687 assert direction is github.GithubObject.NotSet or isinstance(direction, (str, unicode)), direction
688 assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since
689 url_parameters = dict()
690 if filter is not github.GithubObject.NotSet:
691 url_parameters["filter"] = filter
692 if state is not github.GithubObject.NotSet:
693 url_parameters["state"] = state
694 if labels is not github.GithubObject.NotSet:
695 url_parameters["labels"] = ",".join(label.name for label in labels)
696 if sort is not github.GithubObject.NotSet:
697 url_parameters["sort"] = sort
698 if direction is not github.GithubObject.NotSet:
699 url_parameters["direction"] = direction
700 if since is not github.GithubObject.NotSet:
701 url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ")
702 return github.PaginatedList.PaginatedList(
703 github.Issue.Issue,
704 self._requester,
705 "/issues",
706 url_parameters
707 )
708
709 def get_user_issues(self, filter=github.GithubObject.NotSet, state=github.GithubObject.NotSet, labels=github.GithubObject.NotSet, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet, since=github.GithubObject.NotSet):
710 """
711 :calls: `GET /user/issues <http://developer.github.com/v3/issues>`_
712 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue`
713 :param filter: string
714 :param state: string
715 :param labels: list of :class:`github.Label.Label`
716 :param sort: string
717 :param direction: string
718 :param since: datetime.datetime
719 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue`
720 """
721 assert filter is github.GithubObject.NotSet or isinstance(filter, (str, unicode)), filter
722 assert state is github.GithubObject.NotSet or isinstance(state, (str, unicode)), state
723 assert labels is github.GithubObject.NotSet or all(isinstance(element, github.Label.Label) for element in labels), labels
724 assert sort is github.GithubObject.NotSet or isinstance(sort, (str, unicode)), sort
725 assert direction is github.GithubObject.NotSet or isinstance(direction, (str, unicode)), direction
726 assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since
727 url_parameters = dict()
728 if filter is not github.GithubObject.NotSet:
729 url_parameters["filter"] = filter
730 if state is not github.GithubObject.NotSet:
731 url_parameters["state"] = state
732 if labels is not github.GithubObject.NotSet:
733 url_parameters["labels"] = ",".join(label.name for label in labels)
734 if sort is not github.GithubObject.NotSet:
735 url_parameters["sort"] = sort
736 if direction is not github.GithubObject.NotSet:
737 url_parameters["direction"] = direction
738 if since is not github.GithubObject.NotSet:
739 url_parameters["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ")
740 return github.PaginatedList.PaginatedList(
741 github.Issue.Issue,
742 self._requester,
743 "/issues",
744 url_parameters
745 )
746
747 def get_key(self, id):
748 """
749 :calls: `GET /user/keys/:id <http://developer.github.com/v3/users/keys>`_
750 :param id: integer
751 :rtype: :class:`github.UserKey.UserKey`
752 """
753 assert isinstance(id, (int, long)), id
754 headers, data = self._requester.requestJsonAndCheck(
755 "GET",
756 "/user/keys/" + str(id)
757 )
758 return github.UserKey.UserKey(self._requester, headers, data, completed=True)
759
760 def get_keys(self):
761 """
762 :calls: `GET /user/keys <http://developer.github.com/v3/users/keys>`_
763 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.UserKey.UserKey`
764 """
765 return github.PaginatedList.PaginatedList(
766 github.UserKey.UserKey,
767 self._requester,
768 "/user/keys",
769 None
770 )
771
772 def get_notification(self, id):
773 """
774 :calls: `GET /notifications/threads/:id <http://developer.github.com/v3/activity/notifications>`_
775 :rtype: :class:`github.Notification.Notification`
776 """
777
778 assert isinstance(id, (str, unicode)), id
779 headers, data = self._requester.requestJsonAndCheck(
780 "GET",
781 "/notifications/threads/" + id
782 )
783 return github.Notification.Notification(self._requester, headers, data, completed=True)
784
785 def get_notifications(self, all=github.GithubObject.NotSet, participating=github.GithubObject.NotSet):
786 """
787 :calls: `GET /notifications <http://developer.github.com/v3/activity/notifications>`_
788 :param all: bool
789 :param participating: bool
790 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Notification.Notification`
791 """
792
793 assert all is github.GithubObject.NotSet or isinstance(all, bool), all
794 assert participating is github.GithubObject.NotSet or isinstance(participating, bool), participating
795
796 params = dict()
797 if all is not github.GithubObject.NotSet:
798 params["all"] = all
799 if participating is not github.GithubObject.NotSet:
800 params["participating"] = participating
801 # TODO: implement parameter "since"
802
803 return github.PaginatedList.PaginatedList(
804 github.Notification.Notification,
805 self._requester,
806 "/notifications",
807 params
808 )
809
810 def get_organization_events(self, org):
811 """
812 :calls: `GET /users/:user/events/orgs/:org <http://developer.github.com/v3/activity/events>`_
813 :param org: :class:`github.Organization.Organization`
814 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Event.Event`
815 """
816 assert isinstance(org, github.Organization.Organization), org
817 return github.PaginatedList.PaginatedList(
818 github.Event.Event,
819 self._requester,
820 "/users/" + self.login + "/events/orgs/" + org.login,
821 None
822 )
823
824 def get_orgs(self):
825 """
826 :calls: `GET /user/orgs <http://developer.github.com/v3/orgs>`_
827 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Organization.Organization`
828 """
829 return github.PaginatedList.PaginatedList(
830 github.Organization.Organization,
831 self._requester,
832 "/user/orgs",
833 None
834 )
835
836 def get_repo(self, name):
837 """
838 :calls: `GET /repos/:owner/:repo <http://developer.github.com/v3/repos>`_
839 :param name: string
840 :rtype: :class:`github.Repository.Repository`
841 """
842 assert isinstance(name, (str, unicode)), name
843 headers, data = self._requester.requestJsonAndCheck(
844 "GET",
845 "/repos/" + self.login + "/" + name
846 )
847 return github.Repository.Repository(self._requester, headers, data, completed=True)
848
849 def get_repos(self, type=github.GithubObject.NotSet, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet):
850 """
851 :calls: `GET /user/repos <http://developer.github.com/v3/repos>`_
852 :param type: string
853 :param sort: string
854 :param direction: string
855 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
856 """
857 assert type is github.GithubObject.NotSet or isinstance(type, (str, unicode)), type
858 assert sort is github.GithubObject.NotSet or isinstance(sort, (str, unicode)), sort
859 assert direction is github.GithubObject.NotSet or isinstance(direction, (str, unicode)), direction
860 url_parameters = dict()
861 if type is not github.GithubObject.NotSet:
862 url_parameters["type"] = type
863 if sort is not github.GithubObject.NotSet:
864 url_parameters["sort"] = sort
865 if direction is not github.GithubObject.NotSet:
866 url_parameters["direction"] = direction
867 return github.PaginatedList.PaginatedList(
868 github.Repository.Repository,
869 self._requester,
870 "/user/repos",
871 url_parameters
872 )
873
874 def get_starred(self):
875 """
876 :calls: `GET /user/starred <http://developer.github.com/v3/activity/starring>`_
877 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
878 """
879 return github.PaginatedList.PaginatedList(
880 github.Repository.Repository,
881 self._requester,
882 "/user/starred",
883 None
884 )
885
886 def get_starred_gists(self):
887 """
888 :calls: `GET /gists/starred <http://developer.github.com/v3/gists>`_
889 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Gist.Gist`
890 """
891 return github.PaginatedList.PaginatedList(
892 github.Gist.Gist,
893 self._requester,
894 "/gists/starred",
895 None
896 )
897
898 def get_subscriptions(self):
899 """
900 :calls: `GET /user/subscriptions <http://developer.github.com/v3/activity/watching>`_
901 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
902 """
903 return github.PaginatedList.PaginatedList(
904 github.Repository.Repository,
905 self._requester,
906 "/user/subscriptions",
907 None
908 )
909
910 def get_teams(self):
911 """
912 :calls: `GET /user/teams <http://developer.github.com/v3/orgs/teams>`_
913 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team`
914 """
915 return github.PaginatedList.PaginatedList(
916 github.Team.Team,
917 self._requester,
918 "/user/teams",
919 None
920 )
921
922 def get_watched(self):
923 """
924 :calls: `GET /user/watched <http://developer.github.com/v3/activity/starring>`_
925 :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository`
926 """
927 return github.PaginatedList.PaginatedList(
928 github.Repository.Repository,
929 self._requester,
930 "/user/watched",
931 None
932 )
933
934 def has_in_following(self, following):
935 """
936 :calls: `GET /user/following/:user <http://developer.github.com/v3/users/followers>`_
937 :param following: :class:`github.NamedUser.NamedUser`
938 :rtype: bool
939 """
940 assert isinstance(following, github.NamedUser.NamedUser), following
941 status, headers, data = self._requester.requestJson(
942 "GET",
943 "/user/following/" + following._identity
944 )
945 return status == 204
946
947 def has_in_starred(self, starred):
948 """
949 :calls: `GET /user/starred/:owner/:repo <http://developer.github.com/v3/activity/starring>`_
950 :param starred: :class:`github.Repository.Repository`
951 :rtype: bool
952 """
953 assert isinstance(starred, github.Repository.Repository), starred
954 status, headers, data = self._requester.requestJson(
955 "GET",
956 "/user/starred/" + starred._identity
957 )
958 return status == 204
959
960 def has_in_subscriptions(self, subscription):
961 """
962 :calls: `GET /user/subscriptions/:owner/:repo <http://developer.github.com/v3/activity/watching>`_
963 :param subscription: :class:`github.Repository.Repository`
964 :rtype: bool
965 """
966 assert isinstance(subscription, github.Repository.Repository), subscription
967 status, headers, data = self._requester.requestJson(
968 "GET",
969 "/user/subscriptions/" + subscription._identity
970 )
971 return status == 204
972
973 def has_in_watched(self, watched):
974 """
975 :calls: `GET /user/watched/:owner/:repo <http://developer.github.com/v3/activity/starring>`_
976 :param watched: :class:`github.Repository.Repository`
977 :rtype: bool
978 """
979 assert isinstance(watched, github.Repository.Repository), watched
980 status, headers, data = self._requester.requestJson(
981 "GET",
982 "/user/watched/" + watched._identity
983 )
984 return status == 204
985
986 def remove_from_emails(self, *emails):
987 """
988 :calls: `DELETE /user/emails <http://developer.github.com/v3/users/emails>`_
989 :param email: string
990 :rtype: None
991 """
992 assert all(isinstance(element, (str, unicode)) for element in emails), emails
993 post_parameters = emails
994 headers, data = self._requester.requestJsonAndCheck(
995 "DELETE",
996 "/user/emails",
997 input=post_parameters
998 )
999
1000 def remove_from_following(self, following):
1001 """
1002 :calls: `DELETE /user/following/:user <http://developer.github.com/v3/users/followers>`_
1003 :param following: :class:`github.NamedUser.NamedUser`
1004 :rtype: None
1005 """
1006 assert isinstance(following, github.NamedUser.NamedUser), following
1007 headers, data = self._requester.requestJsonAndCheck(
1008 "DELETE",
1009 "/user/following/" + following._identity
1010 )
1011
1012 def remove_from_starred(self, starred):
1013 """
1014 :calls: `DELETE /user/starred/:owner/:repo <http://developer.github.com/v3/activity/starring>`_
1015 :param starred: :class:`github.Repository.Repository`
1016 :rtype: None
1017 """
1018 assert isinstance(starred, github.Repository.Repository), starred
1019 headers, data = self._requester.requestJsonAndCheck(
1020 "DELETE",
1021 "/user/starred/" + starred._identity
1022 )
1023
1024 def remove_from_subscriptions(self, subscription):
1025 """
1026 :calls: `DELETE /user/subscriptions/:owner/:repo <http://developer.github.com/v3/activity/watching>`_
1027 :param subscription: :class:`github.Repository.Repository`
1028 :rtype: None
1029 """
1030 assert isinstance(subscription, github.Repository.Repository), subscription
1031 headers, data = self._requester.requestJsonAndCheck(
1032 "DELETE",
1033 "/user/subscriptions/" + subscription._identity
1034 )
1035
1036 def remove_from_watched(self, watched):
1037 """
1038 :calls: `DELETE /user/watched/:owner/:repo <http://developer.github.com/v3/activity/starring>`_
1039 :param watched: :class:`github.Repository.Repository`
1040 :rtype: None
1041 """
1042 assert isinstance(watched, github.Repository.Repository), watched
1043 headers, data = self._requester.requestJsonAndCheck(
1044 "DELETE",
1045 "/user/watched/" + watched._identity
1046 )
1047
1048 def _initAttributes(self):
1049 self._avatar_url = github.GithubObject.NotSet
1050 self._bio = github.GithubObject.NotSet
1051 self._blog = github.GithubObject.NotSet
1052 self._collaborators = github.GithubObject.NotSet
1053 self._company = github.GithubObject.NotSet
1054 self._created_at = github.GithubObject.NotSet
1055 self._disk_usage = github.GithubObject.NotSet
1056 self._email = github.GithubObject.NotSet
1057 self._events_url = github.GithubObject.NotSet
1058 self._followers = github.GithubObject.NotSet
1059 self._followers_url = github.GithubObject.NotSet
1060 self._following = github.GithubObject.NotSet
1061 self._following_url = github.GithubObject.NotSet
1062 self._gists_url = github.GithubObject.NotSet
1063 self._gravatar_id = github.GithubObject.NotSet
1064 self._hireable = github.GithubObject.NotSet
1065 self._html_url = github.GithubObject.NotSet
1066 self._id = github.GithubObject.NotSet
1067 self._location = github.GithubObject.NotSet
1068 self._login = github.GithubObject.NotSet
1069 self._name = github.GithubObject.NotSet
1070 self._organizations_url = github.GithubObject.NotSet
1071 self._owned_private_repos = github.GithubObject.NotSet
1072 self._plan = github.GithubObject.NotSet
1073 self._private_gists = github.GithubObject.NotSet
1074 self._public_gists = github.GithubObject.NotSet
1075 self._public_repos = github.GithubObject.NotSet
1076 self._received_events_url = github.GithubObject.NotSet
1077 self._repos_url = github.GithubObject.NotSet
1078 self._site_admin = github.GithubObject.NotSet
1079 self._starred_url = github.GithubObject.NotSet
1080 self._subscriptions_url = github.GithubObject.NotSet
1081 self._total_private_repos = github.GithubObject.NotSet
1082 self._type = github.GithubObject.NotSet
1083 self._updated_at = github.GithubObject.NotSet
1084 self._url = github.GithubObject.NotSet
1085
1086 def _useAttributes(self, attributes):
1087 if "avatar_url" in attributes: # pragma no branch
1088 self._avatar_url = self._makeStringAttribute(attributes["avatar_url"])
1089 if "bio" in attributes: # pragma no branch
1090 self._bio = self._makeStringAttribute(attributes["bio"])
1091 if "blog" in attributes: # pragma no branch
1092 self._blog = self._makeStringAttribute(attributes["blog"])
1093 if "collaborators" in attributes: # pragma no branch
1094 self._collaborators = self._makeIntAttribute(attributes["collaborators"])
1095 if "company" in attributes: # pragma no branch
1096 self._company = self._makeStringAttribute(attributes["company"])
1097 if "created_at" in attributes: # pragma no branch
1098 self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
1099 if "disk_usage" in attributes: # pragma no branch
1100 self._disk_usage = self._makeIntAttribute(attributes["disk_usage"])
1101 if "email" in attributes: # pragma no branch
1102 self._email = self._makeStringAttribute(attributes["email"])
1103 if "events_url" in attributes: # pragma no branch
1104 self._events_url = self._makeStringAttribute(attributes["events_url"])
1105 if "followers" in attributes: # pragma no branch
1106 self._followers = self._makeIntAttribute(attributes["followers"])
1107 if "followers_url" in attributes: # pragma no branch
1108 self._followers_url = self._makeStringAttribute(attributes["followers_url"])
1109 if "following" in attributes: # pragma no branch
1110 self._following = self._makeIntAttribute(attributes["following"])
1111 if "following_url" in attributes: # pragma no branch
1112 self._following_url = self._makeStringAttribute(attributes["following_url"])
1113 if "gists_url" in attributes: # pragma no branch
1114 self._gists_url = self._makeStringAttribute(attributes["gists_url"])
1115 if "gravatar_id" in attributes: # pragma no branch
1116 self._gravatar_id = self._makeStringAttribute(attributes["gravatar_id"])
1117 if "hireable" in attributes: # pragma no branch
1118 self._hireable = self._makeBoolAttribute(attributes["hireable"])
1119 if "html_url" in attributes: # pragma no branch
1120 self._html_url = self._makeStringAttribute(attributes["html_url"])
1121 if "id" in attributes: # pragma no branch
1122 self._id = self._makeIntAttribute(attributes["id"])
1123 if "location" in attributes: # pragma no branch
1124 self._location = self._makeStringAttribute(attributes["location"])
1125 if "login" in attributes: # pragma no branch
1126 self._login = self._makeStringAttribute(attributes["login"])
1127 if "name" in attributes: # pragma no branch
1128 self._name = self._makeStringAttribute(attributes["name"])
1129 if "organizations_url" in attributes: # pragma no branch
1130 self._organizations_url = self._makeStringAttribute(attributes["organizations_url"])
1131 if "owned_private_repos" in attributes: # pragma no branch
1132 self._owned_private_repos = self._makeIntAttribute(attributes["owned_private_repos"])
1133 if "plan" in attributes: # pragma no branch
1134 self._plan = self._makeClassAttribute(github.Plan.Plan, attributes["plan"])
1135 if "private_gists" in attributes: # pragma no branch
1136 self._private_gists = self._makeIntAttribute(attributes["private_gists"])
1137 if "public_gists" in attributes: # pragma no branch
1138 self._public_gists = self._makeIntAttribute(attributes["public_gists"])
1139 if "public_repos" in attributes: # pragma no branch
1140 self._public_repos = self._makeIntAttribute(attributes["public_repos"])
1141 if "received_events_url" in attributes: # pragma no branch
1142 self._received_events_url = self._makeStringAttribute(attributes["received_events_url"])
1143 if "repos_url" in attributes: # pragma no branch
1144 self._repos_url = self._makeStringAttribute(attributes["repos_url"])
1145 if "site_admin" in attributes: # pragma no branch
1146 self._site_admin = self._makeBoolAttribute(attributes["site_admin"])
1147 if "starred_url" in attributes: # pragma no branch
1148 self._starred_url = self._makeStringAttribute(attributes["starred_url"])
1149 if "subscriptions_url" in attributes: # pragma no branch
1150 self._subscriptions_url = self._makeStringAttribute(attributes["subscriptions_url"])
1151 if "total_private_repos" in attributes: # pragma no branch
1152 self._total_private_repos = self._makeIntAttribute(attributes["total_private_repos"])
1153 if "type" in attributes: # pragma no branch
1154 self._type = self._makeStringAttribute(attributes["type"])
1155 if "updated_at" in attributes: # pragma no branch
1156 self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
1157 if "url" in attributes: # pragma no branch
1158 self._url = self._makeStringAttribute(attributes["url"])