exacttarget 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
data/exacttarget.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{exacttarget}
8
- s.version = "0.0.1"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matthew Simpson"]
@@ -33,7 +33,7 @@ module ExactTarget
33
33
  }
34
34
  ).body
35
35
  rescue SocketError
36
- puts '[ExactTarget] Error: API request failed (SocketError).'
36
+ raise '[ExactTarget] Error: API request failed (SocketError).'
37
37
  end
38
38
  end
39
39
 
@@ -3,68 +3,88 @@ module ExactTarget
3
3
 
4
4
  public
5
5
 
6
- def email_find_all
7
- email_search
6
+ def email_find_by_id(id, options = {})
7
+ email_find({
8
+ :id => id,
9
+ :body => true
10
+ }.merge(options))
8
11
  end
9
12
 
10
- def email_find_by_id(id)
11
- email_search :id, id, true
13
+ def email_find_by_name(name, options = {})
14
+ email_find({
15
+ :name => name,
16
+ }.merge(options))
12
17
  end
13
18
 
14
- def email_find_by_name(name, get_body = false)
15
- email_search :name, name, get_body
19
+ def email_find_by_subject(subject, options = {})
20
+ email_find({
21
+ :subject => subject,
22
+ }.merge(options))
16
23
  end
17
24
 
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'
25
+ def email_find(options = {})
26
+ @action = 'retrieve'
30
27
  @sub_action = 'all'
31
- @type = ''
32
- @value = ''
28
+ @type = ''
29
+ @value = ''
30
+
31
+ id = options[:id] || false
32
+ name = options[:name] || false
33
+ subject = options[:subject] || false
34
+ start_date = options[:start] || false
35
+ end_date = options[:end] || false
36
+ get_body = options[:body] || false
37
+ list = []
38
+
39
+ format = Proc.new { |date|
40
+ begin
41
+ date if date.instance_of? Date
42
+ Date.strptime(date, '%m/%d/%Y')
43
+ rescue
44
+ raise '[ExactTarget] Error: Invalid date.'
45
+ end
46
+ }
33
47
 
34
- list = []
35
48
  Nokogiri::Slop(send(render(:email)))
36
49
  .exacttarget
37
50
  .system
38
51
  .email
39
52
  .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
53
+ (next if email.emailid.content != id.to_s) if id
54
+ (next if !email.emailname.content.include? name.to_s) if name
55
+ (next if !email.emailsubject.content.include? subject.to_s) if subject
56
+
57
+ date = format.call(email.emailcreateddate.content)
46
58
 
47
- body = (email_get_body(email.emailid.content) if get_body) || nil
59
+ (next if date < format.call(start_date)) if start_date
60
+ (next if date > format.call(end_date)) if end_date
61
+
62
+ body = email_get_body(email.emailid.content) if get_body
48
63
 
49
64
  email.instance_eval do
50
- list << {
65
+ new = {
51
66
  :id => emailid.content,
52
67
  :name => emailname.content,
53
68
  :subject => emailsubject.content,
54
- :category_id => categoryid.content,
55
- :body => body
69
+ :date => email.emailcreateddate.content,
70
+ :category_id => categoryid.content
56
71
  }
72
+
73
+ new[:body] = body if get_body
74
+ list << new
57
75
  end
58
76
  end
59
77
 
60
78
  list
61
79
  end
62
80
 
81
+ private
82
+
63
83
  def email_get_body(id)
64
- @action = 'retrieve'
84
+ @action = 'retrieve'
65
85
  @sub_action = 'htmlemail'
66
- @type = 'emailid'
67
- @value = id.to_s
86
+ @type = 'emailid'
87
+ @value = id.to_s
68
88
 
69
89
  begin
70
90
  Nokogiri::XML(send(render(:email)))
@@ -75,5 +95,4 @@ module ExactTarget
75
95
  end
76
96
 
77
97
  end
78
-
79
98
  end
@@ -1,22 +1,20 @@
1
1
  <system>
2
+
2
3
  <system_name>email</system_name>
3
4
  <action><%= @action %></action>
4
5
  <sub_action><%= @sub_action %></sub_action>
6
+
5
7
  <% if @action == 'retrieve' %>
6
8
  <search_type><%= @type %></search_type>
7
9
  <search_value><%= @value %></search_value>
8
10
  <search_value2></search_value2>
9
11
  <% 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>
12
+ <daterange></daterange>
16
13
  <% else %>
17
14
  <search_value3></search_value3>
18
15
  <% end %>
19
16
  <% end %>
17
+
20
18
  <% if @action == 'add' %>
21
19
  <% if @sub_action == 'HTMLPaste' %>
22
20
  <category></category>
@@ -32,4 +30,5 @@
32
30
  <email_body><![ CDATA[<%= @body %>]]></email_body>
33
31
  <% end %>
34
32
  <% end %>
33
+
35
34
  </system>
data/lib/exacttarget.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  begin
3
3
  require 'nokogiri'
4
4
  rescue LoadError
5
- puts '[ExactTarget] Error: Nokogiri is missing, run "bundle install".'
5
+ raise '[ExactTarget] Error: Nokogiri is missing, run "bundle install".'
6
6
  end
7
7
 
8
8
  # Standard:
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 0
8
7
  - 1
9
- version: 0.0.1
8
+ - 0
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matthew Simpson
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
125
  requirements:
126
126
  - - ">="
127
127
  - !ruby/object:Gem::Version
128
- hash: 2723099065645774218
128
+ hash: -1942609719604810864
129
129
  segments:
130
130
  - 0
131
131
  version: "0"