exactish_target 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.8.7@exactish_target
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ gem "builder", "3.0.0"
3
+
4
+ # Add dependencies to develop your gem here.
5
+ # Include everything needed to run rake, tests, features, etc.
6
+ group :development do
7
+ gem "shoulda", ">= 0"
8
+ gem "rspec", ">= 1.3.0"
9
+ gem "rr", ">= 0.10.11"
10
+ gem "sham_rack", ">= 1.3.0"
11
+ gem "sinatra", ">= 0.9.4"
12
+ gem "jeweler", ">= 1.5.2"
13
+ end
@@ -0,0 +1,29 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ builder (3.0.0)
5
+ git (1.2.5)
6
+ jeweler (1.5.2)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rack (1.0.1)
11
+ rake (0.8.7)
12
+ rr (0.10.11)
13
+ rspec (1.3.0)
14
+ sham_rack (1.3.0)
15
+ shoulda (2.11.3)
16
+ sinatra (0.9.4)
17
+ rack (>= 0.9.1)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ builder (= 3.0.0)
24
+ jeweler (>= 1.5.2)
25
+ rr (>= 0.10.11)
26
+ rspec (>= 1.3.0)
27
+ sham_rack (>= 1.3.0)
28
+ shoulda
29
+ sinatra (>= 0.9.4)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Lonely Planet
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ exactish_target
2
+ ============
3
+
4
+ Super simple interaction with [Exact Target](http://www.exacttarget.com/)
5
+
6
+ This was thrown together for use at [Lonely Planet](http://www.lonelyplanet.com). It fits our (very basic) needs, and not much else. At the moment this is just...
7
+
8
+ * creating subscribers
9
+
10
+ And that's it.
11
+
12
+
13
+ Contributing to exactish_target
14
+ ----------------------------
15
+
16
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
17
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
18
+ * Fork the project
19
+ * Start a feature/bugfix branch
20
+ * Commit and push until you are happy with your contribution
21
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
22
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
23
+
24
+ Copyright
25
+ ---------
26
+
27
+ Copyright (c) 2011 Lonely Planet. See LICENSE.txt for
28
+ further details.
29
+
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "exactish_target"
16
+ gem.homepage = "https://github.com/lonelyplanet/exactish_target"
17
+ gem.summary = %Q{Exact Target client}
18
+ gem.description = %Q{Very simple Exact Target SOAP client. Only supports subscriber creation at this point}
19
+ gem.email = "daniel.vydra@lonelyplanet.com.au"
20
+ gem.authors = ["Lonely Planet"]
21
+
22
+ end
23
+ Jeweler::RubygemsDotOrgTasks.new
24
+
25
+ require 'spec/rake/spectask'
26
+ desc "Run all specs in spec directory"
27
+ Spec::Rake::SpecTask.new(:spec) do |t|
28
+ t.spec_files = FileList['spec/**/*_spec.rb']
29
+ end
30
+
31
+ task :default => :spec
32
+
33
+ require 'rake/rdoctask'
34
+ Rake::RDocTask.new do |rdoc|
35
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
36
+
37
+ rdoc.rdoc_dir = 'rdoc'
38
+ rdoc.title = "exact_target #{version}"
39
+ rdoc.rdoc_files.include('README*')
40
+ rdoc.rdoc_files.include('lib/**/*.rb')
41
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.2
@@ -0,0 +1,78 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{exactish_target}
8
+ s.version = "0.2.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Lonely Planet"]
12
+ s.date = %q{2011-07-12}
13
+ s.description = %q{Very simple Exact Target SOAP client. Only supports subscriber creation at this point}
14
+ s.email = %q{daniel.vydra@lonelyplanet.com.au}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".rvmrc",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "exactish_target.gemspec",
28
+ "lib/exactish_target.rb",
29
+ "rdoc/ExactishTarget.html",
30
+ "rdoc/created.rid",
31
+ "rdoc/index.html",
32
+ "rdoc/lib/exactish_target_rb.html",
33
+ "rdoc/rdoc.css",
34
+ "spec/exact_target_spec.rb",
35
+ "spec/spec_helper.rb",
36
+ "spec/support/fake_exactish_target/app.rb"
37
+ ]
38
+ s.homepage = %q{https://github.com/lonelyplanet/exactish_target}
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.4.2}
41
+ s.summary = %q{Exact Target client}
42
+ s.test_files = [
43
+ "spec/exact_target_spec.rb",
44
+ "spec/spec_helper.rb",
45
+ "spec/support/fake_exactish_target/app.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ s.add_runtime_dependency(%q<builder>, ["= 3.0.0"])
53
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
55
+ s.add_development_dependency(%q<rr>, [">= 0.10.11"])
56
+ s.add_development_dependency(%q<sham_rack>, [">= 1.3.0"])
57
+ s.add_development_dependency(%q<sinatra>, [">= 0.9.4"])
58
+ s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
59
+ else
60
+ s.add_dependency(%q<builder>, ["= 3.0.0"])
61
+ s.add_dependency(%q<shoulda>, [">= 0"])
62
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
63
+ s.add_dependency(%q<rr>, [">= 0.10.11"])
64
+ s.add_dependency(%q<sham_rack>, [">= 1.3.0"])
65
+ s.add_dependency(%q<sinatra>, [">= 0.9.4"])
66
+ s.add_dependency(%q<jeweler>, [">= 1.5.2"])
67
+ end
68
+ else
69
+ s.add_dependency(%q<builder>, ["= 3.0.0"])
70
+ s.add_dependency(%q<shoulda>, [">= 0"])
71
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
72
+ s.add_dependency(%q<rr>, [">= 0.10.11"])
73
+ s.add_dependency(%q<sham_rack>, [">= 1.3.0"])
74
+ s.add_dependency(%q<sinatra>, [">= 0.9.4"])
75
+ s.add_dependency(%q<jeweler>, [">= 1.5.2"])
76
+ end
77
+ end
78
+
@@ -0,0 +1,83 @@
1
+ require "net/https"
2
+ require "uri"
3
+ require "builder/xchar"
4
+
5
+ class ExactishTarget
6
+
7
+ attr_reader :username
8
+ attr_reader :password
9
+ attr_reader :end_point
10
+
11
+ # "https://webservice.s4.exacttarget.com/Service.asmx"
12
+
13
+ def initialize(username, password, end_point)
14
+ @username = username
15
+ @password = password
16
+ @end_point = end_point
17
+ end
18
+
19
+ def uri
20
+ @uri ||= URI.parse(end_point)
21
+ end
22
+
23
+ def create_http
24
+ http = Net::HTTP.new(uri.host, uri.port)
25
+ http.open_timeout = 3 # in seconds
26
+ http.read_timeout = 3 # in seconds
27
+ http.use_ssl = true
28
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
29
+ http
30
+ end
31
+
32
+ def create_request(body)
33
+ request = Net::HTTP::Post.new(uri.request_uri)
34
+ request.add_field "SOAPAction", "Create"
35
+ request.add_field "Content-Type", "text/xml; charset=utf-8"
36
+ request.body = body
37
+ request
38
+ end
39
+
40
+ def create_subscriber(email, country, source)
41
+ http = create_http
42
+ request = create_request(create_subscriber_request_xml(email, country, source))
43
+ begin
44
+ response = http.request(request)
45
+ status_code = $1 if response.body =~ %r{<StatusCode>\s*([^<]+)\s*</StatusCode>}
46
+ unless status_code
47
+ raise StandardError, "Invalid response from Exact Target\n#{response.body}"
48
+ else
49
+ unless status_code.downcase == "ok"
50
+ status_message = $1 if response.body =~ %r{<StatusMessage>\s*([^<]+)\s*</StatusMessage>}
51
+ raise StandardError, "Exact Target Error: #{status_message || "Unknown error"}"
52
+ end
53
+ end
54
+ rescue Exception => e
55
+ raise StandardError, "Subscription request for email: \"#{email}\", country: \"#{country}\", source: \"#{source}\" failed. Newsletter subscription has not been created.\nException: #{e.inspect}"
56
+ end
57
+ end
58
+
59
+ def create_subscriber_request_xml(email, country, source)
60
+ <<-XML.strip
61
+ <?xml version="1.0" encoding="utf-8" ?>
62
+ <env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
63
+ <env:Header><n1:Security env:mustUnderstand="0" xmlns:n1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><n1:UsernameToken><n1:Username>#{username}</n1:Username><n1:Password>#{password}</n1:Password></n1:UsernameToken></n1:Security></env:Header>
64
+ <env:Body>
65
+ <n2:CreateRequest xmlns:n2="http://exacttarget.com/wsdl/partnerAPI">
66
+ <n2:Options xsi:type="n2:CreateOptions" xsi:nil="true"></n2:Options>
67
+ <n2:Objects xsi:type="n2:Subscriber">
68
+ <n2:EmailAddress>#{email.to_xs}</n2:EmailAddress>
69
+ <n2:CustomerKey>#{email.to_xs}</n2:CustomerKey>
70
+ <n2:Attributes><n2:Name>Country</n2:Name><n2:Value>#{country.to_xs}</n2:Value></n2:Attributes>
71
+ <n2:Attributes><n2:Name>Source</n2:Name><n2:Value>#{source.to_xs}</n2:Value></n2:Attributes>
72
+ <n2:Attributes><n2:Name>Lonely Planet Newsletters</n2:Name><n2:Value>true</n2:Value></n2:Attributes>
73
+ <n2:Attributes><n2:Name>Lonely Planet Marketing</n2:Name><n2:Value>true</n2:Value></n2:Attributes>
74
+ </n2:Objects>
75
+ </n2:CreateRequest>
76
+ </env:Body>
77
+ </env:Envelope>
78
+ XML
79
+ end
80
+
81
+ end
82
+
83
+
@@ -0,0 +1,450 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
7
+
8
+ <title>Class: ExactishTarget</title>
9
+
10
+ <link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
11
+
12
+ <script src="./js/jquery.js" type="text/javascript"
13
+ charset="utf-8"></script>
14
+ <script src="./js/thickbox-compressed.js" type="text/javascript"
15
+ charset="utf-8"></script>
16
+ <script src="./js/quicksearch.js" type="text/javascript"
17
+ charset="utf-8"></script>
18
+ <script src="./js/darkfish.js" type="text/javascript"
19
+ charset="utf-8"></script>
20
+
21
+ </head>
22
+ <body class="class">
23
+
24
+ <div id="metadata">
25
+ <div id="home-metadata">
26
+ <div id="home-section" class="section">
27
+ <h3 class="section-header">
28
+ <a href="./index.html">Home</a>
29
+ <a href="./index.html#classes">Classes</a>
30
+ <a href="./index.html#methods">Methods</a>
31
+ </h3>
32
+ </div>
33
+ </div>
34
+
35
+ <div id="file-metadata">
36
+ <div id="file-list-section" class="section">
37
+ <h3 class="section-header">In Files</h3>
38
+ <div class="section-body">
39
+ <ul>
40
+
41
+ <li><a href="./lib/exactish_target_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
42
+ class="thickbox" title="lib/exactish_target.rb">lib/exactish_target.rb</a></li>
43
+
44
+ </ul>
45
+ </div>
46
+ </div>
47
+
48
+
49
+ </div>
50
+
51
+ <div id="class-metadata">
52
+
53
+ <!-- Parent Class -->
54
+
55
+ <div id="parent-class-section" class="section">
56
+ <h3 class="section-header">Parent</h3>
57
+
58
+ <p class="link">Object</p>
59
+
60
+ </div>
61
+
62
+
63
+ <!-- Namespace Contents -->
64
+
65
+
66
+ <!-- Method Quickref -->
67
+
68
+ <div id="method-list-section" class="section">
69
+ <h3 class="section-header">Methods</h3>
70
+ <ul class="link-list">
71
+
72
+ <li><a href="#method-c-new">::new</a></li>
73
+
74
+ <li><a href="#method-i-create_http">#create_http</a></li>
75
+
76
+ <li><a href="#method-i-create_request">#create_request</a></li>
77
+
78
+ <li><a href="#method-i-create_subscriber">#create_subscriber</a></li>
79
+
80
+ <li><a href="#method-i-create_subscriber_request_xml">#create_subscriber_request_xml</a></li>
81
+
82
+ <li><a href="#method-i-uri">#uri</a></li>
83
+
84
+ </ul>
85
+ </div>
86
+
87
+
88
+ <!-- Included Modules -->
89
+
90
+ </div>
91
+
92
+ <div id="project-metadata">
93
+
94
+
95
+
96
+ <div id="classindex-section" class="section project-section">
97
+ <h3 class="section-header">Class Index
98
+ <span class="search-toggle"><img src="./images/find.png"
99
+ height="16" width="16" alt="[+]"
100
+ title="show/hide quicksearch" /></span></h3>
101
+ <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
102
+ <fieldset>
103
+ <legend>Quicksearch</legend>
104
+ <input type="text" name="quicksearch" value=""
105
+ class="quicksearch-field" />
106
+ </fieldset>
107
+ </form>
108
+
109
+ <ul class="link-list">
110
+
111
+ <li><a href="./ExactishTarget.html">ExactishTarget</a></li>
112
+
113
+ </ul>
114
+ <div id="no-class-search-results" style="display: none;">No matching classes.</div>
115
+ </div>
116
+
117
+
118
+ </div>
119
+ </div>
120
+
121
+ <div id="documentation">
122
+ <h1 class="class">ExactishTarget</h1>
123
+
124
+ <div id="description">
125
+
126
+ </div>
127
+
128
+ <!-- Constants -->
129
+
130
+
131
+ <!-- Attributes -->
132
+
133
+ <div id="attribute-method-details" class="method-section section">
134
+ <h3 class="section-header">Attributes</h3>
135
+
136
+
137
+ <div id="username-attribute-method" class="method-detail">
138
+ <a name="username"></a>
139
+
140
+ <div class="method-heading attribute-method-heading">
141
+ <span class="method-name">username</span><span
142
+ class="attribute-access-type">[R]</span>
143
+ </div>
144
+
145
+ <div class="method-description">
146
+
147
+
148
+
149
+ </div>
150
+ </div>
151
+
152
+ <div id="password-attribute-method" class="method-detail">
153
+ <a name="password"></a>
154
+
155
+ <div class="method-heading attribute-method-heading">
156
+ <span class="method-name">password</span><span
157
+ class="attribute-access-type">[R]</span>
158
+ </div>
159
+
160
+ <div class="method-description">
161
+
162
+
163
+
164
+ </div>
165
+ </div>
166
+
167
+ <div id="end-point-attribute-method" class="method-detail">
168
+ <a name="end_point"></a>
169
+
170
+ <div class="method-heading attribute-method-heading">
171
+ <span class="method-name">end_point</span><span
172
+ class="attribute-access-type">[R]</span>
173
+ </div>
174
+
175
+ <div class="method-description">
176
+
177
+
178
+
179
+ </div>
180
+ </div>
181
+
182
+ </div>
183
+
184
+
185
+ <!-- Methods -->
186
+
187
+ <div id="public-class-method-details" class="method-section section">
188
+ <h3 class="section-header">Public Class Methods</h3>
189
+
190
+
191
+ <div id="new-method" class="method-detail ">
192
+ <a name="method-c-new"></a>
193
+
194
+ <div class="method-heading">
195
+
196
+ <span class="method-name">new</span><span
197
+ class="method-args">(username, password, end_point)</span>
198
+ <span class="method-click-advice">click to toggle source</span>
199
+
200
+ </div>
201
+
202
+ <div class="method-description">
203
+
204
+ <p>
205
+ &#8220;<a
206
+ href="https://webservice.s4.exacttarget.com/Service.asmx">webservice.s4.exacttarget.com/Service.asmx</a>&#8220;
207
+ </p>
208
+
209
+
210
+
211
+ <div class="method-source-code"
212
+ id="new-source">
213
+ <pre>
214
+ <span class="ruby-comment cmt"># File lib/exactish_target.rb, line 13</span>
215
+ 13: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">username</span>, <span class="ruby-identifier">password</span>, <span class="ruby-identifier">end_point</span>)
216
+ 14: <span class="ruby-ivar">@username</span> = <span class="ruby-identifier">username</span>
217
+ 15: <span class="ruby-ivar">@password</span> = <span class="ruby-identifier">password</span>
218
+ 16: <span class="ruby-ivar">@end_point</span> = <span class="ruby-identifier">end_point</span>
219
+ 17: <span class="ruby-keyword kw">end</span></pre>
220
+ </div>
221
+
222
+ </div>
223
+
224
+
225
+
226
+
227
+ </div>
228
+
229
+
230
+ </div>
231
+
232
+ <div id="public-instance-method-details" class="method-section section">
233
+ <h3 class="section-header">Public Instance Methods</h3>
234
+
235
+
236
+ <div id="create-http-method" class="method-detail ">
237
+ <a name="method-i-create_http"></a>
238
+
239
+ <div class="method-heading">
240
+
241
+ <span class="method-name">create_http</span><span
242
+ class="method-args">()</span>
243
+ <span class="method-click-advice">click to toggle source</span>
244
+
245
+ </div>
246
+
247
+ <div class="method-description">
248
+
249
+
250
+
251
+
252
+
253
+ <div class="method-source-code"
254
+ id="create-http-source">
255
+ <pre>
256
+ <span class="ruby-comment cmt"># File lib/exactish_target.rb, line 23</span>
257
+ 23: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_http</span>
258
+ 24: <span class="ruby-identifier">http</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">host</span>, <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">port</span>)
259
+ 25: <span class="ruby-identifier">http</span>.<span class="ruby-identifier">open_timeout</span> = <span class="ruby-value">3</span> <span class="ruby-comment cmt"># in seconds</span>
260
+ 26: <span class="ruby-identifier">http</span>.<span class="ruby-identifier">read_timeout</span> = <span class="ruby-value">3</span> <span class="ruby-comment cmt"># in seconds</span>
261
+ 27: <span class="ruby-identifier">http</span>.<span class="ruby-identifier">use_ssl</span> = <span class="ruby-keyword kw">true</span>
262
+ 28: <span class="ruby-identifier">http</span>.<span class="ruby-identifier">verify_mode</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">SSL</span><span class="ruby-operator">::</span><span class="ruby-constant">VERIFY_NONE</span>
263
+ 29: <span class="ruby-identifier">http</span>
264
+ 30: <span class="ruby-keyword kw">end</span></pre>
265
+ </div>
266
+
267
+ </div>
268
+
269
+
270
+
271
+
272
+ </div>
273
+
274
+
275
+ <div id="create-request-method" class="method-detail ">
276
+ <a name="method-i-create_request"></a>
277
+
278
+ <div class="method-heading">
279
+
280
+ <span class="method-name">create_request</span><span
281
+ class="method-args">(body)</span>
282
+ <span class="method-click-advice">click to toggle source</span>
283
+
284
+ </div>
285
+
286
+ <div class="method-description">
287
+
288
+
289
+
290
+
291
+
292
+ <div class="method-source-code"
293
+ id="create-request-source">
294
+ <pre>
295
+ <span class="ruby-comment cmt"># File lib/exactish_target.rb, line 32</span>
296
+ 32: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_request</span>(<span class="ruby-identifier">body</span>)
297
+ 33: <span class="ruby-identifier">request</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span><span class="ruby-operator">::</span><span class="ruby-constant">Post</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">request_uri</span>)
298
+ 34: <span class="ruby-identifier">request</span>.<span class="ruby-identifier">add_field</span> <span class="ruby-value str">&quot;SOAPAction&quot;</span>, <span class="ruby-value str">&quot;Create&quot;</span>
299
+ 35: <span class="ruby-identifier">request</span>.<span class="ruby-identifier">add_field</span> <span class="ruby-value str">&quot;Content-Type&quot;</span>, <span class="ruby-value str">&quot;text/xml; charset=utf-8&quot;</span>
300
+ 36: <span class="ruby-identifier">request</span>.<span class="ruby-identifier">body</span> = <span class="ruby-identifier">body</span>
301
+ 37: <span class="ruby-identifier">request</span>
302
+ 38: <span class="ruby-keyword kw">end</span></pre>
303
+ </div>
304
+
305
+ </div>
306
+
307
+
308
+
309
+
310
+ </div>
311
+
312
+
313
+ <div id="create-subscriber-method" class="method-detail ">
314
+ <a name="method-i-create_subscriber"></a>
315
+
316
+ <div class="method-heading">
317
+
318
+ <span class="method-name">create_subscriber</span><span
319
+ class="method-args">(email, country, source)</span>
320
+ <span class="method-click-advice">click to toggle source</span>
321
+
322
+ </div>
323
+
324
+ <div class="method-description">
325
+
326
+
327
+
328
+
329
+
330
+ <div class="method-source-code"
331
+ id="create-subscriber-source">
332
+ <pre>
333
+ <span class="ruby-comment cmt"># File lib/exactish_target.rb, line 40</span>
334
+ 40: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_subscriber</span>(<span class="ruby-identifier">email</span>, <span class="ruby-identifier">country</span>, <span class="ruby-identifier">source</span>)
335
+ 41: <span class="ruby-identifier">http</span> = <span class="ruby-identifier">create_http</span>
336
+ 42: <span class="ruby-identifier">request</span> = <span class="ruby-identifier">create_request</span>(<span class="ruby-identifier">create_subscriber_request_xml</span>(<span class="ruby-identifier">email</span>, <span class="ruby-identifier">country</span>, <span class="ruby-identifier">source</span>))
337
+ 43: <span class="ruby-keyword kw">begin</span>
338
+ 44: <span class="ruby-identifier">response</span> = <span class="ruby-identifier">http</span>.<span class="ruby-identifier">request</span>(<span class="ruby-identifier">request</span>)
339
+ 45: <span class="ruby-identifier">status_code</span> = <span class="ruby-node">$1</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">%{&lt;StatusCode&gt;\s*([^&lt;]+)\s*&lt;/StatusCode&gt;}</span>
340
+ 46: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">status_code</span>
341
+ 47: <span class="ruby-identifier">raise</span> <span class="ruby-constant">StandardError</span>, <span class="ruby-node">&quot;Invalid response from Exact Target\n#{response.body}&quot;</span>
342
+ 48: <span class="ruby-keyword kw">else</span>
343
+ 49: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">status_code</span>.<span class="ruby-identifier">downcase</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;ok&quot;</span>
344
+ 50: <span class="ruby-identifier">status_message</span> = <span class="ruby-node">$1</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">%{&lt;StatusMessage&gt;\s*([^&lt;]+)\s*&lt;/StatusMessage&gt;}</span>
345
+ 51: <span class="ruby-identifier">raise</span> <span class="ruby-constant">StandardError</span>, <span class="ruby-node">&quot;Exact Target Error: #{status_message || &quot;Unknown error&quot;}&quot;</span>
346
+ 52: <span class="ruby-keyword kw">end</span>
347
+ 53: <span class="ruby-keyword kw">end</span>
348
+ 54: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
349
+ 55: <span class="ruby-identifier">raise</span> <span class="ruby-constant">StandardError</span>, <span class="ruby-node">&quot;Subscription request for email: \&quot;#{email}\&quot;, country: \&quot;#{country}\&quot;, source: \&quot;#{source}\&quot; failed. Newsletter subscription has not been created.\nException: #{e.inspect}&quot;</span>
350
+ 56: <span class="ruby-keyword kw">end</span>
351
+ 57: <span class="ruby-keyword kw">end</span></pre>
352
+ </div>
353
+
354
+ </div>
355
+
356
+
357
+
358
+
359
+ </div>
360
+
361
+
362
+ <div id="create-subscriber-request-xml-method" class="method-detail ">
363
+ <a name="method-i-create_subscriber_request_xml"></a>
364
+
365
+ <div class="method-heading">
366
+
367
+ <span class="method-name">create_subscriber_request_xml</span><span
368
+ class="method-args">(email, country, source)</span>
369
+ <span class="method-click-advice">click to toggle source</span>
370
+
371
+ </div>
372
+
373
+ <div class="method-description">
374
+
375
+
376
+
377
+
378
+
379
+ <div class="method-source-code"
380
+ id="create-subscriber-request-xml-source">
381
+ <pre>
382
+ <span class="ruby-comment cmt"># File lib/exactish_target.rb, line 59</span>
383
+ 59: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_subscriber_request_xml</span>(<span class="ruby-identifier">email</span>, <span class="ruby-identifier">country</span>, <span class="ruby-identifier">source</span>)
384
+ 60: <span class="ruby-value str"> &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt; &lt;env:Envelope xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:env=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt; &lt;env:Header&gt;&lt;n1:Security env:mustUnderstand=&quot;0&quot; xmlns:n1=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd&quot;&gt;&lt;n1:UsernameToken&gt;&lt;n1:Username&gt;#{username}&lt;/n1:Username&gt;&lt;n1:Password&gt;#{password}&lt;/n1:Password&gt;&lt;/n1:UsernameToken&gt;&lt;/n1:Security&gt;&lt;/env:Header&gt; &lt;env:Body&gt; &lt;n2:CreateRequest xmlns:n2=&quot;http://exacttarget.com/wsdl/partnerAPI&quot;&gt; &lt;n2:Options xsi:type=&quot;n2:CreateOptions&quot; xsi:nil=&quot;true&quot;&gt;&lt;/n2:Options&gt; &lt;n2:Objects xsi:type=&quot;n2:Subscriber&quot;&gt; &lt;n2:EmailAddress&gt;#{email.to_xs}&lt;/n2:EmailAddress&gt; &lt;n2:CustomerKey&gt;#{email.to_xs}&lt;/n2:CustomerKey&gt; &lt;n2:Attributes&gt;&lt;n2:Name&gt;Country&lt;/n2:Name&gt;&lt;n2:Value&gt;#{country.to_xs}&lt;/n2:Value&gt;&lt;/n2:Attributes&gt; &lt;n2:Attributes&gt;&lt;n2:Name&gt;Source&lt;/n2:Name&gt;&lt;n2:Value&gt;#{source.to_xs}&lt;/n2:Value&gt;&lt;/n2:Attributes&gt; &lt;n2:Attributes&gt;&lt;n2:Name&gt;Lonely Planet Newsletters&lt;/n2:Name&gt;&lt;n2:Value&gt;true&lt;/n2:Value&gt;&lt;/n2:Attributes&gt; &lt;n2:Attributes&gt;&lt;n2:Name&gt;Lonely Planet Marketing&lt;/n2:Name&gt;&lt;n2:Value&gt;true&lt;/n2:Value&gt;&lt;/n2:Attributes&gt; &lt;/n2:Objects&gt; &lt;/n2:CreateRequest&gt; &lt;/env:Body&gt; &lt;/env:Envelope&gt;</span>.<span class="ruby-identifier">strip</span>
385
+ 61: <span class="ruby-keyword kw">end</span></pre>
386
+ </div>
387
+
388
+ </div>
389
+
390
+
391
+
392
+
393
+ </div>
394
+
395
+
396
+ <div id="uri-method" class="method-detail ">
397
+ <a name="method-i-uri"></a>
398
+
399
+ <div class="method-heading">
400
+
401
+ <span class="method-name">uri</span><span
402
+ class="method-args">()</span>
403
+ <span class="method-click-advice">click to toggle source</span>
404
+
405
+ </div>
406
+
407
+ <div class="method-description">
408
+
409
+
410
+
411
+
412
+
413
+ <div class="method-source-code"
414
+ id="uri-source">
415
+ <pre>
416
+ <span class="ruby-comment cmt"># File lib/exactish_target.rb, line 19</span>
417
+ 19: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">uri</span>
418
+ 20: <span class="ruby-ivar">@uri</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">end_point</span>)
419
+ 21: <span class="ruby-keyword kw">end</span></pre>
420
+ </div>
421
+
422
+ </div>
423
+
424
+
425
+
426
+
427
+ </div>
428
+
429
+
430
+ </div>
431
+
432
+
433
+ </div>
434
+
435
+
436
+ <div id="rdoc-debugging-section-dump" class="debugging-section">
437
+
438
+ <p>Disabled; run with --debug to generate this.</p>
439
+
440
+ </div>
441
+
442
+ <div id="validator-badges">
443
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
444
+ <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
445
+ Rdoc Generator</a> 1.1.6</small>.</p>
446
+ </div>
447
+
448
+ </body>
449
+ </html>
450
+