forked from infusionsoft/Official-API-Python-Library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.py
More file actions
34 lines (25 loc) · 1.04 KB
/
library.py
File metadata and controls
34 lines (25 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from xmlrpc.client import ServerProxy, Error
class Infusionsoft(object):
base_uri = 'https://%s.infusionsoft.com/api/xmlrpc'
def __init__(self, name, api_key, use_datetime=False):
uri = self.base_uri % name
self.client = ServerProxy(uri, use_datetime=use_datetime)
self.client.error = Error
self.key = api_key
def __getattr__(self, service):
def function(method, *args):
call = getattr(self.client, service + '.' + method)
try:
return call(self.key, *args)
except self.client.error as v:
return "ERROR", v
return function
def server(self):
return self.client
class InfusionsoftOAuth(Infusionsoft):
base_uri = 'https://api.infusionsoft.com/crm/xmlrpc/v1?'
def __init__(self, access_token, use_datetime=False):
uri = '%saccess_token=%s' % (self.base_uri, access_token)
self.client = ServerProxy(uri, use_datetime=use_datetime)
self.client.error = Error
self.key = access_token