Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
39 changes: 29 additions & 10 deletions marketo/client.py → pymarketo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,50 +48,69 @@ def patchEnvelope(envelope):
# TODO: Get patch accepted in SUDS or rewrite to use DOM level code
class MarketoSignaturePlugin(MessagePlugin):
authfragment = """
<SOAP-ENV:Header>
<ns1:AuthenticationHeader>
<mktowsUserId>%(userid)s</mktowsUserId>
<requestSignature>%(signature)s</requestSignature>
<requestTimestamp>%(timestamp)s</requestTimestamp>
</ns1:AuthenticationHeader>
</SOAP-ENV:Header>
"""
def __init__(self, userid, secret, *args, **kwargs):
self.userid = userid
self.secret = secret
self.debug = kwargs.get("debug", True)
def sending(self, context):

def marshalled(self, context):
userid = self.userid
timestamp = rfc3339(datetime.datetime.now())
secret = self.secret
signature = sign(secret, timestamp+userid)
auth = self.authfragment % locals()
envelope = context.envelope
envelope = envelope.replace("<SOAP-ENV:Header/>", auth)
envelope = patchEnvelope(envelope)

#Set the right ns prefixes
envelope.nsprefixes[ 'ns1' ] = envelope.nsprefixes[ 'ns0' ]
envelope.clearPrefix( 'ns0' )

#Add our auth to the header element
header = envelope.getChild('Header')
authns = Element( 'ns1:AuthenticationHeader' )
authns.append( Element( 'mktowsUserId' ).setText(self.userid) )
authns.append( Element( 'requestSignature' ).setText(signature) )
authns.append( Element( 'requestTimestamp' ).setText(timestamp) )
header.append( authns )

#Set the proper body prefixes
body = envelope.getChild( 'Body' )
body.prefix = 'SOAP-ENV'
body.children[0].prefix = 'ns1'

if self.debug:
with open("/tmp/envelope.txt","w") as f: f.write(envelope)
context.envelope = envelope
return context
with open("/tmp/envelope.txt","w") as f: f.write(envelope.str())


def MarketoClientFactory(ini, **kwargs):
import json
with open(ini) as f:
ini = json.loads(f.read())
for key, item in ini.items():
ini[key] = str(item)

ini.update(kwargs)
wsdl = ini["wsdl"]

cache = None
if '://' not in wsdl:
if os.path.isfile(wsdl):
wsdl = 'file://' + os.path.abspath(wsdl)
cache = None # TODO: Evaluate using cache
client = Client(wsdl, cache=cache, plugins=[MarketoSignaturePlugin(ini["userid"],ini["encryption_key"])])
client = Client(wsdl, location=ini['endpoint'], cache=cache, plugins=[MarketoSignaturePlugin(ini["userid"],ini["encryption_key"])])

headers = {}
client.set_options(headers=headers)

if kwargs.has_key('proxy'):
if kwargs['proxy'].has_key('https'):
raise NotImplementedError('Connecting to a proxy over HTTPS not supported.')
client.set_options(proxy=kwargs['proxy'])

return client

File renamed without changes.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
suds==0.4
13 changes: 13 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from setuptools import setup

setup(
name='pymarketo',
author='WebReply',
author_email='',
maintainer='Scott Griffin',
maintainer_email='[email protected]',
version='0.1',
packages=['pymarketo', 'tests'],
long_description=open( 'README.rst' ).read(),
install_requires=open( 'requirements.txt' ).read().split()
)
2 changes: 1 addition & 1 deletion tests/simpletests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from marketo.client import MarketoClientFactory
from pymarketo.client import MarketoClientFactory
import os
import sys #@UnusedImport
import time #@UnusedImport
Expand Down