File: conversations.py

package info (click to toggle)
python-diaspy 0.6.0-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 352 kB
  • sloc: python: 1,600; makefile: 149
file content (32 lines) | stat: -rw-r--r-- 786 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3


from diaspy import errors, models


class Mailbox():
	"""Object implementing diaspora* mailbox.
	"""
	def __init__(self, connection, fetch=True):
		self._connection = connection
		self._mailbox = []
		if fetch: self._fetch()

	def __len__(self):
		return len(self._mailbox)

	def __iter__(self):
		return iter(self._mailbox)

	def __getitem__(self, n):
		return self._mailbox[n]

	def _fetch(self):
		"""This method will fetch messages from user's mailbox.
		"""
		request = self._connection.get('conversations.json')

		if request.status_code != 200:
			raise errors.DiaspyError('wrong status code: {0}'.format(request.status_code))
		mailbox = request.json()
		self._mailbox = [models.Conversation(self._connection, c['conversation']['id']) for c in mailbox]