[IMP] update of the posts

This commit is contained in:
Guewen Baconnier @ Camptocamp
2012-11-23 16:56:00 +01:00
parent b4c2fbc7fa
commit 51feae800d
3 changed files with 184 additions and 29 deletions

View File

@@ -28,6 +28,14 @@ from requests.packages.urllib3.filepost import encode_multipart_formdata
_logger = logging.getLogger(__name__)
POST_SENDING_STATUS = {
100: 'Ready/Pending',
101: 'Processing',
102: 'Waiting for confirmation',
200: 'Sent',
300: 'Some error occured and object wasn\'t sent',
400: 'Sending cancelled',
}
class PingenException(RuntimeError):
"""There was an ambiguous exception that occurred while handling your
@@ -42,7 +50,6 @@ class APIError(PingenException):
"""An Error occured with the pingen API"""
class Pingen(object):
""" Interface to pingen.com API
"""
@@ -90,7 +97,9 @@ class Pingen(object):
response = method(complete_url, **kwargs)
if not response.ok:
raise ConnectionError(response.error)
raise ConnectionError(
"%s: %s" % (response.json['errorcode'],
response.json['errormessage']))
if response.json['error']:
raise APIError(
@@ -167,3 +176,24 @@ class Pingen(object):
return response.json['id']
def post_infos(self, post_id):
""" Return the information of a post
:param int post_id: id of the document to send
:return: dict of infos of the post
"""
response = self._send(
requests.get,
'post/get',
params={'id': post_id})
return response.json['item']
@staticmethod
def is_posted(post_infos):
""" return True if the post has been sent
:param dict post_infos: post infos returned by `post_infos`
"""
return post_infos['status'] == 200