5 from diaspy
.models
import Notification
8 """This module abstracts notifications.
12 class Notifications():
13 """This class represents notifications of a user.
15 def __init__(self
, connection
):
16 self
._connection
= connection
17 self
._notifications
= self
.get()
20 return iter(self
._notifications
)
23 """Returns list of most recent notifications.
25 params
= {'per_page': 5, '_': int(round(time
.time(), 3)*1000)}
26 headers
= {'x-csrf-token': self
._connection
.get_token()}
28 request
= self
._connection
.get('notifications.json', headers
=headers
, params
=params
)
30 if request
.status_code
!= 200:
31 raise Exception('status code: {0}: cannot retreive notifications'.format(request
.status_code
))
32 return [Notification(self
._connection
, n
) for n
in request
.json()]
35 def get(self
, per_page
=5, page
=1):
36 """Returns list of notifications.
38 params
= {'per_page': per_page
, 'page': page
}
39 headers
= {'x-csrf-token': self
._connection
.get_token()}
41 request
= self
._connection
.get('notifications.json', headers
=headers
, params
=params
)
43 if request
.status_code
!= 200:
44 raise Exception('status code: {0}: cannot retreive notifications'.format(request
.status_code
))
46 notifications
= request
.json()
47 return [Notification(self
._connection
, n
) for n
in notifications
]