exacttarget 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -1,8 +1,8 @@
1
1
  = ExactTarget -- XML API client for the ExactTarget email system
2
2
 
3
- ExactTarget is a client system for communicating with the ExactTarget email system. The client
4
- supports the most up-to-date XML API and is capable of uploading email pastes, images and retrieving
5
- lists of subscribers, emails and more.
3
+ ExactTarget is a library for communicating with the ExactTarget email system. The library
4
+ supports the most up-to-date XML API and is capable of uploading email pastes, images and
5
+ retrieving lists of subscribers, emails and more.
6
6
 
7
7
  == Download and installation
8
8
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
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.1.1"
8
+ s.version = "0.1.2"
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"]
@@ -28,7 +28,9 @@ Gem::Specification.new do |s|
28
28
  "lib/exacttarget.rb",
29
29
  "lib/exacttarget/client.rb",
30
30
  "lib/exacttarget/email.rb",
31
+ "lib/exacttarget/image.rb",
31
32
  "lib/exacttarget/templates/email.xml.erb",
33
+ "lib/exacttarget/templates/image.xml.erb",
32
34
  "lib/exacttarget/templates/main.xml.erb"
33
35
  ]
34
36
  s.homepage = %q{http://github.com/msimpson/exacttarget}
data/lib/exacttarget.rb CHANGED
@@ -7,6 +7,7 @@ end
7
7
 
8
8
  # Standard:
9
9
  require 'net/https'
10
+ require 'net/ftp'
10
11
  require 'uri'
11
12
  require 'erb'
12
13
 
@@ -1,20 +1,63 @@
1
1
  module ExactTarget
2
+ FTP_STANDARD = {
3
+ :location => 'ExactTargetFTP',
4
+ :uri => 'ftp.exacttarget.com',
5
+ :path => '/',
6
+ }
7
+ FTP_ENHANCED = {
8
+ :location => 'ExactTargetEnhancedFTP',
9
+ :uri => 'ftp1.exacttarget.com',
10
+ :path => '/import',
11
+ }
12
+
2
13
  class Client
3
-
4
- attr_reader :username, :password
14
+
15
+ attr_reader :username, :password, :ftp
5
16
 
6
17
  public
7
18
 
8
- def initialize(username, password)
9
- @username = username
10
- @password = password
19
+ def initialize(username, password, ftp_username = 'import', ftp_password = 'import', ftp = FTP_STANDARD)
20
+ @username = username
21
+ @password = password
22
+ @ftp = {
23
+ :username => ftp_username.to_s,
24
+ :password => ftp_password.to_s,
25
+ :handle => Net::FTP.new(ftp[:uri])
26
+ }.merge ftp
27
+
28
+ begin
29
+ @ftp[:handle].login @ftp[:username], @ftp[:password]
30
+ @ftp[:handle].chdir @ftp[:path]
31
+ rescue Net::FTPPermError => msg
32
+ puts '[ExactTarget] Error: FTP access failed.'
33
+ raise msg
34
+ end
35
+
11
36
  @uri = URI.parse('https://api.dc1.exacttarget.com/integrate.asp')
12
- @url = Net::HTTP.new(@uri.host, @uri.port)
13
- @url.use_ssl = true
37
+ @api = Net::HTTP.new(@uri.host, @uri.port)
38
+ @api.use_ssl = true
14
39
  end
15
40
 
16
41
  private
17
42
 
43
+ def put(file_path)
44
+ begin
45
+ @ftp[:handle].put(file_path.to_s)
46
+ rescue Exception => msg
47
+ puts '[ExactTarget] Error: FTP put failed.'
48
+ raise msg
49
+ end
50
+ end
51
+
52
+ def delete(file_name)
53
+ begin
54
+ @ftp[:handle].delete(file_name.to_s)
55
+ rescue Exception => msg
56
+ puts '[ExactTarget] Error: FTP delete failed.'
57
+ raise msg
58
+ end
59
+ end
60
+
18
61
  def render(template)
19
62
  path = File.join(File.dirname(__FILE__), "templates/#{template.to_s}.xml.erb")
20
63
  file = File.open(path, 'r').read
@@ -26,14 +69,15 @@ module ExactTarget
26
69
  post = 'qf=xml&xml=' + URI.escape(render(:main))
27
70
 
28
71
  begin
29
- @url.post(@uri.path, post,
72
+ @api.post(@uri.path, post,
30
73
  {
31
74
  'Content-Type' => 'application/x-www-form-urlencoded',
32
75
  'Content-length' => post.length.to_s
33
76
  }
34
77
  ).body
35
- rescue SocketError
36
- raise '[ExactTarget] Error: API request failed (SocketError).'
78
+ rescue SocketError => msg
79
+ puts '[ExactTarget] Error: API request failed.'
80
+ raise msg
37
81
  end
38
82
  end
39
83
 
@@ -0,0 +1,31 @@
1
+ module ExactTarget
2
+ class Client
3
+
4
+ public
5
+
6
+ def image_import(file_path)
7
+ @name = File.basename(file_path)
8
+
9
+ begin
10
+ put(file_path.to_s)
11
+ result = Nokogiri::XML(send(render(:image)))
12
+ delete(@name)
13
+ rescue Exception => msg
14
+ puts msg
15
+ end
16
+
17
+ desc = result.xpath('//filemanagement-description').text
18
+ total = result.xpath('//filemanagement-totalmoved').text.to_i
19
+ name = result.xpath('//filemanagement-info').text
20
+ error = desc.include?('not exist') ? 'File not found.' : total < 1 ? 'Unsupported file type.' : nil
21
+
22
+ {
23
+ :file_path => file_path,
24
+ :old_name => @name,
25
+ :new_name => name,
26
+ :error => error
27
+ }
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ <system>
2
+
3
+ <system_name>filemanagement</system_name>
4
+ <action>filemove</action>
5
+ <source>
6
+ <location><%= @ftp[:location] %></location>
7
+ <files>
8
+ <filename><%= @name %></filename>
9
+ </files>
10
+ </source>
11
+ <destination>imageimport</destination>
12
+
13
+ </system>
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matthew Simpson
@@ -109,7 +109,9 @@ files:
109
109
  - lib/exacttarget.rb
110
110
  - lib/exacttarget/client.rb
111
111
  - lib/exacttarget/email.rb
112
+ - lib/exacttarget/image.rb
112
113
  - lib/exacttarget/templates/email.xml.erb
114
+ - lib/exacttarget/templates/image.xml.erb
113
115
  - lib/exacttarget/templates/main.xml.erb
114
116
  has_rdoc: true
115
117
  homepage: http://github.com/msimpson/exacttarget
@@ -125,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
127
  requirements:
126
128
  - - ">="
127
129
  - !ruby/object:Gem::Version
128
- hash: -4363040574825173026
130
+ hash: 1328632892447175540
129
131
  segments:
130
132
  - 0
131
133
  version: "0"