mirror of
https://github.com/retailcrm/api-client-python.git
synced 2025-01-22 16:21:40 +03:00
first commit. constructor and request method
This commit is contained in:
commit
0fce38952d
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.swp
|
38
IntaroApy.py
Normal file
38
IntaroApy.py
Normal file
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user