4 from diaspy
import errors
, models
8 """Object implementing diaspora* mailbox.
10 def __init__(self
, connection
, fetch
=True):
11 self
._connection
= connection
13 if fetch
: self
._fetch
()
16 return len(self
._mailbox
)
19 return iter(self
._mailbox
)
21 def __getitem__(self
, n
):
22 return self
._mailbox
[n
]
25 """This method will fetch messages from user's mailbox.
27 request
= self
._connection
.get('conversations.json')
29 if request
.status_code
!= 200:
30 raise errors
.DiaspyError('wrong status code: {0}'.format(request
.status_code
))
31 mailbox
= request
.json()
32 self
._mailbox
= [models
.Conversation(self
._connection
, c
['conversation']['id']) for c
in mailbox
]