cupid 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -28,21 +28,48 @@ folders = et_translator.retrieve_email_folders
28
28
  # Retrieving email copies for not default account (your_account_id can be nil - default account on ET)
29
29
  copies = et_translator.retrieve_email_copies(name)
30
30
 
31
+ # Retrieving emails from list for not default account (your_account_id can be nil - default account on ET)
32
+ copies = et_translator.retrieve_emails_from_list(list_id)
33
+
31
34
  # Creating new folder
32
35
  # not required fields for folder: description, content_type, is_active, is_editable, allow_children
33
36
  new_folder_id = et_translator.create_folder('title', :parent => parent_directory_id)
34
37
 
38
+ # Creating folders
39
+ # not required fields for folders: description, content_type, is_active, is_editable, allow_children
40
+ new_folder_ids = et_translator.create_folders(['title', 'title2'], :parent => parent_directory_id)
41
+
35
42
  # Creating new email
36
43
  # not required fields for email: email_type, is_html_paste, character_set, name, description, category_id
37
44
  new_email_id = et_translator.create_email('subject', 'body')
38
45
 
46
+ # Creating emails
47
+ # not required fields for emails: email_type, is_html_paste, character_set, name, description, category_id
48
+ new_email_ids = et_translator.create_emails({'subject' => 'body', 'subject2' => 'body2'})
49
+
50
+ # User object:
51
+ {
52
+ :email => 'email@email.com',
53
+ :lists => [list_id1, list_id2...],
54
+ :first_name => 'Name',
55
+ :last_name => 'Lastname'
56
+ }
57
+
39
58
  # Creating new subscriber
40
59
  # not required fields for subscriber: first_name, last_name, client_id
41
- new_subscriber_id = et_translator.create_subscriber('email@email.com')
60
+ new_subscriber_id = et_translator.create_subscriber(user_object)
61
+
62
+ # Creating subscribers
63
+ # not required fields for subscriber: first_name, last_name, client_id
64
+ new_subscriber_ids = et_translator.create_subscribers([user_object1, user_object2...])
42
65
 
43
66
  # Send email to list
44
67
  # not required fields for send: account
45
68
  send_tracking_id = et_translator.send_email_to_list(email_id, list_id)
69
+
70
+ # Send emails to lists
71
+ # not required fields for send: account
72
+ send_tracking_ids = et_translator.send_emails_to_lists({'email_id' => 'list_id','email_id' => 'list_id'...})
46
73
  ```
47
74
 
48
75
  ## Installation
@@ -50,13 +77,13 @@ send_tracking_id = et_translator.send_email_to_list(email_id, list_id)
50
77
  Puts this line into `Gemfile` then run `$ bundle`:
51
78
 
52
79
  ``` ruby
53
- gem 'cupid', '0.1.2'
80
+ gem 'cupid', '0.2.0'
54
81
  ```
55
82
 
56
83
  Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
57
84
 
58
85
  ``` ruby
59
- config.gem 'cupid', :version => '0.1.2'
86
+ config.gem 'cupid', :version => '0.2.0'
60
87
  ```
61
88
 
62
89
  Or manually install cupid gem: `$ gem install cupid`
@@ -30,19 +30,23 @@ module Cupid
30
30
  all_copies = response.css('Results').map{|f| {f.css('Name').to_a.map(&:text).join('/') => f.css('ID')[0].text}}
31
31
  end
32
32
 
33
- def create_email(subject, body, *args)
34
- options = args.extract_options!
35
- options[:subject] = CGI.escapeHTML subject.to_s
36
- options[:body] = CGI.escapeHTML body.to_s
37
- options[:client_id] ||= @account
33
+ def retrieve_emails_from_folder(folder, account=nil, properties=nil)
34
+ account ||= @account
35
+ properties ||= ['ID', 'Name']
36
+ filters = '<Filter xsi:type="SimpleFilterPart">' +
37
+ '<Property>CategoryID</Property>' +
38
+ '<SimpleOperator>equals</SimpleOperator>' +
39
+ '<Value>' + folder + '</Value>' +
40
+ '</Filter>'
38
41
 
39
- options[:email_type] ||= 'HTML'
40
- options[:is_html_paste] ||= 'true' # ??
41
- options[:character_set] ||= 'utf-8'
42
+ soap_body = build_retrieve(account.to_s, 'Email', properties, filters)
43
+ response = build_request('Retrieve', 'RetrieveRequestMsg', soap_body)
44
+ response = Nokogiri::XML(response.http.body).remove_namespaces!
45
+ all_copies = response.css('Results').map{|f| {f.css('Name').to_a.map(&:text).join('/') => f.css('ID')[0].text}}
46
+ end
42
47
 
43
- soap_body = '<Objects xsi:type="Email">' +
44
- create_email_object(options) +
45
- '</Objects>'
48
+ def create_email(subject, body, *args)
49
+ soap_body = prepare_email(subject, body, args)
46
50
 
47
51
  response = build_request('Create', 'CreateRequest', soap_body)
48
52
  response = Nokogiri::XML(response.http.body).remove_namespaces!
@@ -50,19 +54,7 @@ module Cupid
50
54
  end
51
55
 
52
56
  def create_folder(title, *args)
53
- options = args.extract_options!
54
- options[:title] = CGI.escapeHTML title.to_s
55
- options[:description] ||= 'description'
56
- options[:client_id] ||= @account
57
-
58
- options[:content_type] ||= 'email'
59
- options[:is_active] ||= 'true'
60
- options[:is_editable] ||= 'true'
61
- options[:allow_children] ||= 'true'
62
-
63
- soap_body = '<Objects xsi:type="DataFolder">' +
64
- create_folder_object(options) +
65
- '</Objects>'
57
+ soap_body = prepare_folder(title, args)
66
58
 
67
59
  response = build_request('Create', 'CreateRequest', soap_body)
68
60
  response = Nokogiri::XML(response.http.body).remove_namespaces!
@@ -70,27 +62,72 @@ module Cupid
70
62
  end
71
63
 
72
64
  def send_email_to_list(email_id, list_id, account=nil)
73
- account ||= @account
74
- soap_body = '<Objects xsi:type="Send">' +
75
- create_send_object(email_id, list_id, account) +
76
- '</Objects>'
65
+ soap_body = prepare_send_object(email_id, list_id, account)
77
66
 
78
67
  response = build_request('Create', 'CreateRequest', soap_body)
79
68
  response = Nokogiri::XML(response.http.body).remove_namespaces!
80
69
  created_send_id = response.css('NewID').text
81
70
  end
82
71
 
83
- def email_link(email_id)
84
- "https://members.s4.exacttarget.com/Content/Email/EmailEdit.aspx?eid=" + email_id.to_s
72
+ def create_emails(subject_bodies, *args)
73
+ soap_body = ''
74
+ subject_bodies.each{ |subject, body| soap_body += prepare_email(subject, body, args) }
75
+
76
+ response = build_request('Create', 'CreateRequest', soap_body)
77
+ response = Nokogiri::XML(response.http.body).remove_namespaces!
78
+ response.css('Results').map{ |f| f.css('NewID').text }
79
+ end
80
+
81
+ def create_folders(titles, *args)
82
+ soap_body = titles.map{ |title| prepare_folder(title, args) }.join('')
83
+
84
+ response = build_request('Create', 'CreateRequest', soap_body)
85
+ response = Nokogiri::XML(response.http.body).remove_namespaces!
86
+ response.css('Results').map{ |f| f.css('NewID').text }
87
+ end
88
+
89
+ def send_emails_to_lists(emails_lists, account=nil)
90
+ soap_body = ''
91
+ emails_lists.each{ |email_id, list_id| soap_body += prepare_send(email_id, list_id, account) }
92
+
93
+ response = build_request('Create', 'CreateRequest', soap_body)
94
+ response = Nokogiri::XML(response.http.body).remove_namespaces!
95
+ response.css('Results').map{ |f| f.css('NewID').text }
96
+ end
97
+
98
+ def delete_email(email_id, account=nil)
99
+ soap_body = prepare_delete_email(email_id, account)
100
+
101
+ response = build_request('Delete', 'DeleteRequest', soap_body)
102
+ response = Nokogiri::XML(response.http.body).remove_namespaces!
103
+ response.css('Results').css('StatusCode').text == 'OK'
85
104
  end
86
105
 
87
- def create_emails(*args)
88
- raise NoMethodError.new "I will implement this method soon"
106
+ def delete_emails(emails, account=nil)
107
+ soap_body = emails.map{ |email_id| prepare_delete_email(email_id, account) }.join('')
108
+
109
+ response = build_request('Delete', 'DeleteRequest', soap_body)
110
+ response = Nokogiri::XML(response.http.body).remove_namespaces!
111
+ response.css('Results').map{ |f| f.css('StatusCode').text == 'OK' }
89
112
  end
90
113
 
91
114
  private
115
+
116
+ def prepare_email(subject, body, *args)
117
+ options = args.extract_options!
118
+ options[:subject] = CGI.escapeHTML subject.to_s
119
+ options[:body] = CGI.escapeHTML body.to_s
120
+ options[:client_id] ||= @account
121
+
122
+ options[:email_type] ||= 'HTML'
123
+ options[:is_html_paste] ||= 'true' # ??
124
+ options[:character_set] ||= 'utf-8'
125
+
126
+ create_email_object(options)
127
+ end
128
+
92
129
  def create_email_object(options)
93
- email_object = '<ObjectID xsi:nil="true"/>'
130
+ email_object = '<Objects xsi:type="Email"><ObjectID xsi:nil="true"/>'
94
131
  email_object += '<Client><ID>' + options[:client_id].to_s + '</ID></Client>' if options[:client_id]
95
132
  email_object += '<CategoryID>' + options[:category_id].to_s + '</CategoryID>' if options[:category_id]
96
133
  email_object += '<Name>' + options[:name].to_s + '</Name>' if options[:name]
@@ -99,11 +136,25 @@ module Cupid
99
136
  '<HTMLBody>' + options[:body] + '</HTMLBody>' +
100
137
  '<EmailType>' + options[:email_type] + '</EmailType>' +
101
138
  '<IsHTMLPaste>' + options[:is_html_paste] + '</IsHTMLPaste>' +
102
- '<CharacterSet>' + options[:character_set] + '</CharacterSet>'
139
+ '<CharacterSet>' + options[:character_set] + '</CharacterSet></Objects>'
140
+ end
141
+
142
+ def prepare_folder(title, *args)
143
+ options = args.extract_options!
144
+ options[:title] = CGI.escapeHTML title.to_s
145
+ options[:description] ||= 'description'
146
+ options[:client_id] ||= @account
147
+
148
+ options[:content_type] ||= 'email'
149
+ options[:is_active] ||= 'true'
150
+ options[:is_editable] ||= 'true'
151
+ options[:allow_children] ||= 'true'
152
+
153
+ create_folder_object(options)
103
154
  end
104
155
 
105
156
  def create_folder_object(options)
106
- folder_object = '<ObjectID xsi:nil="true"/>'
157
+ folder_object = '<Objects xsi:type="DataFolder"><ObjectID xsi:nil="true"/>'
107
158
  folder_object += '<Client><ID>' + options[:client_id].to_s + '</ID></Client>' if options[:client_id]
108
159
  folder_object += '<CustomerKey>' + options[:title].to_s + '</CustomerKey>' if options[:title]
109
160
  folder_object += '<Name>' + options[:title].to_s + '</Name>' +
@@ -121,22 +172,44 @@ module Cupid
121
172
  <ObjectID xsi:nil="true"/>
122
173
  </ParentFolder>'
123
174
  end
175
+ folder_object += '</Objects>'
176
+ end
177
+
178
+ def prepare_send(email_id, list_id, account=nil)
179
+ account ||= @account
180
+ create_send_object(email_id, list_id, account)
124
181
  end
125
182
 
126
183
  def create_send_object(email_id, list_id, account)
127
- send_object = '<PartnerKey xsi:nil="true"/>' +
128
- '<ObjectID xsi:nil="true"/>' +
129
- '<Client><ID>' + account.to_s + '</ID></Client>' +
130
- '<Email>' +
131
- '<PartnerKey xsi:nil="true"/>' +
132
- '<ID>' + email_id.to_s + '</ID>' +
133
- '<ObjectID xsi:nil="true"/>' +
134
- '</Email>' +
135
- '<List>' +
136
- '<PartnerKey xsi:nil="true"/>' +
137
- '<ObjectID xsi:nil="true"/>' +
138
- '<ID>' + list_id.to_s + '</ID>' +
139
- '</List>'
184
+ '<Objects xsi:type="Send"><PartnerKey xsi:nil="true"/>' +
185
+ '<ObjectID xsi:nil="true"/>' +
186
+ '<Client><ID>' + account.to_s + '</ID></Client>' +
187
+ '<Email>' +
188
+ '<PartnerKey xsi:nil="true"/>' +
189
+ '<ID>' + email_id.to_s + '</ID>' +
190
+ '<ObjectID xsi:nil="true"/>' +
191
+ '</Email>' +
192
+ '<List>' +
193
+ '<PartnerKey xsi:nil="true"/>' +
194
+ '<ObjectID xsi:nil="true"/>' +
195
+ '<ID>' + list_id.to_s + '</ID>' +
196
+ '</List>' +
197
+ '</Objects>'
198
+ end
199
+
200
+ def prepare_delete_email(email_id, account=nil)
201
+ account ||= @account
202
+ create_delete_email_object(email_id, account)
203
+ end
204
+
205
+ def create_delete_email_object(email_id, account)
206
+ '<Objects xsi:type="Email">' +
207
+ '<Client>' +
208
+ '<ID>' + account + '</ID>' +
209
+ '</Client>' +
210
+ '<ID>' + email_id + '</ID>' +
211
+ '<ObjectID xsi:nil="true"/>' +
212
+ '</Objects>'
140
213
  end
141
214
  end
142
215
  end
@@ -1,38 +1,57 @@
1
1
  module Cupid
2
2
  class Session
3
- def create_subscriber(email, *args)
4
- options = args.extract_options!
5
- options[:email] = email.to_s
6
- options[:client_id] ||= @account
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)
7
12
 
8
- soap_body = '<Objects xsi:type="Subscriber">' +
9
- create_subscriber_object(options) +
10
- '</Objects>'
11
-
12
- build_request('Create', 'CreateRequest', soap_body)
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
13
16
  end
14
17
 
15
- def create_subscribers(*args)
16
- raise NoMethodError.new "I will implement this method soon"
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
17
24
  end
18
25
 
19
26
  private
20
- def create_subscriber_object(options)
21
- subscriber_object = '<ObjectID xsi:nil="true"/>'
22
- subscriber_object += '<PartnerKey xsi:nil="true" />'
23
- subscriber_object += '<Client><ID>' + options[:client_id].to_s + '</ID></Client>' if options[:client_id]
24
- subscriber_object += '<Lists>' + options[:lists].map(&:list_object).join('') + '</Lists>' if options[:lists]
25
- subscriber_object += '<FirstName>' + options[:first_name].to_s + '</FirstName>' if options[:first_name]
26
- subscriber_object += '<LastName>' + options[:last_name].to_s + '</LastName>' if options[:last_name]
27
- subscriber_object += '<EmailAddress>' + options[:email] + '</EmailAddress>'
28
- end
29
-
30
- def list_object(list_id)
31
- '<PartnerKey xsi:nil="true">
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
+ end
44
+
45
+ def list_object(list_id)
46
+ '<Lists>
47
+ <PartnerKey xsi:nil="true">
32
48
  </PartnerKey>
33
49
  <ID>' + list_id.to_s + '</ID>
34
50
  <ObjectID xsi:nil="true">
35
- </ObjectID>'
36
- end
51
+ </ObjectID>
52
+ </Lists>'
53
+ end
54
+
55
+ subscriber_object += '</Objects>'
37
56
  end
38
57
  end
@@ -1,3 +1,3 @@
1
1
  module Cupid
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -38,7 +38,7 @@ body = {
38
38
  }
39
39
 
40
40
  header = {
41
- 'a:Action' => 'Create',
41
+ 'a:Action' => 'Delete',
42
42
  'a:MessageID' => 'urn:uuid:99e6822c-5436-4fec-a243-3126c14924f6',
43
43
  'a:ReplyTo' => {
44
44
  'a:Address' => 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous'
@@ -129,7 +129,7 @@ body = '<Objects xsi:type="Send">
129
129
  <List>
130
130
  <PartnerKey xsi:nil="true"/>
131
131
  <ObjectID xsi:nil="true"/>
132
- <ID>57</ID>
132
+ <ID>354</ID>
133
133
  </List>
134
134
  </Objects>'
135
135
  #
@@ -170,13 +170,39 @@ body = '<RetrieveRequest>
170
170
  </Filter>
171
171
  </RetrieveRequest>'
172
172
 
173
- html = CGI.escapeHTML('<center><h2>Way Cool Email</h2></center>')
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>'
174
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
+ #
175
201
  # body = '
176
202
  # <Objects xsi:type="Email">
177
203
  # <ObjectID xsi:nil="true"/>
178
204
  # <Client><ID>1058484</ID></Client>
179
- # <CategoryID>277</CategoryID>
205
+ # <CategoryID>354</CategoryID>
180
206
  # <HTMLBody>'+html+'</HTMLBody>
181
207
  # <Subject>Test Subject111</Subject>
182
208
  # <EmailType>HTML</EmailType>
@@ -193,7 +219,7 @@ namespaces = {
193
219
  }
194
220
  #
195
221
  response = client.request :retrieve do |soap|
196
- soap.input = ['RetrieveRequestMsg', { 'xmlns'=>"http://exacttarget.com/wsdl/partnerAPI"}]
222
+ soap.input = ['DeleteRequest', { 'xmlns'=>"http://exacttarget.com/wsdl/partnerAPI"}]
197
223
  soap.header = header
198
224
  soap.env_namespace = :s
199
225
  soap.namespaces = namespaces
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cupid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - gazay