exacttarget 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +22 -0
- data/VERSION +1 -1
- data/exacttarget.gemspec +65 -0
- data/lib/exacttarget.rb +14 -4
- data/lib/exacttarget/client.rb +41 -0
- data/lib/exacttarget/email.rb +79 -0
- data/lib/exacttarget/templates/email.xml.erb +35 -0
- data/lib/exacttarget/templates/main.xml.erb +8 -0
- metadata +14 -8
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.6.0)
|
6
|
+
bundler (~> 1.0.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
nokogiri (1.4.4)
|
10
|
+
rake (0.8.7)
|
11
|
+
rcov (0.9.9)
|
12
|
+
shoulda (2.11.3)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
bundler (~> 1.0.0)
|
19
|
+
jeweler (~> 1.6.0)
|
20
|
+
nokogiri (>= 1.4.4)
|
21
|
+
rcov
|
22
|
+
shoulda
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/exacttarget.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
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{exacttarget}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Matthew Simpson"]
|
12
|
+
s.date = %q{2011-05-08}
|
13
|
+
s.description = %q{ExactTarget is a client system for communicating with the ExactTarget email system. The client supports the most up-to-date XML API and is capable of uploading email pastes, images and retrieving lists of subscribers, emails and more.}
|
14
|
+
s.email = %q{matt.simpson@alextom.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"exacttarget.gemspec",
|
28
|
+
"lib/exacttarget.rb",
|
29
|
+
"lib/exacttarget/client.rb",
|
30
|
+
"lib/exacttarget/email.rb",
|
31
|
+
"lib/exacttarget/templates/email.xml.erb",
|
32
|
+
"lib/exacttarget/templates/main.xml.erb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/msimpson/exacttarget}
|
35
|
+
s.licenses = ["MIT"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.7}
|
38
|
+
s.summary = %q{An XML API client for the ExactTarget email system.}
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
47
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
48
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<nokogiri>, [">= 1.4.4"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
52
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
53
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
54
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
55
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
59
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
61
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
62
|
+
s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
data/lib/exacttarget.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# Nokogiri is required for XML parsing:
|
2
|
+
begin
|
3
|
+
require 'nokogiri'
|
4
|
+
rescue LoadError
|
5
|
+
puts '[ExactTarget] Error: Nokogiri is missing, run "bundle install".'
|
5
6
|
end
|
7
|
+
|
8
|
+
# Standard:
|
9
|
+
require 'net/https'
|
10
|
+
require 'uri'
|
11
|
+
require 'erb'
|
12
|
+
|
13
|
+
# Library:
|
14
|
+
require 'exacttarget/client'
|
15
|
+
require 'exacttarget/email'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ExactTarget
|
2
|
+
class Client
|
3
|
+
|
4
|
+
attr_reader :username, :password
|
5
|
+
|
6
|
+
public
|
7
|
+
|
8
|
+
def initialize(username, password)
|
9
|
+
@username = username
|
10
|
+
@password = password
|
11
|
+
@uri = URI.parse('https://api.dc1.exacttarget.com/integrate.asp')
|
12
|
+
@url = Net::HTTP.new(@uri.host, @uri.port)
|
13
|
+
@url.use_ssl = true
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def render(template)
|
19
|
+
path = File.join(File.dirname(__FILE__), "templates/#{template.to_s}.xml.erb")
|
20
|
+
file = File.open(path, 'r').read
|
21
|
+
ERB.new(file, 0, '<>').result(binding)
|
22
|
+
end
|
23
|
+
|
24
|
+
def send(xml)
|
25
|
+
@system = xml
|
26
|
+
post = 'qf=xml&xml=' + URI.escape(render(:main))
|
27
|
+
|
28
|
+
begin
|
29
|
+
@url.post(@uri.path, post,
|
30
|
+
{
|
31
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
32
|
+
'Content-length' => post.length.to_s
|
33
|
+
}
|
34
|
+
).body
|
35
|
+
rescue SocketError
|
36
|
+
puts '[ExactTarget] Error: API request failed (SocketError).'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module ExactTarget
|
2
|
+
class Client
|
3
|
+
|
4
|
+
public
|
5
|
+
|
6
|
+
def email_find_all
|
7
|
+
email_search
|
8
|
+
end
|
9
|
+
|
10
|
+
def email_find_by_id(id)
|
11
|
+
email_search :id, id, true
|
12
|
+
end
|
13
|
+
|
14
|
+
def email_find_by_name(name, get_body = false)
|
15
|
+
email_search :name, name, get_body
|
16
|
+
end
|
17
|
+
|
18
|
+
def email_find_by_subject(subject, get_body = false)
|
19
|
+
email_search :subject, subject, get_body
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def email_search(filter = :all, value = '', get_body = false)
|
25
|
+
# ExactTarget does not return more than one email
|
26
|
+
# for any search besides all. So we must grab the
|
27
|
+
# entire list and search here (slow, but necessary).
|
28
|
+
|
29
|
+
@action = 'retrieve'
|
30
|
+
@sub_action = 'all'
|
31
|
+
@type = ''
|
32
|
+
@value = ''
|
33
|
+
|
34
|
+
list = []
|
35
|
+
Nokogiri::Slop(send(render(:email)))
|
36
|
+
.exacttarget
|
37
|
+
.system
|
38
|
+
.email
|
39
|
+
.emaillist.each do |email|
|
40
|
+
case filter
|
41
|
+
when :id
|
42
|
+
next if !email.emailid.content == value.to_s
|
43
|
+
when :name, :subject
|
44
|
+
next if !email.send('email' + filter.to_s).content.include? value.to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
body = (email_get_body(email.emailid.content) if get_body) || nil
|
48
|
+
|
49
|
+
email.instance_eval do
|
50
|
+
list << {
|
51
|
+
:id => emailid.content,
|
52
|
+
:name => emailname.content,
|
53
|
+
:subject => emailsubject.content,
|
54
|
+
:category_id => categoryid.content,
|
55
|
+
:body => body
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
list
|
61
|
+
end
|
62
|
+
|
63
|
+
def email_get_body(id)
|
64
|
+
@action = 'retrieve'
|
65
|
+
@sub_action = 'htmlemail'
|
66
|
+
@type = 'emailid'
|
67
|
+
@value = id.to_s
|
68
|
+
|
69
|
+
begin
|
70
|
+
Nokogiri::XML(send(render(:email)))
|
71
|
+
.xpath('//htmlbody').text
|
72
|
+
rescue
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<system>
|
2
|
+
<system_name>email</system_name>
|
3
|
+
<action><%= @action %></action>
|
4
|
+
<sub_action><%= @sub_action %></sub_action>
|
5
|
+
<% if @action == 'retrieve' %>
|
6
|
+
<search_type><%= @type %></search_type>
|
7
|
+
<search_value><%= @value %></search_value>
|
8
|
+
<search_value2></search_value2>
|
9
|
+
<% if @sub_action == 'all' %>
|
10
|
+
<daterange>
|
11
|
+
<% if @type == 'daterange' || @type == 'emailnameanddaterange' %>
|
12
|
+
<startdate><%= @start_date %></startdate>
|
13
|
+
<enddate><%= @end_date %></enddate>
|
14
|
+
<% end %>
|
15
|
+
</daterange>
|
16
|
+
<% else %>
|
17
|
+
<search_value3></search_value3>
|
18
|
+
<% end %>
|
19
|
+
<% end %>
|
20
|
+
<% if @action == 'add' %>
|
21
|
+
<% if @sub_action == 'HTMLPaste' %>
|
22
|
+
<category></category>
|
23
|
+
<email_name><%= @name %></email_name>
|
24
|
+
<email_subject><%= @subject %></email_subject>
|
25
|
+
<% else %>
|
26
|
+
<search_type>emailid</search_type>
|
27
|
+
<search_value><%= @id %></search_value>
|
28
|
+
<% end %>
|
29
|
+
<% if @method == 'file' %>
|
30
|
+
<file_name><%= @file_name %></file_name>
|
31
|
+
<% else %>
|
32
|
+
<email_body><![ CDATA[<%= @body %>]]></email_body>
|
33
|
+
<% end %>
|
34
|
+
<% end %>
|
35
|
+
</system>
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Matthew Simpson
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-05-
|
17
|
+
date: 2011-05-08 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -74,17 +74,17 @@ dependencies:
|
|
74
74
|
prerelease: false
|
75
75
|
version_requirements: *id004
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
|
-
name:
|
77
|
+
name: nokogiri
|
78
78
|
requirement: &id005 !ruby/object:Gem::Requirement
|
79
79
|
none: false
|
80
80
|
requirements:
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
segments:
|
84
|
-
-
|
85
|
-
-
|
84
|
+
- 1
|
85
|
+
- 4
|
86
86
|
- 4
|
87
|
-
version:
|
87
|
+
version: 1.4.4
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: *id005
|
@@ -100,11 +100,17 @@ extra_rdoc_files:
|
|
100
100
|
files:
|
101
101
|
- .document
|
102
102
|
- Gemfile
|
103
|
+
- Gemfile.lock
|
103
104
|
- LICENSE.txt
|
104
105
|
- README.rdoc
|
105
106
|
- Rakefile
|
106
107
|
- VERSION
|
108
|
+
- exacttarget.gemspec
|
107
109
|
- lib/exacttarget.rb
|
110
|
+
- lib/exacttarget/client.rb
|
111
|
+
- lib/exacttarget/email.rb
|
112
|
+
- lib/exacttarget/templates/email.xml.erb
|
113
|
+
- lib/exacttarget/templates/main.xml.erb
|
108
114
|
has_rdoc: true
|
109
115
|
homepage: http://github.com/msimpson/exacttarget
|
110
116
|
licenses:
|
@@ -119,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
125
|
requirements:
|
120
126
|
- - ">="
|
121
127
|
- !ruby/object:Gem::Version
|
122
|
-
hash:
|
128
|
+
hash: 2723099065645774218
|
123
129
|
segments:
|
124
130
|
- 0
|
125
131
|
version: "0"
|