~didrocks/unity/altf10

« back to all changes in this revision

Viewing changes to grackle/client.py

  • Committer: Curtis Hovey
  • Date: 2012-02-24 21:43:12 UTC
  • Revision ID: curtis.hovey@canonical.com-20120224214312-zlji369uv0l9v75m
Move errors to their own module.
Remove duplicate definiton of SUPPORTED_DISPLAY_TYPES.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
    urlencode,
7
7
)
8
8
 
9
 
 
10
 
class UnsupportedDisplayType(Exception):
11
 
    """Raised when an Unsupported display_type is requested."""
12
 
 
13
 
 
14
 
class UnsupportedOrder(Exception):
15
 
    """Raised when an Unsupported order is requested."""
16
 
 
17
 
 
18
 
SUPPORTED_DISPLAY_TYPES = (
19
 
    'all',
20
 
    'text-only',
21
 
    'headers-only',
 
9
from grackle.error import (
 
10
    UnparsableDateRange,
 
11
    UnsupportedDisplayType,
 
12
    UnsupportedOrder,
22
13
    )
23
14
 
24
15
 
73
64
        else:
74
65
            raise Exception('!!')
75
66
 
76
 
    def get_messages(self, archive_id, message_ids=None, limit=None,
77
 
                     memo=None, order=None, headers=None,
78
 
                     max_body_length=None, include_hidden=False,
 
67
    def get_messages(self, archive_id, message_ids=None, date_range=None,
 
68
                     limit=None, memo=None, order=None, headers=None,
 
69
                     include_hidden=False, max_body_length=None,
79
70
                     display_type='all'):
80
71
        """Retrieve specified messages.
81
72
 
82
73
        :param archive_id: The archive to retrieve messages from.
83
74
        :param message_ids: (optional) Retrieve only messages with these ids.
 
75
        :param date_range: Retrieve the messages from or between a range of
 
76
            dates. Example: 2012-01-01..2012-01-31 retrieve all the messages
 
77
            between the 01 and 31 of January, including message from 01
 
78
            and 31.
84
79
        :param limit: The maximum number of messages to return.  The server
85
80
            may, at its discretion, return fewer.
86
81
        :param memo: (optional) Opaque identifier describing the position in
108
103
        parameters = {}
109
104
        if message_ids is not None:
110
105
            parameters['message_ids'] = message_ids
 
106
        if date_range is not None:
 
107
            parameters['date_range'] = date_range
111
108
        if limit is not None:
112
109
            parameters['limit'] = limit
113
110
        if memo is not None:
127
124
                raise UnsupportedOrder
128
125
            elif response.reason == UnsupportedDisplayType.__doc__:
129
126
                raise UnsupportedDisplayType
 
127
            elif response.reason == UnparsableDateRange.__doc__:
 
128
                raise UnparsableDateRange
130
129
            else:
131
130
                raise ValueError('Bad request')
132
131
        data = response.read()