markety 1.4.3 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +3 -0
  3. data/README.md +66 -15
  4. data/Rakefile +1 -1
  5. data/example_xml/get_lead_failure.xml +42 -0
  6. data/example_xml/get_lead_success.xml +63 -0
  7. data/example_xml/get_lead_success_two_leads.xml +88 -0
  8. data/example_xml/list_op_add_to_list_success.xml +42 -0
  9. data/example_xml/list_op_is_member_of_list_failure.xml +50 -0
  10. data/example_xml/list_op_is_member_of_list_success.xml +51 -0
  11. data/example_xml/list_op_remove_from_list_failure.xml +50 -0
  12. data/example_xml/list_op_remove_from_list_success.xml +42 -0
  13. data/example_xml/sync_lead_failure.xml +60 -0
  14. data/example_xml/sync_lead_success.xml +78 -0
  15. data/lib/markety.rb +26 -1
  16. data/lib/markety/authentication_header.rb +3 -3
  17. data/lib/markety/client.rb +35 -141
  18. data/lib/markety/command.rb +11 -0
  19. data/lib/markety/command/get_lead.rb +27 -0
  20. data/lib/markety/command/list_operation.rb +68 -0
  21. data/lib/markety/command/sync_lead.rb +55 -0
  22. data/lib/markety/enums.rb +18 -16
  23. data/lib/markety/lead.rb +69 -0
  24. data/lib/markety/lead_key.rb +5 -4
  25. data/lib/markety/response.rb +15 -0
  26. data/lib/markety/response/generic_response.rb +45 -0
  27. data/lib/markety/response/get_lead_response.rb +35 -0
  28. data/lib/markety/response/list_operation_response.rb +30 -0
  29. data/lib/markety/response/response_factory.rb +27 -0
  30. data/lib/markety/response/sync_lead_response.rb +32 -0
  31. data/lib/markety/version.rb +1 -3
  32. data/spec/markety/lead_key_spec.rb +10 -11
  33. data/spec/markety/{lead_record_spec.rb → lead_spec.rb} +13 -30
  34. data/spec/markety/response/get_lead_response_spec.rb +170 -0
  35. data/spec/markety/response/list_operation_response_spec.rb +76 -0
  36. data/spec/markety/response/sync_lead_response_spec.rb +107 -0
  37. data/spec/spec_helper.rb +4 -0
  38. data/spec/support/savon_helper.rb +14 -0
  39. metadata +61 -33
  40. data/lib/markety/lead_record.rb +0 -73
@@ -0,0 +1,51 @@
1
+ I, [2014-09-16T16:16:57.156322 #29320] INFO -- : SOAP request: https://354-ESL-459.mktoapi.com/soap/mktows/2_4
2
+ I, [2014-09-16T16:16:57.156460 #29320] INFO -- : SOAPAction: "http://www.marketo.com/mktows/listOperation", Content-Type: text/xml;charset=UTF-8, Content-Length: 948
3
+ D, [2014-09-16T16:16:57.156806 #29320] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?>
4
+ <SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.marketo.com/mktows/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.marketo.com/mktows/">
5
+ <SOAP-ENV:Header>
6
+ <ns1:AuthenticationHeader>
7
+ <mktowsUserId>xxx</mktowsUserId>
8
+ <requestSignature>xxx</requestSignature>
9
+ <requestTimestamp>2014-09-16T16:16:57-05:00</requestTimestamp>
10
+ </ns1:AuthenticationHeader>
11
+ </SOAP-ENV:Header>
12
+ <SOAP-ENV:Body>
13
+ <tns:paramsListOperation>
14
+ <listOperation>ISMEMBEROFLIST</listOperation>
15
+ <strict>false</strict>
16
+ <listKey>
17
+ <keyType>MKTOLISTNAME</keyType>
18
+ <keyValue>foo_list</keyValue>
19
+ </listKey>
20
+ <listMemberList>
21
+ <leadKey>
22
+ <keyType>IDNUM</keyType>
23
+ <keyValue>1001088</keyValue>
24
+ </leadKey>
25
+ </listMemberList>
26
+ </tns:paramsListOperation>
27
+ </SOAP-ENV:Body>
28
+ </SOAP-ENV:Envelope>
29
+
30
+ D, [2014-09-16T16:16:57.157081 #29320] DEBUG -- : HTTPI POST request to 354-ESL-459.mktoapi.com (net_http)
31
+ I, [2014-09-16T16:16:57.524647 #29320] INFO -- : SOAP response (status 200)
32
+ D, [2014-09-16T16:16:57.525001 #29320] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?>
33
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.marketo.com/mktows/">
34
+ <SOAP-ENV:Body>
35
+ <ns1:successListOperation>
36
+ <result>
37
+ <success>true</success>
38
+ <statusList>
39
+ <leadStatus>
40
+ <leadKey>
41
+ <keyType>IDNUM</keyType>
42
+ <keyValue>1001088</keyValue>
43
+ </leadKey>
44
+ <status>true</status>
45
+ </leadStatus>
46
+ </statusList>
47
+ </result>
48
+ </ns1:successListOperation>
49
+ </SOAP-ENV:Body>
50
+ </SOAP-ENV:Envelope>
51
+
@@ -0,0 +1,50 @@
1
+ I, [2014-09-16T16:56:26.346615 #30338] INFO -- : SOAP request: https://354-ESL-459.mktoapi.com/soap/mktows/2_4
2
+ I, [2014-09-16T16:56:26.346749 #30338] INFO -- : SOAPAction: "http://www.marketo.com/mktows/listOperation", Content-Type: text/xml;charset=UTF-8, Content-Length: 948
3
+ D, [2014-09-16T16:56:26.347190 #30338] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?>
4
+ <SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.marketo.com/mktows/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.marketo.com/mktows/">
5
+ <SOAP-ENV:Header>
6
+ <ns1:AuthenticationHeader>
7
+ <mktowsUserId>xxx</mktowsUserId>
8
+ <requestSignature>xxx</requestSignature>
9
+ <requestTimestamp>2014-09-16T16:56:26-05:00</requestTimestamp>
10
+ </ns1:AuthenticationHeader>
11
+ </SOAP-ENV:Header>
12
+ <SOAP-ENV:Body>
13
+ <tns:paramsListOperation>
14
+ <listOperation>REMOVEFROMLIST</listOperation>
15
+ <strict>false</strict>
16
+ <listKey>
17
+ <keyType>MKTOLISTNAME</keyType>
18
+ <keyValue>foo_list</keyValue>
19
+ </listKey>
20
+ <listMemberList>
21
+ <leadKey>
22
+ <keyType>IDNUM</keyType>
23
+ <keyValue>1009999</keyValue>
24
+ </leadKey>
25
+ </listMemberList>
26
+ </tns:paramsListOperation>
27
+ </SOAP-ENV:Body>
28
+ </SOAP-ENV:Envelope>
29
+
30
+ D, [2014-09-16T16:56:26.347596 #30338] DEBUG -- : HTTPI POST request to 354-ESL-459.mktoapi.com (net_http)
31
+ I, [2014-09-16T16:56:27.153555 #30338] INFO -- : SOAP response (status 200)
32
+ D, [2014-09-16T16:56:27.153877 #30338] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?>
33
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.marketo.com/mktows/">
34
+ <SOAP-ENV:Body>
35
+ <ns1:successListOperation>
36
+ <result>
37
+ <success>false</success>
38
+ <statusList>
39
+ <leadStatus>
40
+ <leadKey>
41
+ <keyType>IDNUM</keyType>
42
+ <keyValue>1009999</keyValue>
43
+ </leadKey>
44
+ <status>false</status>
45
+ </leadStatus>
46
+ </statusList>
47
+ </result>
48
+ </ns1:successListOperation>
49
+ </SOAP-ENV:Body>
50
+ </SOAP-ENV:Envelope>
@@ -0,0 +1,42 @@
1
+ I, [2014-09-16T16:50:43.510336 #30338] INFO -- : SOAP request: https://354-ESL-459.mktoapi.com/soap/mktows/2_4
2
+ I, [2014-09-16T16:50:43.510488 #30338] INFO -- : SOAPAction: "http://www.marketo.com/mktows/listOperation", Content-Type: text/xml;charset=UTF-8, Content-Length: 948
3
+ D, [2014-09-16T16:50:43.510828 #30338] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?>
4
+ <SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.marketo.com/mktows/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.marketo.com/mktows/">
5
+ <SOAP-ENV:Header>
6
+ <ns1:AuthenticationHeader>
7
+ <mktowsUserId>xxx</mktowsUserId>
8
+ <requestSignature>xxx</requestSignature>
9
+ <requestTimestamp>2014-09-16T16:50:43-05:00</requestTimestamp>
10
+ </ns1:AuthenticationHeader>
11
+ </SOAP-ENV:Header>
12
+ <SOAP-ENV:Body>
13
+ <tns:paramsListOperation>
14
+ <listOperation>REMOVEFROMLIST</listOperation>
15
+ <strict>false</strict>
16
+ <listKey>
17
+ <keyType>MKTOLISTNAME</keyType>
18
+ <keyValue>foo_list</keyValue>
19
+ </listKey>
20
+ <listMemberList>
21
+ <leadKey>
22
+ <keyType>IDNUM</keyType>
23
+ <keyValue>1001086</keyValue>
24
+ </leadKey>
25
+ </listMemberList>
26
+ </tns:paramsListOperation>
27
+ </SOAP-ENV:Body>
28
+ </SOAP-ENV:Envelope>
29
+
30
+ D, [2014-09-16T16:50:43.513412 #30338] DEBUG -- : HTTPI POST request to 354-ESL-459.mktoapi.com (net_http)
31
+ I, [2014-09-16T16:50:43.894848 #30338] INFO -- : SOAP response (status 200)
32
+ D, [2014-09-16T16:50:43.895364 #30338] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?>
33
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://www.marketo.com/mktows/">
34
+ <SOAP-ENV:Body>
35
+ <ns1:successListOperation>
36
+ <result>
37
+ <success>true</success>
38
+ <statusList xsi:nil="true"/>
39
+ </result>
40
+ </ns1:successListOperation>
41
+ </SOAP-ENV:Body>
42
+ </SOAP-ENV:Envelope>
@@ -0,0 +1,60 @@
1
+ REQUEST:
2
+
3
+ <?xml version="1.0" encoding="UTF-8"?>
4
+ <SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.marketo.com/mktows/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.marketo.com/mktows/">
5
+ <SOAP-ENV:Header>
6
+ <ns1:AuthenticationHeader>
7
+ <mktowsUserId>xxx</mktowsUserId>
8
+ <requestSignature>xxx</requestSignature>
9
+ <requestTimestamp>2014-07-23T16:53:18-05:00</requestTimestamp>
10
+ </ns1:AuthenticationHeader>
11
+ <ns1:MktowsContextHeader>
12
+ <targetWorkspace>Futures Institute</targetWorkspace>
13
+ </ns1:MktowsContextHeader>
14
+ </SOAP-ENV:Header>
15
+ <SOAP-ENV:Body>
16
+ <tns:paramsSyncLead>
17
+ <leadRecord>
18
+ <foreignSysPersonId>-2</foreignSysPersonId>
19
+ <Email>starlord@example.com</Email>
20
+ <leadAttributeList>
21
+ <attribute>
22
+ <attrName>FirstName</attrName>
23
+ <attrType>string</attrType>
24
+ <attrValue>Peter</attrValue>
25
+ </attribute>
26
+ <attribute>
27
+ <attrName>LastName</attrName>
28
+ <attrType>string</attrType>
29
+ <attrValue>Quill</attrValue>
30
+ </attribute>
31
+ <attribute>
32
+ <attrName>pants</attrName>
33
+ <attrType>string</attrType>
34
+ <attrValue>corduroy</attrValue>
35
+ </attribute>
36
+ </leadAttributeList>
37
+ </leadRecord>
38
+ <returnLead>true</returnLead>
39
+ </tns:paramsSyncLead>
40
+ </SOAP-ENV:Body>
41
+ </SOAP-ENV:Envelope>
42
+
43
+
44
+ RESPONSE:
45
+ <?xml version="1.0" encoding="UTF-8"?>
46
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
47
+ <SOAP-ENV:Body>
48
+ <SOAP-ENV:Fault>
49
+ <faultcode>SOAP-ENV:Client</faultcode>
50
+ <faultstring>20105 - Unknown lead field</faultstring>
51
+ <detail>
52
+ <ns1:serviceException xmlns:ns1="http://www.marketo.com/mktows/">
53
+ <name>mktServiceException</name>
54
+ <message>syncLead operation failed: unknown fields for import: pants (20105)</message>
55
+ <code>20105</code>
56
+ </ns1:serviceException>
57
+ </detail>
58
+ </SOAP-ENV:Fault>
59
+ </SOAP-ENV:Body>
60
+ </SOAP-ENV:Envelope>
@@ -0,0 +1,78 @@
1
+ REQUEST:
2
+
3
+ <?xml version="1.0" encoding="UTF-8"?>
4
+ <SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.marketo.com/mktows/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.marketo.com/mktows/">
5
+ <SOAP-ENV:Header>
6
+ <ns1:AuthenticationHeader>
7
+ <mktowsUserId>xxx</mktowsUserId>
8
+ <requestSignature>xxx</requestSignature>
9
+ <requestTimestamp>2014-07-23T16:48:03-05:00</requestTimestamp>
10
+ </ns1:AuthenticationHeader>
11
+ <ns1:MktowsContextHeader>
12
+ <targetWorkspace>Futures Institute</targetWorkspace>
13
+ </ns1:MktowsContextHeader>
14
+ </SOAP-ENV:Header>
15
+ <SOAP-ENV:Body>
16
+ <tns:paramsSyncLead>
17
+ <leadRecord>
18
+ <foreignSysPersonId>-1</foreignSysPersonId>
19
+ <Email>spiderman@example.com</Email>
20
+ <leadAttributeList>
21
+ <attribute>
22
+ <attrName>FirstName</attrName>
23
+ <attrType>string</attrType>
24
+ <attrValue>Peter</attrValue>
25
+ </attribute>
26
+ <attribute>
27
+ <attrName>LastName</attrName>
28
+ <attrType>string</attrType>
29
+ <attrValue>Parker</attrValue>
30
+ </attribute>
31
+ </leadAttributeList>
32
+ </leadRecord>
33
+ <returnLead>true</returnLead>
34
+ </tns:paramsSyncLead>
35
+ </SOAP-ENV:Body>
36
+ </SOAP-ENV:Envelope>
37
+
38
+
39
+ RESPONSE:
40
+
41
+ <?xml version="1.0" encoding="UTF-8"?>
42
+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://www.marketo.com/mktows/">
43
+ <SOAP-ENV:Body>
44
+ <ns1:successSyncLead>
45
+ <result>
46
+ <leadId>1001064</leadId>
47
+ <syncStatus>
48
+ <leadId>1001064</leadId>
49
+ <status>CREATED</status>
50
+ <error xsi:nil="true"/>
51
+ </syncStatus>
52
+ <leadRecord>
53
+ <Id>1001064</Id>
54
+ <Email>spiderman@example.com</Email>
55
+ <ForeignSysPersonId xsi:nil="true"/>
56
+ <ForeignSysType xsi:nil="true"/>
57
+ <leadAttributeList>
58
+ <attribute>
59
+ <attrName>FirstName</attrName>
60
+ <attrType>string</attrType>
61
+ <attrValue>Peter</attrValue>
62
+ </attribute>
63
+ <attribute>
64
+ <attrName>LastName</attrName>
65
+ <attrType>string</attrType>
66
+ <attrValue>Parker</attrValue>
67
+ </attribute>
68
+ <attribute>
69
+ <attrName>Website</attrName>
70
+ <attrType>url</attrType>
71
+ <attrValue>example.com</attrValue>
72
+ </attribute>
73
+ </leadAttributeList>
74
+ </leadRecord>
75
+ </result>
76
+ </ns1:successSyncLead>
77
+ </SOAP-ENV:Body>
78
+ </SOAP-ENV:Envelope>
data/lib/markety.rb CHANGED
@@ -1,6 +1,31 @@
1
1
  require 'savon'
2
+ require 'logger'
2
3
  require 'markety/authentication_header'
3
4
  require 'markety/client'
5
+ require 'markety/command'
4
6
  require 'markety/enums'
7
+ require 'markety/lead'
5
8
  require 'markety/lead_key'
6
- require 'markety/lead_record'
9
+ require 'markety/response'
10
+ require 'markety/version'
11
+
12
+
13
+ # To use Markety, the first thing you need to do is call
14
+ # Markety.new_client(...)
15
+ # to create a Markety::Client object. It is through methods
16
+ # on this object that you will send requests to Marketo.
17
+ #
18
+ # The request methods are defined and documented in the
19
+ # Markety::Command modules, which are all <tt>include</tt>d
20
+ # and accessible from Markety::Client.
21
+ #
22
+ # Every Markety request method returns a Markety::Response of some sort.
23
+ # All responses derive from Markety::Response::GenericResponse, which exposes
24
+ # basic information about the request's success or failure.
25
+ # The information you really want is in the appropriate subclass, e.g.
26
+ #
27
+ # * Markety::Command::GetLead returns Markety::Response::GetLeadResponse
28
+ # * Markety::Command::ListOperation returns Markety::Response::ListOperationResponse
29
+ # ... and so on
30
+ module Markety
31
+ end
@@ -1,7 +1,7 @@
1
1
  module Markety
2
- # This class exists only to encapsulate the authentication header part of a soap request to marketo
2
+ # This class exists only to encapsulate the authentication header part of a soap request to Marketo.
3
3
  class AuthenticationHeader
4
- DIGEST = OpenSSL::Digest::Digest.new('sha1')
4
+ DIGEST = OpenSSL::Digest::SHA1.new
5
5
 
6
6
  def initialize(access_key, secret_key, time = DateTime.now)
7
7
  @access_key = access_key
@@ -44,4 +44,4 @@ module Markety
44
44
  OpenSSL::HMAC.hexdigest(DIGEST, @secret_key, string_to_encrypt)
45
45
  end
46
46
  end
47
- end
47
+ end
@@ -1,158 +1,52 @@
1
- module Markety
2
- def self.new_client(access_key, secret_key, end_point, options = {})
3
- api_version = options.fetch(:api_version, '2_3')
4
-
5
- client = Savon.client do
6
- endpoint end_point
7
- wsdl "http://app.marketo.com/soap/mktows/#{api_version}?WSDL"
8
- env_namespace "SOAP-ENV"
9
- namespaces({"xmlns:ns1" => "http://www.marketo.com/mktows/"})
10
- pretty_print_xml true
11
- log false if options[:log] == false
12
- end
13
-
14
- Client.new(client, Markety::AuthenticationHeader.new(access_key, secret_key))
15
- end
1
+ require 'markety/command'
2
+ require 'markety/response'
16
3
 
4
+ module Markety
5
+ # All of the Markety::Command modules are mixed in to Client, so see the documentation for those modules.
17
6
  class Client
18
- def initialize(savon_client, authentication_header)
19
- @client = savon_client
20
- @header = authentication_header
21
- end
22
-
23
- public
24
-
25
- def get_lead_by_idnum(idnum)
26
- get_lead(LeadKey.new(LeadKeyType::IDNUM, idnum))
27
- end
28
-
29
-
30
- def get_lead_by_email(email)
31
- get_lead(LeadKey.new(LeadKeyType::EMAIL, email))
32
- end
33
-
34
- def set_logger(logger)
35
- @logger = logger
36
- end
37
-
38
- def sync_lead(email, first, last, company, mobile)
39
- lead_record = LeadRecord.new(email)
40
- lead_record.set_attribute('FirstName', first)
41
- lead_record.set_attribute('LastName', last)
42
- lead_record.set_attribute('Email', email)
43
- lead_record.set_attribute('Company', company)
44
- lead_record.set_attribute('MobilePhone', mobile)
45
- sync_lead_record(lead_record)
46
- end
47
-
48
- def sync_lead_record(lead_record)
49
- begin
50
- attributes = []
51
- lead_record.each_attribute_pair do |name, value|
52
- attributes << {attr_name: name, attr_value: value, attr_type: lead_record.get_attribute_type(name) }
53
- end
54
-
55
- response = send_request(:sync_lead, {
56
- return_lead: true,
57
- lead_record: {
58
- email: lead_record.email,
59
- lead_attribute_list: {
60
- attribute: attributes
61
- }
62
- }
63
- })
64
-
65
- return LeadRecord.from_hash(response[:success_sync_lead][:result][:lead_record])
66
- rescue Exception => e
67
- @logger.log(e) if @logger
68
- return nil
69
- end
70
- end
71
-
72
- def sync_lead_record_on_id(lead_record)
73
- idnum = lead_record.idnum
74
- raise 'lead record id not set' if idnum.nil?
75
-
76
- begin
77
- attributes = []
78
- lead_record.each_attribute_pair do |name, value|
79
- attributes << {attr_name: name, attr_value: value}
80
- end
81
-
82
- attributes << {attr_name: 'Id', attr_type: 'string', attr_value: idnum.to_s}
83
-
84
- response = send_request(:sync_lead, {
85
- return_lead: true,
86
- lead_record:
87
- {
88
- lead_attribute_list: { attribute: attributes},
89
- id: idnum
90
- }
91
- })
92
- return LeadRecord.from_hash(response[:success_sync_lead][:result][:lead_record])
93
- rescue Exception => e
94
- @logger.log(e) if @logger
95
- return nil
7
+ include Markety::Command::GetLead
8
+ include Markety::Command::SyncLead
9
+ include Markety::Command::ListOperation
10
+
11
+ attr_reader :target_workspace
12
+
13
+ def initialize(access_key, secret_key, end_point, options = {})
14
+ api_version = options.fetch(:api_version, '2_3')
15
+
16
+ @client = Savon.client do
17
+ endpoint end_point
18
+ wsdl "http://app.marketo.com/soap/mktows/#{api_version}?WSDL"
19
+ namespaces({"xmlns:ns1" => "http://www.marketo.com/mktows/"})
20
+ env_namespace "SOAP-ENV"
21
+ pretty_print_xml true
22
+ log false if options[:log] == false
96
23
  end
97
- end
98
24
 
99
- def add_to_list(list_name, idnum)
100
- list_operation(list_name, ListOperationType::ADD_TO, idnum)
101
- end
102
-
103
- def remove_from_list(list_name, idnum)
104
- list_operation(list_name, ListOperationType::REMOVE_FROM, idnum)
105
- end
106
-
107
- def is_member_of_list?(list_name, idnum)
108
- response = list_operation(list_name, ListOperationType::IS_MEMBER_OF, idnum)
109
- return response[:success_list_operation][:result][:status_list][:lead_status][:status]
25
+ @auth_header = Markety::AuthenticationHeader.new(access_key, secret_key)
26
+ @client_options = {}
27
+ @client_options[:target_workspace] = options.has_key?(:target_workspace) ? options[:target_workspace] : {}
110
28
  end
111
29
 
112
30
  private
113
31
 
114
- def list_operation(list_name, list_operation_type, idnum)
115
- begin
116
- response = send_request(:list_operation, {
117
- list_operation: list_operation_type,
118
- strict: 'false',
119
- list_key: {
120
- key_type: 'MKTOLISTNAME',
121
- key_value: list_name
122
- },
123
- list_member_list: {
124
- lead_key: [{
125
- key_type: 'IDNUM',
126
- key_value: idnum
127
- }
128
- ]
129
- }
130
- })
131
- return response
132
- rescue Exception => e
133
- @logger.log(e) if @logger
134
- return nil
32
+ def send_request(cmd_type, message)
33
+ @auth_header.set_time(DateTime.now)
34
+
35
+ header_hash = @auth_header.to_hash
36
+ if cmd_type==:sync_lead && @target_workspace
37
+ header_hash.merge!({ "ns1:MktowsContextHeader"=>{"targetWorkspace"=>@target_workspace}})
135
38
  end
136
- end
137
39
 
138
- def get_lead(lead_key)
139
40
  begin
140
- response = send_request(:get_lead, {"leadKey" => lead_key.to_hash})
141
- return LeadRecord.from_hash(response[:success_get_lead][:result][:lead_record_list][:lead_record])
142
- rescue Exception => e
143
- @logger.log(e) if @logger
144
- return nil
41
+ response = request(cmd_type, message, header_hash) #returns a Savon::Response
42
+ rescue Savon::SOAPFault => e
43
+ response = e
145
44
  end
45
+ Markety::Response::ResponseFactory.create_response(cmd_type,response)
146
46
  end
147
47
 
148
- def send_request(namespace, message)
149
- @header.set_time(DateTime.now)
150
- response = request(namespace, message, @header.to_hash)
151
- response.to_hash
152
- end
153
-
154
- def request(namespace, message, header)
155
- @client.call(namespace, message: message, soap_header: header)
48
+ def request(cmd_type, message, header)
49
+ @client.call(cmd_type, message: message, soap_header: header)
156
50
  end
157
51
  end
158
52
  end