-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.py
65 lines (55 loc) · 2.22 KB
/
api.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import urllib2, urllib
import xon
class BlueHornetAPI(object):
def __init__(self, api_key, api_secret):
self.api_key = api_key
self.api_secret = api_secret
self.last_request = None
def method_call(self, method_calls):
api_dict = {
'api': {
'authentication': {
'api_key': self.api_key,
'shared_secret': self.api_secret,
},
'data': method_calls,
},
}
request_xml = xon.dumps(api_dict)
self.last_request = request_xml
params = urllib.urlencode({'data': request_xml,})
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/plain"}
url = 'https://echo.bluehornet.com/api/xmlrpc/index.php'
request = urllib2.Request(url, params, headers)
response = urllib2.urlopen(request)
response_xml = response.read()
return xon.loads(response_xml)
def get_method_dict(self, method_name, **kwargs):
return_dict = {
'methodCall': {
'methodName': method_name,
},
}
return_dict['methodCall'].update(kwargs)
return return_dict
def send_mail(self, subject, message, from_email, recipient_list,
fail_silently=False):
pass
def set_subscriber(self, email, **kwargs):
method_call = self.get_method_dict('legacy.manage_subscriber',
email=email,
**kwargs)
return self.method_call([method_call])
def retrieve_active(self, extended='1', basic='1', **kwargs):
method_call = self.get_method_dict('legacy.retrieve_active',
**kwargs)
return self.method_call([method_call])
def check_email(self, *addresses):
method_calls = []
for address in addresses:
method_dict = self.get_method_dict('utilities.checkemail',
email=address,
mx_check='1')
method_calls.append(method_dict)
return self.method_call(method_calls)