cupid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cupid.gemspec
4
+ gemspec
@@ -0,0 +1,39 @@
1
+ # Cupid gem — Create, organize and send emails through Exact Target
2
+
3
+ Send love, not war. This version of cupid can only work with ET SOAP API with s4.
4
+
5
+ ## Usage
6
+
7
+
8
+
9
+ ## Installation
10
+
11
+ Puts this line into `Gemfile` then run `$ bundle`:
12
+
13
+ ``` ruby
14
+ gem 'cupid', '0.0.1'
15
+ ```
16
+
17
+ Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
18
+
19
+ ``` ruby
20
+ config.gem 'cupid', :version => '0.0.1'
21
+ ```
22
+
23
+ Or manually install cupid gem: `$ gem install cupid`
24
+
25
+ ## Contributors
26
+
27
+ * @gazay
28
+
29
+ ## License
30
+
31
+ The MIT License
32
+
33
+ Copyright (c) 2011 gazay
34
+
35
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
36
+
37
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
38
+
39
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "cupid/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "cupid"
7
+ s.version = Cupid::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['gazay']
10
+ s.email = ['gazay@evilmartians.com']
11
+ s.homepage = ""
12
+ s.summary = %q{Create, organize and send emails through Exact Target SOAP API}
13
+ s.description = %q{Send love, not war. This version of cupid can only work with ET SOAP API with s4.}
14
+
15
+ s.rubyforge_project = "cupid"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,10 @@
1
+ require("cupid/configuration")
2
+
3
+ module Cupid
4
+ extend Configuration
5
+
6
+ def self.configure
7
+ yield self if block_given?
8
+ end
9
+
10
+ end
@@ -0,0 +1,20 @@
1
+ require 'erb'
2
+ require 'uri'
3
+ require 'savon'
4
+ require 'logger'
5
+ require 'builder'
6
+ require 'net/https'
7
+ require 'nokogiri'
8
+ require 'cupid/session'
9
+
10
+ include(ERB::Util)
11
+
12
+ module Cupid
13
+ module Configuration
14
+ attr_accessor(
15
+ :username,
16
+ # :api_type, #now it's only soap s4. But i want MOAR
17
+ :password
18
+ )
19
+ end
20
+ end
@@ -0,0 +1,2 @@
1
+ require("cupid/methods/email")
2
+ require("cupid/methods/subscriber")
@@ -0,0 +1,63 @@
1
+ module Cupid
2
+ class Session
3
+ def retreive_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>'
19
+
20
+ response = build_request('Retrieve', 'RetrieveRequestMsg', soap_body)
21
+ response = Nokogiri::XML(response.http.body).remove_namespaces!
22
+ all_folders = response.css('Results').map{|f| {f.css('Name').to_a.map(&:text).join('/') => f.css('ID')[0].text}}
23
+ end
24
+
25
+ def create_email(subject, body, *args)
26
+ options = args.extract_options!
27
+ options[:subject] = subject.to_s
28
+ options[:body] = CGI.escapeHTML body.to_s
29
+
30
+ options[:email_type] = 'HTML'
31
+ options[:is_html_paste] = 'true' # ??
32
+
33
+ soap_body = '<Objects xsi:type="Email">' +
34
+ create_email_object(options) +
35
+ '</Objects>'
36
+
37
+ response = build_request('Create', 'CreateRequest', soap_body)
38
+ response = Nokogiri::XML(response.http.body).remove_namespaces!
39
+ created_email_id = response.css('NewID').text
40
+ end
41
+
42
+ def email_link(email_id)
43
+ "https://members.s4.exacttarget.com/Content/Email/EmailEdit.aspx?eid=" + email_id.to_s
44
+ end
45
+
46
+ def create_emails(*args)
47
+ raise NoMethodError.new "I will implement this method soon"
48
+ end
49
+
50
+ private
51
+ def create_email_object(options)
52
+ email_object = '<ObjectID xsi:nil="true"/>'
53
+ email_object += '<Client><ID>' + options[:client_id].to_s + '</ID></Client>' if options[:client_id]
54
+ email_object += '<CategoryID>' + options[:category_id].to_s + '</CategoryID>' if options[:category_id]
55
+ email_object += '<Name>' + options[:name].to_s + '</Name>' if options[:name]
56
+ email_object += '<Description>' + options[:description].to_s + '</Description>' if options[:description]
57
+ email_object += '<Subject>' + options[:subject] + '</Subject>' +
58
+ '<HTMLBody>' + options[:body] + '</HTMLBody>' +
59
+ '<EmailType>' + options[:email_type] + '</EmailType>' +
60
+ '<IsHTMLPaste>' + options[:is_html_paste] + '</IsHTMLPaste>'
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,37 @@
1
+ module Cupid
2
+ class Session
3
+ def create_subscriber(email, *args)
4
+ options = args.extract_options!
5
+ options[:email] = email.to_s
6
+
7
+ soap_body = '<Objects xsi:type="Subscriber">' +
8
+ create_subscriber_object(options) +
9
+ '</Objects>'
10
+
11
+ build_request('Create', 'CreateRequest', soap_body)
12
+ end
13
+
14
+ def create_subscribers(*args)
15
+ raise NoMethodError.new "I will implement this method soon"
16
+ end
17
+
18
+ private
19
+ def create_subscriber_object(options)
20
+ subscriber_object = '<ObjectID xsi:nil="true"/>'
21
+ subscriber_object += '<PartnerKey xsi:nil="true" />'
22
+ subscriber_object += '<Client><ID>' + options[:client_id].to_s + '</ID></Client>' if options[:client_id]
23
+ subscriber_object += '<Lists>' + options[:lists].map(&:list_object).join('') + '</Lists>' if options[:lists]
24
+ subscriber_object += '<FirstName>' + options[:first_name].to_s + '</FirstName>' if options[:first_name]
25
+ subscriber_object += '<LastName>' + options[:last_name].to_s + '</LastName>' if options[:last_name]
26
+ subscriber_object += '<EmailAddress>' + options[:email] + '</EmailAddress>'
27
+ end
28
+
29
+ def list_object(list_id)
30
+ '<PartnerKey xsi:nil="true">
31
+ </PartnerKey>
32
+ <ID>' + list_id.to_s + '</ID>
33
+ <ObjectID xsi:nil="true">
34
+ </ObjectID>'
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,61 @@
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
+ @headers = {"Content-Type" => "application/x-www-form-urlencoded", "Connection" => "close"}
16
+
17
+ @api_uri = @api_wsdl = DEFAULTS[:soap_s4_url]
18
+ @api_uri = URI.parse(@api_uri)
19
+ @api_url = Net::HTTP.new(@api_uri.host, @api_uri.port)
20
+
21
+ @api_url.use_ssl = DEFAULTS[:use_ssl]
22
+ @wsa_soap_s4_to = DEFAULTS[:wsa_soap_s4_to]
23
+ end
24
+
25
+ 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
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Cupid
2
+ VERSION = '0.0.1'
3
+ end
File without changes
@@ -0,0 +1,158 @@
1
+ require 'rubygems'
2
+ require 'ruby-debug'
3
+ require 'savon'
4
+ require 'cgi'
5
+
6
+ client = Savon::Client.new do
7
+ wsdl.document = "https://webservice.s4.exacttarget.com/etframework.wsdl"
8
+ end
9
+
10
+ client.wsse.credentials "username", "password"
11
+ client.wsse.created_at = Time.now.utc
12
+ client.wsse.expires_at = (Time.now + 60).utc
13
+ client.http.headers["SOAPAction"] = '"urn:example#service"'
14
+
15
+ # p client.wsdl.soap_actions
16
+
17
+ # 1058396
18
+
19
+ # [:create, :perform, :update, :schedule, :configure, :version_info, :execute, :extract, :get_system_status, :query, :delete, :retrieve, :describe]
20
+ body = {
21
+ 'wsdl:Objects' => {
22
+ 'wsdl:EmailAddress' => 'wuuuuut@tester.com',
23
+ 'wsdl:Attributes' => [
24
+ {"wsdl:Name" => "First Name", "wsdl:Value" => "Wuuuuut"},
25
+ {"wsdl:Name" => "Last Name", "wsdl:Value" => "Teeeester"},
26
+ {"wsdl:Name" => "Company", "wsdl:Value" => "Northern Trail Outfitters"}
27
+ ],
28
+ 'wsdl:Lists' => {
29
+ 'wsdl:ID' => '251',
30
+ 'wsdl:Status' => 'Active'
31
+ },
32
+ :attributes! => {
33
+ 'wsdl:Lists' => {'xsi:type' => 'wsdl:SubscriberList'}
34
+ }
35
+
36
+ }
37
+ }
38
+
39
+ header = {
40
+ 'a:Action' => 'Retrieve',
41
+ 'a:MessageID' => 'urn:uuid:99e6822c-5436-4fec-a243-3126c14924f6',
42
+ 'a:ReplyTo' => {
43
+ 'a:Address' => 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous'
44
+ },
45
+ 'VsDebuggerCausalityData' => 'uIDPo5GdUXRQCEBNrqnw0gOEloMAAAAAIAi4IHpPlUiMs1MZ2raBIhJnF/jqJLlAgZIny03R+tgACQAA',
46
+ 'a:To' => 'https://webservice.s4.exacttarget.com/Service.asmx'
47
+ }
48
+ '
49
+ <a:MessageID>urn:uuid:99e6822c-5436-4fec-a243-3126c14924f6</a:MessageID>
50
+ <a:ReplyTo>
51
+ <a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>
52
+ </a:ReplyTo>
53
+ <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPo5GdUXRQCEBNrqnw0gOEloMAAAAAIAi4IHpPlUiMs1MZ2raBIhJnF/jqJLlAgZIny03R+tgACQAA</VsDebuggerCausalityData>
54
+ <a:To s:mustUnderstand="1">https://webservice.s4.exacttarget.com/Service.asmx</a:To>
55
+ <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
56
+ <u:Timestamp u:Id="_0">
57
+ <u:Created>2011-07-27T15:04:42.722Z</u:Created>
58
+ <u:Expires>2011-07-27T15:09:42.722Z</u:Expires>
59
+ </u:Timestamp>
60
+ <o:UsernameToken u:Id="uuid-8e2ca2bf-1581-4d7a-a981-bbdab4639bc3-1">
61
+ <o:Username>username</o:Username>
62
+ <o:Password>password</o:Password>
63
+ </o:UsernameToken>
64
+ </o:Security>'
65
+ #
66
+ body = '<RetrieveRequest>
67
+ <ObjectType>DataFolder</ObjectType>
68
+ <Properties>ID</Properties>
69
+ <Properties>Name</Properties>
70
+ <Properties>ParentFolder.ID</Properties>
71
+ <Properties>ParentFolder.Name</Properties>
72
+ <Filter xsi:type="SimpleFilterPart">
73
+ <Property>Account</Property>
74
+ <SimpleOperator>equals</SimpleOperator>
75
+ <Value>1058484</Value>
76
+ </Filter>
77
+ </RetrieveRequest>'
78
+
79
+ body = '<RetrieveRequest>
80
+ <ObjectType>List</ObjectType>
81
+ <Properties>ListName</Properties>
82
+ <Properties>ID</Properties>
83
+ <Filter xsi:type="SimpleFilterPart">
84
+ <Property>ListName</Property>
85
+ <SimpleOperator>equals</SimpleOperator>
86
+ <Value>All Subscribers</Value>
87
+ </Filter>
88
+ </RetrieveRequest>'
89
+
90
+ body = '<RetrieveRequest>
91
+ <ClientIDs>
92
+ <ID>1058484</ID>
93
+ </ClientIDs>
94
+ <ObjectType>DataFolder</ObjectType>
95
+ <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
+ </RetrieveRequest>'
105
+
106
+ # body = '<RetrieveRequest>
107
+ # <ClientIDs>
108
+ # <ID>1058396</ID>
109
+ # </ClientIDs>
110
+ # <ObjectType>DataFolder</ObjectType>
111
+ # <Properties>ID</Properties>
112
+ # <Properties>Name</Properties>
113
+ # <Properties>ParentFolder.ID</Properties>
114
+ # <Properties>ParentFolder.Name</Properties>
115
+ # <Filter xsi:type="SimpleFilterPart">
116
+ # <Property>ContentType</Property>
117
+ # <SimpleOperator>like</SimpleOperator>
118
+ # <Value>email</Value>
119
+ # </Filter>
120
+ # </RetrieveRequest>'
121
+
122
+ html = CGI.escapeHTML('<center><h2>Way Cool Email</h2></center>')
123
+
124
+ # body = '
125
+ # <Objects xsi:type="Email">
126
+ # <ObjectID xsi:nil="true"/>
127
+ # <Client><ID>1058484</ID></Client>
128
+ # <CategoryID>277</CategoryID>
129
+ # <HTMLBody>'+html+'</HTMLBody>
130
+ # <Subject>Test Subject111</Subject>
131
+ # <EmailType>HTML</EmailType>
132
+ # <IsHTMLPaste>true</IsHTMLPaste>
133
+ # </Objects>'
134
+
135
+ namespaces = {
136
+ 'xmlns:s'=>"http://schemas.xmlsoap.org/soap/envelope/",
137
+ 'xmlns:a'=>"http://schemas.xmlsoap.org/ws/2004/08/addressing",
138
+ 'xmlns:u'=>"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd",
139
+ 'xmlns:xsi'=>"http://www.w3.org/2001/XMLSchema-instance",
140
+ 'xmlns:xsd'=>"http://www.w3.org/2001/XMLSchema",
141
+ 'xmlns:o'=>"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
142
+ }
143
+ #
144
+ response = client.request :retrieve do |soap|
145
+ soap.input = ['RetrieveRequestMsg', { 'xmlns'=>"http://exacttarget.com/wsdl/partnerAPI"}]
146
+ soap.header = header
147
+ soap.env_namespace = :s
148
+ soap.namespaces = namespaces
149
+ soap.body = body
150
+ end
151
+ #
152
+ # response = client.request :create do |soap|
153
+ # soap.input = ['CreateRequest', { 'xmlns'=>"http://exacttarget.com/wsdl/partnerAPI"}]
154
+ # soap.header = header
155
+ # soap.env_namespace = :s
156
+ # soap.namespaces = namespaces
157
+ # soap.body = body
158
+ # end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cupid
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - gazay
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-01 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Send love, not war. This version of cupid can only work with ET SOAP API with s4.
22
+ email:
23
+ - gazay@evilmartians.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - Gemfile
32
+ - README.md
33
+ - Rakefile
34
+ - cupid.gemspec
35
+ - lib/cupid.rb
36
+ - lib/cupid/configuration.rb
37
+ - lib/cupid/methods.rb
38
+ - lib/cupid/methods/email.rb
39
+ - lib/cupid/methods/subscriber.rb
40
+ - lib/cupid/session.rb
41
+ - lib/cupid/version.rb
42
+ - spec/cupid/cupid_spec.rb
43
+ - tmp/dancing_with_ET.rb
44
+ homepage: ""
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ requirements: []
71
+
72
+ rubyforge_project: cupid
73
+ rubygems_version: 1.7.2
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Create, organize and send emails through Exact Target SOAP API
77
+ test_files:
78
+ - spec/cupid/cupid_spec.rb