cupid 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cupid (0.0.2)
4
+ cupid (0.0.6)
5
5
  builder (>= 2.1.2)
6
6
  nokogiri (>= 1.4.1)
7
7
  savon (>= 0.9.0)
@@ -18,7 +18,7 @@ GEM
18
18
  rack
19
19
  nokogiri (1.5.0)
20
20
  nori (1.0.2)
21
- rack (1.3.2)
21
+ rack (1.3.3)
22
22
  savon (0.9.7)
23
23
  akami (~> 1.0)
24
24
  builder (>= 2.1.2)
data/README.md CHANGED
@@ -6,7 +6,36 @@ Sponsored by Evil Martians <http://evilmartians.com>
6
6
 
7
7
  ## Usage
8
8
 
9
+ Add cupid initializer to your config/initializers and now there only two parameters to configure:
9
10
 
11
+ ``` ruby
12
+ Cupid.configure do |config|
13
+ config.username = 'username'
14
+ config.password = 'password'
15
+ end
16
+ ```
17
+
18
+ After that you can create Cupid::Session object and do some stuff through it:
19
+
20
+ ``` ruby
21
+ # Creating session
22
+ et_translator = Cupid::Session.new
23
+
24
+ # Retrieving folders for not default account (your_account_id can be nil - default account on ET)
25
+ folders = et_translator.retrieve_email_folders(your_account_id)
26
+
27
+ # Creating new folder
28
+ # not required fields for folder: description, content_type, is_active, is_editable, allow_children
29
+ new_folder_id = et_translator.create_folder('title', :parent => parent_directory_id, :client_id => your_account_id)
30
+
31
+ # Creating new email
32
+ # not required fields for email: email_type, is_html_paste, character_set, name, description, category_id
33
+ new_email_id = et_translator.create_email('subject', 'body', :client_id => your_account_id, :category_id => new_folder_id)
34
+
35
+ # Creating new subscriber
36
+ # not required fields for subscriber: first_name, last_name, client_id
37
+ new_subscriber_id = et_translator.create_subscriber('email@email.com')
38
+ ```
10
39
 
11
40
  ## Installation
12
41
 
@@ -12,7 +12,8 @@ module Cupid
12
12
  attr_accessor(
13
13
  :username,
14
14
  # :api_type, #now it's only soap s4. But i want MOAR
15
- :password
15
+ :password,
16
+ :account
16
17
  )
17
18
  end
18
19
  end
@@ -1,22 +1,15 @@
1
1
  module Cupid
2
2
  class Session
3
- def retrieve_email_folders(account)
4
- soap_body = '<RetrieveRequest>
5
- <ClientIDs>
6
- <ID>' + account.to_s + '</ID>
7
- </ClientIDs>
8
- <ObjectType>DataFolder</ObjectType>
9
- <Properties>ID</Properties>
10
- <Properties>Name</Properties>
11
- <Properties>ParentFolder.ID</Properties>
12
- <Properties>ParentFolder.Name</Properties>
13
- <Filter xsi:type="SimpleFilterPart">
14
- <Property>ContentType</Property>
15
- <SimpleOperator>like</SimpleOperator>
16
- <Value>email</Value>
17
- </Filter>
18
- </RetrieveRequest>'
3
+ def retrieve_email_folders(account=nil, properties=nil)
4
+ account ||= @account
5
+ properties ||= ['ID', 'Name', 'ParentFolder.ID', 'ParentFolder.Name']
6
+ filters = 'Filter xsi:type="SimpleFilterPart"' => {
7
+ 'Property' => 'ContentType',
8
+ 'SimpleOperator' => 'like',
9
+ 'Value' => 'email'
10
+ }
19
11
 
12
+ soap_body = build_retrieve(account.to_s, 'DataFolder', properties, filters)
20
13
  response = build_request('Retrieve', 'RetrieveRequestMsg', soap_body)
21
14
  response = Nokogiri::XML(response.http.body).remove_namespaces!
22
15
  all_folders = response.css('Results').map{|f| {f.css('Name').to_a.map(&:text).join('/') => f.css('ID')[0].text}}
@@ -26,7 +19,8 @@ module Cupid
26
19
  options = args.extract_options!
27
20
  options[:subject] = CGI.escapeHTML subject.to_s
28
21
  options[:body] = CGI.escapeHTML body.to_s
29
-
22
+ options[:client_id] ||= @account
23
+
30
24
  options[:email_type] ||= 'HTML'
31
25
  options[:is_html_paste] ||= 'true' # ??
32
26
  options[:character_set] ||= 'utf-8'
@@ -44,6 +38,7 @@ module Cupid
44
38
  options = args.extract_options!
45
39
  options[:title] = CGI.escapeHTML title.to_s
46
40
  options[:description] ||= 'description'
41
+ options[:client_id] ||= @account
47
42
 
48
43
  options[:content_type] ||= 'email'
49
44
  options[:is_active] ||= 'true'
@@ -59,6 +54,17 @@ module Cupid
59
54
  created_folder_id = response.css('NewID').text
60
55
  end
61
56
 
57
+ def send_email_to_list(email_id, list_id, account=nil)
58
+ account ||= @account
59
+ soap_body = '<Objects xsi:type="Send">' +
60
+ create_send_object(email_id, list_id, account) +
61
+ '</Objects>'
62
+
63
+ response = build_request('Create', 'CreateRequest', soap_body)
64
+ response = Nokogiri::XML(response.http.body).remove_namespaces!
65
+ created_send_id = response.css('NewID').text
66
+ end
67
+
62
68
  def email_link(email_id)
63
69
  "https://members.s4.exacttarget.com/Content/Email/EmailEdit.aspx?eid=" + email_id.to_s
64
70
  end
@@ -101,5 +107,22 @@ module Cupid
101
107
  </ParentFolder>'
102
108
  end
103
109
  end
110
+
111
+ def create_send_object(email_id, list_id, account)
112
+ send_object = '<PartnerKey xsi:nil="true"/>' +
113
+ '<ObjectID xsi:nil="true"/>' +
114
+ '<Client><ID>' + account.to_s + '</ID></Client>' +
115
+ '<Email>' +
116
+ '<PartnerKey xsi:nil="true"/>' +
117
+ '<ID>' + email_id.to_s + '</ID>' +
118
+ '<ObjectID xsi:nil="true"/>' +
119
+ '</Email>' +
120
+ '<List>' +
121
+ '<PartnerKey xsi:nil="true"/>' +
122
+ '<ObjectID xsi:nil="true"/>' +
123
+ '<ID>' + list_id.to_s + '</CustomerKey>' +
124
+ '</List>' +
125
+ '</Objects>'
126
+ end
104
127
  end
105
128
  end
@@ -0,0 +1,13 @@
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
@@ -3,6 +3,7 @@ module Cupid
3
3
  def create_subscriber(email, *args)
4
4
  options = args.extract_options!
5
5
  options[:email] = email.to_s
6
+ options[:client_id] ||= @account
6
7
 
7
8
  soap_body = '<Objects xsi:type="Subscriber">' +
8
9
  create_subscriber_object(options) +
@@ -12,6 +12,7 @@ module Cupid
12
12
  options = args.extract_options!
13
13
  @username = options[:username] ||= Cupid.username
14
14
  @password = options[:password] ||= Cupid.password
15
+ @account = options[:account] ||= Cupid.account
15
16
  @headers = {"Content-Type" => "application/x-www-form-urlencoded", "Connection" => "close"}
16
17
 
17
18
  @api_uri = @api_wsdl = DEFAULTS[:soap_s4_url]
@@ -23,39 +24,54 @@ module Cupid
23
24
  end
24
25
 
25
26
  private
26
- def build_request(type, method, body)
27
- client = Savon::Client.new(@api_wsdl)
28
- client.wsse.username = @username
29
- client.wsse.password = @password
30
- client.wsse.created_at = Time.now.utc
31
- client.wsse.expires_at = (Time.now + 120).utc
32
-
33
- header = {
34
- 'a:Action' => type,
35
- 'a:MessageID' => 'urn:uuid:99e6822c-5436-4fec-a243-3126c14924f6',
36
- 'a:ReplyTo' => {
37
- 'a:Address' => 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous'
38
- },
39
- 'VsDebuggerCausalityData' => 'uIDPo5GdUXRQCEBNrqnw0gOEloMAAAAAIAi4IHpPlUiMs1MZ2raBIhJnF/jqJLlAgZIny03R+tgACQAA',
40
- 'a:To' => @wsa_soap_s4_to
41
- }
42
-
43
- namespaces = {
44
- 'xmlns:s'=>"http://schemas.xmlsoap.org/soap/envelope/",
45
- 'xmlns:a'=>"http://schemas.xmlsoap.org/ws/2004/08/addressing",
46
- 'xmlns:u'=>"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd",
47
- 'xmlns:xsi'=>"http://www.w3.org/2001/XMLSchema-instance",
48
- 'xmlns:xsd'=>"http://www.w3.org/2001/XMLSchema",
49
- 'xmlns:o'=>"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
50
- }
51
-
52
- response = client.request type.downcase.to_sym do |soap|
53
- soap.input = [method, { 'xmlns'=>"http://exacttarget.com/wsdl/partnerAPI"}]
54
- soap.header = header
55
- soap.env_namespace = :s
56
- soap.namespaces = namespaces
57
- soap.body = body
58
- end
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
59
60
  end
61
+ end
62
+
63
+ def build_retrieve(id, object_type, properties, filters=nil)
64
+ body = {'RetrieveRequest' => {
65
+ 'ClientIDs' => {
66
+ 'ID' => id
67
+ },
68
+ 'ObjectType' => object_type,
69
+ 'Properties' => properties
70
+ }
71
+ }
72
+ body['RetrieveRequest'].merge! filters if filters
73
+
74
+ body
75
+ end
60
76
  end
61
77
  end
@@ -1,3 +1,3 @@
1
1
  module Cupid
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  # require 'ruby-debug'
3
+ require 'nokogiri'
3
4
  require 'savon'
4
5
  require 'cgi'
5
6
 
@@ -37,7 +38,7 @@ body = {
37
38
  }
38
39
 
39
40
  header = {
40
- 'a:Action' => 'Retrieve',
41
+ 'a:Action' => 'Create',
41
42
  'a:MessageID' => 'urn:uuid:99e6822c-5436-4fec-a243-3126c14924f6',
42
43
  'a:ReplyTo' => {
43
44
  'a:Address' => 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous'
@@ -91,17 +92,52 @@ body = '<RetrieveRequest>
91
92
  <ClientIDs>
92
93
  <ID>1058484</ID>
93
94
  </ClientIDs>
94
- <ObjectType>DataFolder</ObjectType>
95
+ <ObjectType>List</ObjectType>
96
+ <Properties>CustomerKey</Properties>
95
97
  <Properties>ID</Properties>
96
- <Properties>Name</Properties>
97
- <Properties>ParentFolder.ID</Properties>
98
- <Properties>ParentFolder.Name</Properties>
99
- <Filter xsi:type="SimpleFilterPart">
100
- <Property>ContentType</Property>
101
- <SimpleOperator>like</SimpleOperator>
102
- <Value>email</Value>
103
- </Filter>
104
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>57</ID>
133
+ </List>
134
+ </Objects>'
135
+ #
136
+ # puts body
137
+ #
138
+ # puts '-============-'
139
+ #
140
+ # puts body_noko.text
105
141
 
106
142
  # body = '<RetrieveRequest>
107
143
  # <ClientIDs>
@@ -142,7 +178,7 @@ namespaces = {
142
178
  }
143
179
  #
144
180
  response = client.request :retrieve do |soap|
145
- soap.input = ['RetrieveRequestMsg', { 'xmlns'=>"http://exacttarget.com/wsdl/partnerAPI"}]
181
+ soap.input = ['CreateRequest', { 'xmlns'=>"http://exacttarget.com/wsdl/partnerAPI"}]
146
182
  soap.header = header
147
183
  soap.env_namespace = :s
148
184
  soap.namespaces = namespaces
metadata CHANGED
@@ -1,80 +1,58 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cupid
3
- version: !ruby/object:Gem::Version
4
- hash: 19
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 6
10
- version: 0.0.6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - gazay
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-05 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-22 00:00:00.000000000 %:z
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
21
16
  name: builder
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2153805140 !ruby/object:Gem::Requirement
24
18
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 15
29
- segments:
30
- - 2
31
- - 1
32
- - 2
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
33
22
  version: 2.1.2
34
23
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: nokogiri
38
24
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *2153805140
26
+ - !ruby/object:Gem::Dependency
27
+ name: nokogiri
28
+ requirement: &2153804440 !ruby/object:Gem::Requirement
40
29
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 5
45
- segments:
46
- - 1
47
- - 4
48
- - 1
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
49
33
  version: 1.4.1
50
34
  type: :runtime
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: savon
54
35
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *2153804440
37
+ - !ruby/object:Gem::Dependency
38
+ name: savon
39
+ requirement: &2153803980 !ruby/object:Gem::Requirement
56
40
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 59
61
- segments:
62
- - 0
63
- - 9
64
- - 0
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
65
44
  version: 0.9.0
66
45
  type: :runtime
67
- version_requirements: *id003
68
- description: Send love, not war. This version of cupid can only work with ET SOAP API with s4.
69
- email:
46
+ prerelease: false
47
+ version_requirements: *2153803980
48
+ description: Send love, not war. This version of cupid can only work with ET SOAP
49
+ API with s4.
50
+ email:
70
51
  - gazay@evilmartians.com
71
52
  executables: []
72
-
73
53
  extensions: []
74
-
75
54
  extra_rdoc_files: []
76
-
77
- files:
55
+ files:
78
56
  - Gemfile
79
57
  - Gemfile.lock
80
58
  - README.md
@@ -84,43 +62,36 @@ files:
84
62
  - lib/cupid/configuration.rb
85
63
  - lib/cupid/methods.rb
86
64
  - lib/cupid/methods/email.rb
65
+ - lib/cupid/methods/list.rb
87
66
  - lib/cupid/methods/subscriber.rb
88
67
  - lib/cupid/session.rb
89
68
  - lib/cupid/version.rb
90
69
  - spec/cupid/cupid_spec.rb
91
70
  - tmp/dancing_with_ET.rb
92
- homepage: ""
71
+ has_rdoc: true
72
+ homepage: ''
93
73
  licenses: []
94
-
95
74
  post_install_message:
96
75
  rdoc_options: []
97
-
98
- require_paths:
76
+ require_paths:
99
77
  - lib
100
- required_ruby_version: !ruby/object:Gem::Requirement
78
+ required_ruby_version: !ruby/object:Gem::Requirement
101
79
  none: false
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- hash: 3
106
- segments:
107
- - 0
108
- version: "0"
109
- required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
85
  none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- hash: 3
115
- segments:
116
- - 0
117
- version: "0"
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
118
90
  requirements: []
119
-
120
91
  rubyforge_project: cupid
121
- rubygems_version: 1.8.6
92
+ rubygems_version: 1.6.2
122
93
  signing_key:
123
94
  specification_version: 3
124
95
  summary: Create, organize and send emails through Exact Target SOAP API
125
- test_files:
96
+ test_files:
126
97
  - spec/cupid/cupid_spec.rb