bfcfadac21784a69002bfa12cf0aae80896dab18
6 from diaspy
.models
import Notification
9 """This module abstracts notifications.
13 class Notifications():
14 """This class represents notifications of a user.
16 def __init__(self
, connection
):
17 self
._connection
= connection
18 self
._notifications
= self
.get()
21 return iter(self
._notifications
)
23 def __getitem__(self
, n
):
24 return self
._notifications
[n
]
27 """Returns list of most recent notifications.
29 params
= {'per_page': 5, '_': int(round(time
.time(), 3)*1000)}
30 headers
= {'x-csrf-token': repr(self
._connection
)}
32 request
= self
._connection
.get('notifications.json', headers
=headers
, params
=params
)
34 if request
.status_code
!= 200:
35 raise Exception('status code: {0}: cannot retreive notifications'.format(request
.status_code
))
36 return [Notification(self
._connection
, n
) for n
in request
.json()]
38 def get(self
, per_page
=5, page
=1):
39 """Returns list of notifications.
41 params
= {'per_page': per_page
, 'page': page
}
42 headers
= {'x-csrf-token': repr(self
._connection
)}
44 request
= self
._connection
.get('notifications.json', headers
=headers
, params
=params
)
46 if request
.status_code
!= 200:
47 raise Exception('status code: {0}: cannot retreive notifications'.format(request
.status_code
))
49 notifications
= request
.json()
50 return [Notification(self
._connection
, n
) for n
in notifications
]