cupid 0.2.4 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +0,0 @@
1
- module Cupid
2
- class Session
3
- def retrieve_lists(account=nil, properties=nil)
4
- account ||= @account
5
- properties ||= ['ID', 'CustomerKey']
6
-
7
- soap_body = build_retrieve(account.to_s, 'List', properties)
8
- response = build_request('Retrieve', 'RetrieveRequestMsg', soap_body)
9
- response = Nokogiri::XML(response.http.body).remove_namespaces!
10
- all_lists = response.css('Results').map{|f| {f.css('CustomerKey').to_a.map(&:text).join('/') => f.css('ID')[0].text}}
11
- end
12
- end
13
- end
@@ -1,56 +0,0 @@
1
- module Cupid
2
- class Session
3
- # User object:
4
- # {
5
- # :email => 'email@email.com',
6
- # :lists => [list_id1, list_id2...],
7
- # :first_name => 'Name',
8
- # :last_name => 'Lastname'
9
- # }
10
- def create_subscriber(user, account=nil)
11
- soap_body = prepare_subscriber(user, account)
12
-
13
- response = build_request('Create', 'CreateRequest', soap_body)
14
- response = Nokogiri::XML(response.http.body).remove_namespaces!
15
- created_user_id = response.css('NewID').text
16
- end
17
-
18
- def create_subscribers(users, account=nil)
19
- soap_body = users.map{ |user| prepare_subscriber(user, account) }
20
-
21
- response = build_request('Create', 'CreateRequest', soap_body)
22
- response = Nokogiri::XML(response.http.body).remove_namespaces!
23
- created_user_id = response.css('NewID').text
24
- end
25
-
26
- private
27
-
28
- def prepare_subscriber(user, account=nil)
29
- user[:lists].map!{ |list| list_object(list) }
30
- account ||= @account
31
-
32
- create_subscriber_object(user, account)
33
- end
34
-
35
- def create_subscriber_object(user, account)
36
- subscriber_object = '<Objects xsi:type="Subscriber"><ObjectID xsi:nil="true"/>'
37
- subscriber_object += '<PartnerKey xsi:nil="true" />'
38
- subscriber_object += '<Client><ID>' + account.to_s + '</ID></Client>' if account
39
- subscriber_object += user[:lists].join('') if user[:lists]
40
- subscriber_object += '<FirstName>' + user[:first_name].to_s + '</FirstName>' if user[:first_name]
41
- subscriber_object += '<LastName>' + user[:last_name].to_s + '</LastName>' if user[:last_name]
42
- subscriber_object += '<EmailAddress>' + user[:email] + '</EmailAddress>'
43
- subscriber_object += '</Objects>'
44
- end
45
-
46
- def list_object(list_id)
47
- '<Lists>
48
- <PartnerKey xsi:nil="true">
49
- </PartnerKey>
50
- <ID>' + list_id.to_s + '</ID>
51
- <ObjectID xsi:nil="true">
52
- </ObjectID>
53
- </Lists>'
54
- end
55
- end
56
- end
@@ -1,78 +0,0 @@
1
- require("cupid/methods")
2
-
3
- module Cupid
4
- class Session
5
- DEFAULTS = {
6
- :soap_s4_url => "https://webservice.s4.exacttarget.com/etframework.wsdl",
7
- :wsa_soap_s4_to => "https://webservice.s4.exacttarget.com/Service.asmx",
8
- :use_ssl => true
9
- }
10
-
11
- def initialize(*args)
12
- options = args.extract_options!
13
- @username = options[:username] ||= Cupid.username
14
- @password = options[:password] ||= Cupid.password
15
- @account = options[:account] ||= Cupid.account
16
- @headers = {"Content-Type" => "application/x-www-form-urlencoded", "Connection" => "close"}
17
-
18
- @api_uri = @api_wsdl = DEFAULTS[:soap_s4_url]
19
- @api_uri = URI.parse(@api_uri)
20
- @api_url = Net::HTTP.new(@api_uri.host, @api_uri.port)
21
-
22
- @api_url.use_ssl = DEFAULTS[:use_ssl]
23
- @wsa_soap_s4_to = DEFAULTS[:wsa_soap_s4_to]
24
- end
25
-
26
- private
27
-
28
- def build_request(type, method, body)
29
- client = Savon::Client.new(@api_wsdl)
30
- client.wsse.username = @username
31
- client.wsse.password = @password
32
- client.wsse.created_at = Time.now.utc
33
- client.wsse.expires_at = (Time.now + 120).utc
34
-
35
- header = {
36
- 'a:Action' => type,
37
- 'a:MessageID' => 'urn:uuid:99e6822c-5436-4fec-a243-3126c14924f6',
38
- 'a:ReplyTo' => {
39
- 'a:Address' => 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous'
40
- },
41
- 'VsDebuggerCausalityData' => 'uIDPo5GdUXRQCEBNrqnw0gOEloMAAAAAIAi4IHpPlUiMs1MZ2raBIhJnF/jqJLlAgZIny03R+tgACQAA',
42
- 'a:To' => @wsa_soap_s4_to
43
- }
44
-
45
- namespaces = {
46
- 'xmlns:s'=>"http://schemas.xmlsoap.org/soap/envelope/",
47
- 'xmlns:a'=>"http://schemas.xmlsoap.org/ws/2004/08/addressing",
48
- 'xmlns:u'=>"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd",
49
- 'xmlns:xsi'=>"http://www.w3.org/2001/XMLSchema-instance",
50
- 'xmlns:xsd'=>"http://www.w3.org/2001/XMLSchema",
51
- 'xmlns:o'=>"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
52
- }
53
-
54
- response = client.request type.downcase.to_sym do |soap|
55
- soap.input = [method, { 'xmlns'=>"http://exacttarget.com/wsdl/partnerAPI"}]
56
- soap.header = header
57
- soap.env_namespace = :s
58
- soap.namespaces = namespaces
59
- soap.body = body
60
- end
61
- end
62
-
63
- def build_retrieve(id, object_type, properties, filters=nil)
64
- body = '<RetrieveRequest>' +
65
- '<ClientIDs>' +
66
- '<ID>' + id.to_s + '</ID>' +
67
- '</ClientIDs>' +
68
- '<ObjectType>' + object_type.to_s + '</ObjectType>'
69
- properties.each do |p|
70
- body += '<Properties>' + p.to_s + '</Properties>'
71
- end
72
-
73
- body += filters if filters
74
-
75
- body + '</RetrieveRequest>'
76
- end
77
- end
78
- end
File without changes
@@ -1,235 +0,0 @@
1
- require 'rubygems'
2
- # require 'ruby-debug'
3
- require 'nokogiri'
4
- require 'savon'
5
- require 'cgi'
6
-
7
- client = Savon::Client.new do
8
- wsdl.document = "https://webservice.s4.exacttarget.com/etframework.wsdl"
9
- end
10
-
11
- client.wsse.credentials "", ""
12
- client.wsse.created_at = Time.now.utc
13
- client.wsse.expires_at = (Time.now + 60).utc
14
- client.http.headers["SOAPAction"] = '"urn:example#service"'
15
-
16
- # p client.wsdl.soap_actions
17
-
18
- # 1058396
19
-
20
- # [:create, :perform, :update, :schedule, :configure, :version_info, :execute, :extract, :get_system_status, :query, :delete, :retrieve, :describe]
21
- body = {
22
- 'wsdl:Objects' => {
23
- 'wsdl:EmailAddress' => 'wuuuuut@tester.com',
24
- 'wsdl:Attributes' => [
25
- {"wsdl:Name" => "First Name", "wsdl:Value" => "Wuuuuut"},
26
- {"wsdl:Name" => "Last Name", "wsdl:Value" => "Teeeester"},
27
- {"wsdl:Name" => "Company", "wsdl:Value" => "Northern Trail Outfitters"}
28
- ],
29
- 'wsdl:Lists' => {
30
- 'wsdl:ID' => '251',
31
- 'wsdl:Status' => 'Active'
32
- },
33
- :attributes! => {
34
- 'wsdl:Lists' => {'xsi:type' => 'wsdl:SubscriberList'}
35
- }
36
-
37
- }
38
- }
39
-
40
- header = {
41
- 'a:Action' => 'Delete',
42
- 'a:MessageID' => 'urn:uuid:99e6822c-5436-4fec-a243-3126c14924f6',
43
- 'a:ReplyTo' => {
44
- 'a:Address' => 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous'
45
- },
46
- 'VsDebuggerCausalityData' => 'uIDPo5GdUXRQCEBNrqnw0gOEloMAAAAAIAi4IHpPlUiMs1MZ2raBIhJnF/jqJLlAgZIny03R+tgACQAA',
47
- 'a:To' => 'https://webservice.s4.exacttarget.com/Service.asmx'
48
- }
49
- '
50
- <a:MessageID>urn:uuid:99e6822c-5436-4fec-a243-3126c14924f6</a:MessageID>
51
- <a:ReplyTo>
52
- <a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>
53
- </a:ReplyTo>
54
- <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo5GdUXRQCEBNrqnw0gOEloMAAAAAIAi4IHpPlUiMs1MZ2raBIhJnF/jqJLlAgZIny03R+tgACQAA</VsDebuggerCausalityData>
55
- <a:To s:mustUnderstand="1">https://webservice.s4.exacttarget.com/Service.asmx</a:To>
56
- <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
57
- <u:Timestamp u:Id="_0">
58
- <u:Created>2011-07-27T15:04:42.722Z</u:Created>
59
- <u:Expires>2011-07-27T15:09:42.722Z</u:Expires>
60
- </u:Timestamp>
61
- <o:UsernameToken u:Id="uuid-8e2ca2bf-1581-4d7a-a981-bbdab4639bc3-1">
62
- <o:Username>username</o:Username>
63
- <o:Password>password</o:Password>
64
- </o:UsernameToken>
65
- </o:Security>'
66
- #
67
- body = '<RetrieveRequest>
68
- <ObjectType>DataFolder</ObjectType>
69
- <Properties>ID</Properties>
70
- <Properties>Name</Properties>
71
- <Properties>ParentFolder.ID</Properties>
72
- <Properties>ParentFolder.Name</Properties>
73
- <Filter xsi:type="SimpleFilterPart">
74
- <Property>Account</Property>
75
- <SimpleOperator>equals</SimpleOperator>
76
- <Value>1058484</Value>
77
- </Filter>
78
- </RetrieveRequest>'
79
-
80
- body = '<RetrieveRequest>
81
- <ObjectType>List</ObjectType>
82
- <Properties>ListName</Properties>
83
- <Properties>ID</Properties>
84
- <Filter xsi:type="SimpleFilterPart">
85
- <Property>ListName</Property>
86
- <SimpleOperator>equals</SimpleOperator>
87
- <Value>All Subscribers</Value>
88
- </Filter>
89
- </RetrieveRequest>'
90
-
91
- body = '<RetrieveRequest>
92
- <ClientIDs>
93
- <ID>1058484</ID>
94
- </ClientIDs>
95
- <ObjectType>List</ObjectType>
96
- <Properties>CustomerKey</Properties>
97
- <Properties>ID</Properties>
98
- </RetrieveRequest>'
99
-
100
- body = {
101
- 'RetrieveRequest' => {
102
- 'ClientIDs' => {
103
- 'ID' => '1058484'
104
- },
105
- 'ObjectType' => 'List',
106
- 'Properties' => ['CustomerKey', 'ID']
107
- }
108
- }
109
- body_noko = Nokogiri::XML::Builder.new do |xml|
110
- xml.retrieve_request {
111
- xml.client_ids {
112
- xml.id "1058484"
113
- }
114
- xml.object_type "List"
115
- xml.properties "CustomerKey"
116
- xml.properties "ID"
117
- }
118
- end
119
-
120
- body = '<Objects xsi:type="Send">
121
- <PartnerKey xsi:nil="true"/>
122
- <Client><ID>1058484</ID></Client>
123
- <ObjectID xsi:nil="true"/>
124
- <Email>
125
- <PartnerKey xsi:nil="true"/>
126
- <ID>565</ID>
127
- <ObjectID xsi:nil="true"/>
128
- </Email>
129
- <List>
130
- <PartnerKey xsi:nil="true"/>
131
- <ObjectID xsi:nil="true"/>
132
- <ID>354</ID>
133
- </List>
134
- </Objects>'
135
- #
136
- # puts body
137
- #
138
- # puts '-============-'
139
- #
140
- # puts body_noko.text
141
- body = '<RetrieveRequest>
142
- <ClientIDs>
143
- <ID>1058484</ID>
144
- </ClientIDs>
145
- <ObjectType>DataFolder</ObjectType>
146
- <Properties>ID</Properties>
147
- <Properties>Name</Properties>
148
- <Properties>ParentFolder.ID</Properties>
149
- <Properties>ParentFolder.Name</Properties>
150
- <Filter xsi:type="SimpleFilterPart">
151
- <Property>ContentType</Property>
152
- <SimpleOperator>like</SimpleOperator>
153
- <Value>email</Value>
154
- </Filter>
155
- </RetrieveRequest>'
156
-
157
- body = '<RetrieveRequest>
158
- <ClientIDs>
159
- <ID>1058484</ID>
160
- </ClientIDs>
161
- <ObjectType>Email</ObjectType>
162
- <Properties>ID</Properties>
163
- <Properties>Name</Properties>
164
- <Properties>Folder</Properties>
165
- <Properties>CategoryID</Properties>
166
- <Filter xsi:type="SimpleFilterPart">
167
- <Property>Name</Property>
168
- <SimpleOperator>like</SimpleOperator>
169
- <Value>120911_piter_follow_up_side</Value>
170
- </Filter>
171
- </RetrieveRequest>'
172
-
173
- body = '<RetrieveRequest>
174
- <ClientIDs>
175
- <ID>1058484</ID>
176
- </ClientIDs>
177
- <ObjectType>Email</ObjectType>
178
- <Properties>ID</Properties>
179
- <Properties>Name</Properties>
180
- <Properties>Folder</Properties>
181
- <Properties>CategoryID</Properties>
182
- <Filter xsi:type="SimpleFilterPart">
183
- <Property>Name</Property>
184
- <SimpleOperator>like</SimpleOperator>
185
- <Value>120911_piter_follow_up_side</Value>
186
- </Filter>
187
- </RetrieveRequest>'
188
-
189
- body = '
190
- <Objects xsi:type="Email">
191
- <Client>
192
- <ID>1058484</ID>
193
- </Client>
194
- <ID>1724</ID>
195
- <ObjectID xsi:nil="true"/>
196
- </Objects>
197
- '
198
-
199
- html = CGI.escapeHTML('<center><h2>Way Cool Email</h2></center>')
200
- #
201
- # body = '
202
- # <Objects xsi:type="Email">
203
- # <ObjectID xsi:nil="true"/>
204
- # <Client><ID>1058484</ID></Client>
205
- # <CategoryID>354</CategoryID>
206
- # <HTMLBody>'+html+'</HTMLBody>
207
- # <Subject>Test Subject111</Subject>
208
- # <EmailType>HTML</EmailType>
209
- # <IsHTMLPaste>true</IsHTMLPaste>
210
- # </Objects>'
211
-
212
- namespaces = {
213
- 'xmlns:s'=>"http://schemas.xmlsoap.org/soap/envelope/",
214
- 'xmlns:a'=>"http://schemas.xmlsoap.org/ws/2004/08/addressing",
215
- 'xmlns:u'=>"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd",
216
- 'xmlns:xsi'=>"http://www.w3.org/2001/XMLSchema-instance",
217
- 'xmlns:xsd'=>"http://www.w3.org/2001/XMLSchema",
218
- 'xmlns:o'=>"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
219
- }
220
- #
221
- response = client.request :retrieve do |soap|
222
- soap.input = ['DeleteRequest', { 'xmlns'=>"http://exacttarget.com/wsdl/partnerAPI"}]
223
- soap.header = header
224
- soap.env_namespace = :s
225
- soap.namespaces = namespaces
226
- soap.body = body
227
- end
228
- #
229
- # response = client.request :create do |soap|
230
- # soap.input = ['CreateRequest', { 'xmlns'=>"http://exacttarget.com/wsdl/partnerAPI"}]
231
- # soap.header = header
232
- # soap.env_namespace = :s
233
- # soap.namespaces = namespaces
234
- # soap.body = body
235
- # end