Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7026cfe

Browse files
committed
Work towards Notificationssigmavirus24#26
1 parent6e37d74 commit7026cfe

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

‎github3/github.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
fromgithub3.reposimportRepository
1919
fromgithub3.usersimportUser,Key
2020
fromgithub3.decoratorsimportrequires_auth,requires_basic_auth
21+
fromgithub3.notificationsimportNotification
2122

2223

2324
classGitHub(GitHubCore):
@@ -471,6 +472,26 @@ def iter_gists(self, username=None, number=-1):
471472
url=self._build_url('gists')
472473
returnself._iter(int(number),url,Gist)
473474

475+
@requires_auth
476+
defiter_notifications(self,all=False,participating=False,number=-1):
477+
"""Iterate over the user's notification.
478+
479+
:param bool all: (optional), iterate over all notifications
480+
:param bool participating: (optional), only iterate over notifications
481+
in which the user is participating
482+
:param int number: (optional), how many notifications to return
483+
:returns: generator of
484+
:class:`Notification <github3.notifications.Notification`
485+
"""
486+
params=None
487+
ifall:
488+
params= {'all':all}
489+
elifparticipating:
490+
params= {'participating':participating}
491+
492+
url=self._build_url('notifications')
493+
returnself._iter(int(number),url,Notification,params)
494+
474495
@requires_auth
475496
defiter_user_issues(self,filter='',state='',labels='',sort='',
476497
direction='',since='',number=-1):

‎github3/notifications.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
fromgithub3.modelsimportGitHubCore
2+
fromgithub3.reposimportRepository
3+
4+
5+
classNotification(GitHubCore):
6+
def__init__(self,notif,session=None):
7+
super(Notification,self).__init__(notif,session)
8+
self._api=notif.get('urls', {}).get('self','')
9+
#: Comment responsible for the notification
10+
self.comment=notif.get('comment', {})
11+
#: Thread information
12+
self.thread=notif.get('thread', {})
13+
#: Repository the comment was made on
14+
self.repository=Repository(notif.get('repository', {}),self)
15+
#: When the thread was last updated
16+
self.updated_at=self._strptime(notif.get('updated_at'))
17+
#: Id of the thread
18+
self.id=notif.get('id')
19+
#: Dictionary of urls for the thread
20+
self.urls=notif.get('urls')
21+
#: datetime object representing the last time the user read the thread
22+
self.last_read_at=notif.get('last_read_at')
23+
ifself.last_read_at:
24+
self.last_read_at=self._strptime(self.last_read_at)
25+
#: The reason you're receiving the notification
26+
self.reason=notif.get('reason')
27+
self._unread=notif.get('unread')
28+
29+
defis_unread(self):
30+
"""Tells you if the thread is unread or not."""
31+
returnself._unread
32+
33+
defmark(self):
34+
"""Mark the thread as read.
35+
36+
:returns: bool
37+
"""
38+
returnself._boolean(self._post(self.urls.get('mark')),205,404)
39+
40+
# I suspect these three methods will be PUTs but I am weary to guess too
41+
# soon.
42+
defmute(self):
43+
"""Mute the thread.
44+
45+
:returns: bool
46+
"""
47+
raiseNotImplementedError
48+
49+
defunmute(self):
50+
"""Unmute the thread.
51+
52+
:returns: bool
53+
"""
54+
raiseNotImplementedError

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp