This commit is contained in:
tikijian 2014-09-10 23:59:23 +04:00
parent f50cd9e318
commit bbea2c891e
2 changed files with 54 additions and 0 deletions

46
Intaro.py Normal file
View File

@ -0,0 +1,46 @@
import requests
class IntaroApy:
"""Intaro Api wrapper"""
apiVersion = '3'
def __init__(self, crmUrl, apiKey):
self.apiUrl = 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)
elif method == 'POST':
result = requests.post(url, data=self.parameters)
statusCode = result.status_code
r = result.json()
# reset params dict
self.parameters = { 'apiKey': self.apiKey }
if statusCode > 400 or r.has_key('success') and r['success'] == False :
#TODO: ApiException
pass
if r.has_key('generatedAt') :
self.generatedAt = r['generatedAt']
del r['generatedAt']
del r['success']
return r
def orderGet(self, id, by='externalId') :
url = self.apiUrl + 'orders/' + str(id)
if by != 'externalId' :
self.parameters['by'] = by
return self.requestApi(url)

8
test.py Normal file
View File

@ -0,0 +1,8 @@
from Intaro import IntaroApy
from pprint import pprint
i = IntaroApy('https://g-lights.intarocrm.ru', 'pPsg3F79dj0OYkeYKwogOT9cccaipIKR')
result = i.orderGet(1342)
pprint(result)