~didrocks/unity/altf10

« back to all changes in this revision

Viewing changes to grackle/client.py

  • Committer: Aaron Bentley
  • Date: 2012-01-11 11:18:15 UTC
  • Revision ID: aaron@canonical.com-20120111111815-0ecv9fihdao2u68o
Start working on GET.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
        self.port = port
16
16
        self.netloc = '%s:%d' % (host, port)
17
17
 
18
 
    def archive_url(self, archive_id, query):
19
 
        path = '/%s' % quote(archive_id)
20
 
        query_string = urlencode(query)
21
 
        return urlunparse(('http', self.netloc, path, '', query_string, ''))
 
18
    def archive_url(self, archive_name, query):
 
19
        path = '/%s' % quote(archive_name)
 
20
        query = urlencode(query)
 
21
        url = urlunparse(('http', self.netloc, path, '', '', ''))
22
22
 
23
23
    def _get_connection(self):
 
24
        print 'Connecting to %s' % self.port
24
25
        return httplib.HTTPConnection(self.host, self.port)
25
26
 
26
 
    def _verb_archive(self, verb, archive_id, query, body=None):
27
 
        url = self.archive_url(archive_id, query)
 
27
    def _verb_archive(self, verb, archive_name, query, body=None):
 
28
        url = self.archive_url(archive_name, query)
28
29
        connection = self._get_connection()
29
30
        connection.request(verb, url, body)
30
31
        return connection.getresponse()
31
32
 
32
 
    def put_message(self, archive_id, key, file_obj):
 
33
    def put_message(self, archive_name, key, file_obj):
33
34
        response = self._verb_archive(
34
 
            'POST', archive_id, {'key': key}, file_obj.read())
 
35
            'POST', archive_name, {'key': key}, file_obj.read())
35
36
        data = response.read()
36
37
        if response.status == httplib.BAD_REQUEST:
37
38
            raise Exception('wtf')
40
41
        else:
41
42
            raise Exception('!!')
42
43
 
43
 
    def get_messages(self, archive_id, message_ids=None, limit=None,
44
 
                     memo=None, order=None):
 
44
    def get_messages(self, archive_name, message_ids=None):
45
45
        parameters = {}
46
46
        if message_ids is not None:
47
 
            parameters['message_ids'] = message_ids
48
 
        if limit is not None:
49
 
            parameters['limit'] = limit
50
 
        if memo is not None:
51
 
            parameters['memo'] = memo
52
 
        if order is not None:
53
 
            parameters['order'] = order
 
47
            parameters[message_ids] = message_ids
54
48
        query = {'parameters': simplejson.dumps(parameters)}
55
 
        response = self._verb_archive('GET', archive_id, query)
56
 
        data = response.read()
57
 
        return simplejson.loads(data)
 
49
        response = self._verb_archive('GET', archive_name, query)
 
50
        return {}