-
Notifications
You must be signed in to change notification settings - Fork 0
/
nscommerceapi.py
54 lines (46 loc) · 1.61 KB
/
nscommerceapi.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
"""@todo: nscommerceapi docstring"""
import os
import pickle
from suds.client import Client
class NsCommerceApi(object):
def __init__(
self,
app_var='NSAPI_APP',
cert_var='NSAPI_CERT',
toke_var='NSAPI_TOKEN'
):
"""Create and return the client, along with security headers"""
self.app_var = app_var
self.cert_var = cert_var
self.toke_var = toke_var
self.client = None
def connect(self):
try:
cert = os.environ[self.cert_var]
except KeyError:
cert = raw_input('\nEnter Certificate:\n\t')
try:
app = os.environ[self.app_var]
except KeyError:
app = raw_input('\nEnter Application name:\n\t')
try:
toke_fn = os.environ[self.toke_var]
except KeyError:
toke_fn = raw_input("Enter UserToken file location:\n\t")
try:
with open(toke_fn, 'r') as toke_file:
toke = pickle.load(toke_file).rstrip()
except IOError:
toke = raw_input('\nEnter UserToken:\n\t')
wsdl = 'https://ecomapi.networksolutions.com/soapservice.asmx?wsdl'
#Set up the SOAP client based on the nsCommerce WSDl
client = Client(wsdl)
#Create security headers and pass them to the client
headers = client.factory.create('SecurityCredential')
headers.Application = app
headers.Certificate = cert
headers.UserToken = toke
client.set_options(soapheaders=headers)
#send the client back for manipulation
self.client = client
return client