From 0fce38952d8b51014321c2799baadd5c7f9c9b80 Mon Sep 17 00:00:00 2001 From: tikijian Date: Wed, 10 Sep 2014 22:25:29 +0400 Subject: [PATCH] first commit. constructor and request method --- .gitignore | 1 + IntaroApy.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .gitignore create mode 100644 IntaroApy.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/IntaroApy.py b/IntaroApy.py new file mode 100644 index 0000000..d0730a9 --- /dev/null +++ b/IntaroApy.py @@ -0,0 +1,38 @@ +import requests + +class IntaroApy: + 'Intaro Api wrapper' + + apiVersion = '3' + + def __init__(self, crmUrl, apiKey): + self.crmUrl = crmUrl + '/api/v' + IntaroApy.apiVersion + '/' + self.apiKey = apiKey + self.parameters = { 'apiKey': apiKey } + + def requestApi(self, url, method='GET', format='json'): + + #TODO: catch http exceptions + if method == 'GET': + result = requests.get(url, params=self.parameters) + else if method == 'POST': + result = requests.post(url, data=self.parameters) + + statusCode = result.status_code + r = result.json() + + # reset params dict + self.parameters = { 'apiKey': apiKey } + + if statusCode > 400 || r.has_key('success') && r['success'] == False : + #TODO: ApiException + + if r.has_key('generatedAt') : + self.generatedAt = r['generatedAt'] + del r['generatedAt'] + + del r['success'] + + return True + +