Beispiel #1
0
 def sync(self, box_url):
     data = { 'box': box_url }
     logger.info("Syncing box %s" % box_url)
     url = service_url('postapi', 'actions/sync')
     r = self.http.post(url, data=json.dumps(data),
                        headers={'Content-Type': 'application/json',
                                 'Accept': 'application/json'})
     if not r.ok:
         raise ServiceResponseError(r)
Beispiel #2
0
 def send_post(self, boxes, subject, body):
     logger.info("Sending message to:\n%s" % '\n'.join(boxes))
     url = service_url('postapi', 'actions/deliver')
     data = {'to': boxes, 'subject': subject, 'body': body}
     r = self.http.post(url, data=json.dumps(data),
                        headers={'Content-Type': 'application/json',
                                 'Accepts': 'application/json'})
     if not r.ok:
         raise ServiceResponseError(r)
     return self.response_to_json(r)
Beispiel #3
0
 def sync(self, box_url):
     data = {'box': box_url}
     logger.info("Syncing box %s" % box_url)
     url = service_url('postapi', 'actions/sync')
     r = self.http.post(url,
                        data=json.dumps(data),
                        headers={
                            'Content-Type': 'application/json',
                            'Accept': 'application/json'
                        })
     if not r.ok:
         raise ServiceResponseError(r)
Beispiel #4
0
    def get_box(self, name):
        '''Returns the box with the given name, or None if no such box can be found.

        Raises ServiceError if there was an issue with the service.'''
        logger.info("Fetching box for %s" % name)
        url = service_url('postapi', 'boxes/%s' % name)
        r = self.http.get(url, headers={'Accept': 'application/json'})
        if r.status_code == 404:
            return None
        elif not r.ok:
            raise ServiceResponseError(r)
        else:
            return self.response_to_json(r)
Beispiel #5
0
 def send_post(self, boxes, subject, body):
     logger.info("Sending message to:\n%s" % '\n'.join(boxes))
     url = service_url('postapi', 'actions/deliver')
     data = {'to': boxes, 'subject': subject, 'body': body}
     r = self.http.post(url,
                        data=json.dumps(data),
                        headers={
                            'Content-Type': 'application/json',
                            'Accepts': 'application/json'
                        })
     if not r.ok:
         raise ServiceResponseError(r)
     return self.response_to_json(r)
Beispiel #6
0
    def get_box(self, name):
        '''Returns the box with the given name, or None if no such box can be found.

        Raises ServiceError if there was an issue with the service.'''
        logger.info("Fetching box for %s" % name)
        url = service_url('postapi', 'boxes/%s' % name)
        r = self.http.get(url, headers={'Accept': 'application/json'})
        if r.status_code == 404:
            return None
        elif not r.ok:
            raise ServiceResponseError(r)
        else:
            return self.response_to_json(r)
Beispiel #7
0
 def get_post_detail(self, dpost_pk):
     logger.info("Viewing post details with delivered post id: %s" % dpost_pk)
     url = service_url('postapi', 'delivered-posts/%s' % dpost_pk)
     r = self.http.get(url, headers={'Accept': 'application/json'})
     if not r.ok:
         raise ServiceResponseError(r)
     dpost = self.response_to_json(r)
     logger.info("Fetching post body: %s" % dpost['post'])
     r = self.http.get(dpost['post'], headers={'Accept': 'application/json'})
     if not r.ok:
         raise ServiceResponseError(r)
     dpost['post'] = self.response_to_json(r)
     return dpost
Beispiel #8
0
    def create_box(self, name):
        '''Creates a box with the given name.

        Raises ServiceError if there was an issue with the service.'''
        logger.info("Creating box for %s" % name)
        data = { 'name': name }
        url = service_url('boxes')
        r = self.http.post(url, data=json.dumps(data),
                           headers={'Content-Type': 'application/json',
                                    'Accept': 'application/json'})
        if not r.ok:
            raise ServiceResponseError(r)
        
        return self.response_to_json(r)
Beispiel #9
0
 def get_post_detail(self, dpost_pk):
     logger.info("Viewing post details with delivered post id: %s" %
                 dpost_pk)
     url = service_url('postapi', 'delivered-posts/%s' % dpost_pk)
     r = self.http.get(url, headers={'Accept': 'application/json'})
     if not r.ok:
         raise ServiceResponseError(r)
     dpost = self.response_to_json(r)
     logger.info("Fetching post body: %s" % dpost['post'])
     r = self.http.get(dpost['post'],
                       headers={'Accept': 'application/json'})
     if not r.ok:
         raise ServiceResponseError(r)
     dpost['post'] = self.response_to_json(r)
     return dpost
Beispiel #10
0
    def create_box(self, name):
        '''Creates a box with the given name.

        Raises ServiceError if there was an issue with the service.'''
        logger.info("Creating box for %s" % name)
        data = {'name': name}
        url = service_url('boxes')
        r = self.http.post(url,
                           data=json.dumps(data),
                           headers={
                               'Content-Type': 'application/json',
                               'Accept': 'application/json'
                           })
        if not r.ok:
            raise ServiceResponseError(r)

        return self.response_to_json(r)
Beispiel #11
0
 def delete_post(self, dpost_pk):
     logger.info("Deleting delivered post id: %s" % dpost_pk)
     url = service_url('postapi', 'delivered-posts/%s' % dpost_pk)
     r = self.http.delete(url, headers={'Accept': 'application/json'})
     if not r.ok:
         raise ServiceResponseError(r)
Beispiel #12
0
 def delete_post(self, dpost_pk):
     logger.info("Deleting delivered post id: %s" % dpost_pk)
     url = service_url('postapi', 'delivered-posts/%s' % dpost_pk)
     r = self.http.delete(url, headers={'Accept': 'application/json'})
     if not r.ok:
         raise ServiceResponseError(r)