diff options
author | Christian Struck <christian@struck.se> | 2013-02-02 04:17:03 +0100 |
---|---|---|
committer | Christian Struck <christian@struck.se> | 2013-02-02 04:17:03 +0100 |
commit | e1981063359b0910614e5ea3f861a5ce1e54970d (patch) | |
tree | ced65c7d63233ced0892ed8800c01b7ccfe1d5c6 /bvggrabber/api/__init__.py | |
parent | 9caefee9893048f169bc451cd9c454e0af668deb (diff) | |
download | bvg-grabber-e1981063359b0910614e5ea3f861a5ce1e54970d.tar.gz bvg-grabber-e1981063359b0910614e5ea3f861a5ce1e54970d.tar.bz2 bvg-grabber-e1981063359b0910614e5ea3f861a5ce1e54970d.zip |
Added a new object to return which is easier to handle an implements a merge function if it is wished to mix actualdeparture with scheduleddeparture departures.
Diffstat (limited to 'bvggrabber/api/__init__.py')
-rw-r--r-- | bvggrabber/api/__init__.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/bvggrabber/api/__init__.py b/bvggrabber/api/__init__.py index 36c913b..c489e8b 100644 --- a/bvggrabber/api/__init__.py +++ b/bvggrabber/api/__init__.py @@ -30,6 +30,37 @@ class QueryApi(object): "the call() method!") +class Response(object): + + def __init__(self, state, departures, error=None): + self._state = state + self._departures = departures + self._error = error + + def merge(self, other): + if isinstance(other, Response): + if not other.state: + raise ValueError("The response contains errors: " + str(other.error)) + elif not self.state: + raise ValueError("The response contains errors: " + str(self.error)) + else: + self.departures.extend(other.departures) + else: + raise TypeError("The given object is not a response object") + + @property + def state(self): + return self._state + + @property + def departures(self): + return self._departures + + @property + def error(self): + return self._error + + @total_ordering class Departure(object): |