planet_express 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,6 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
6
+
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ # Please keep this file alphabetically sorted.
2
+
3
+ *.gem
4
+ *.rbc
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/.rbenv-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p194
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3-p194@planet_express --create --install
data/DEVELOP.md ADDED
@@ -0,0 +1,35 @@
1
+ # Setup
2
+
3
+ ## Install Ruby
4
+
5
+ ## Ruby
6
+
7
+ Make sure that you're using the correct ruby version. We provide both
8
+ .rbenv-version and .rvmrc files just to be sure.
9
+
10
+ ```
11
+ ruby --version;
12
+ ruby 1.9.3p194]
13
+ ```
14
+
15
+ ## Gems
16
+
17
+ Install `bundler` and all the dependencies:
18
+
19
+ ```
20
+ gem install bundler;
21
+ bundle install;
22
+ ```
23
+
24
+ At the end you should see:
25
+
26
+ ```
27
+ $ bundle check
28
+ The Gemfile's dependencies are satisfied
29
+ ```
30
+
31
+ ## Tests
32
+
33
+ ```
34
+ bundle exec guard
35
+ ```
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source :rubygems
2
+ ruby '1.9.3'
3
+
4
+ # Specify your gem's dependencies in planet_express.gemspec
5
+ gemspec
6
+
7
+ group :osx do
8
+ gem 'rb-fsevent', :require => false
9
+ gem 'ruby_gntp'
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ planet_express (0.0.3)
5
+ activesupport
6
+ hpricot
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activesupport (3.2.8)
12
+ i18n (~> 0.6)
13
+ multi_json (~> 1.0)
14
+ diff-lcs (1.1.3)
15
+ guard (1.4.0)
16
+ listen (>= 0.4.2)
17
+ thor (>= 0.14.6)
18
+ guard-bundler (1.0.0)
19
+ bundler (~> 1.0)
20
+ guard (~> 1.1)
21
+ guard-rspec (2.1.0)
22
+ guard (>= 1.1)
23
+ rspec (~> 2.11)
24
+ hpricot (0.8.6)
25
+ i18n (0.6.1)
26
+ listen (0.5.3)
27
+ multi_json (1.3.6)
28
+ rb-fsevent (0.9.2)
29
+ rspec (2.11.0)
30
+ rspec-core (~> 2.11.0)
31
+ rspec-expectations (~> 2.11.0)
32
+ rspec-mocks (~> 2.11.0)
33
+ rspec-core (2.11.1)
34
+ rspec-expectations (2.11.3)
35
+ diff-lcs (~> 1.1.3)
36
+ rspec-mocks (2.11.3)
37
+ ruby_gntp (0.3.4)
38
+ thor (0.16.0)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ guard
45
+ guard-bundler
46
+ guard-rspec
47
+ planet_express!
48
+ rb-fsevent
49
+ rspec
50
+ ruby_gntp
data/Guardfile ADDED
@@ -0,0 +1,25 @@
1
+ guard 'rspec', :all_on_start => true, :all_after_pass => false do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+
6
+ # Rails example
7
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
8
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
9
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
10
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
11
+ watch('config/routes.rb') { "spec/routing" }
12
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
13
+
14
+ # Capybara request specs
15
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
16
+
17
+ # Turnip features and steps
18
+ watch(%r{^spec/acceptance/(.+)\.feature$})
19
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
20
+ end
21
+
22
+ guard 'bundler' do
23
+ watch('Gemfile')
24
+ watch(/^.+\.gemspec/)
25
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Mario Zaizar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,124 @@
1
+ Planet Express.rb
2
+ =================
3
+
4
+ Planet Express, Inc. is an intergalactic email delivery <strike>company</strike>
5
+ lib built in Ruby. Is meant to be used with Silverpop mailing system, to provide
6
+ an easy way to send emails. We're using it with Rails 3 apps.
7
+
8
+ > "Our crew is replaceable. Your <strike>package</strike> email isn't."
9
+
10
+ **@MarioZaizar**
11
+
12
+ ## Installation
13
+ ---------------
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```
18
+ gem 'planet_express'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ ```
24
+ $ bundle
25
+ ```
26
+
27
+ Or install it yourself as:
28
+
29
+ ```
30
+ $ gem install planet_express
31
+ ```
32
+
33
+ Usage
34
+ -----
35
+
36
+ You only need three things, the package, the destination and the data.
37
+
38
+ ```
39
+ recipient = 'mariozaizar@gmail.com'
40
+ package_id = 1807752
41
+ cargo = {
42
+ fist_name: 'Mario',
43
+ last_name: 'Zaizar',
44
+ bill_float_test_body: "<h1>Good news everyone!</h1><img src='http://goo.gl/XazeH'>"
45
+ }
46
+ ```
47
+
48
+ Then create a new deliver, prepare the ship and deliver it!
49
+
50
+ ```
51
+ job = PlanetExpress::Delivery.new
52
+ request = job.prepare package_id, recipient, cargo
53
+ response = job.deliver!
54
+ ```
55
+
56
+ Silverpop API
57
+ -------------
58
+
59
+ We're using this <https://transact5.silverpop.com/XTMail> end point.
60
+
61
+ ### Request:
62
+
63
+ ```
64
+ <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
65
+ <XTMAILING>
66
+ <CAMPAIGN_ID>1807752</CAMPAIGN_ID>
67
+ <SHOW_ALL_SEND_DETAIL>true</SHOW_ALL_SEND_DETAIL>
68
+ <SEND_AS_BATCH>false</SEND_AS_BATCH>
69
+ <NO_RETRY_ON_FAILURE>false</NO_RETRY_ON_FAILURE>
70
+ <RECIPIENT>
71
+ <EMAIL>mariozaizar@gmail.com</EMAIL>
72
+ <BODY_TYPE>HTML</BODY_TYPE>
73
+ <PERSONALIZATION>
74
+ <TAG_NAME>first_name</TAG_NAME>
75
+ <VALUE><![CDATA[Mario]]></VALUE>
76
+ </PERSONALIZATION>
77
+ <PERSONALIZATION>
78
+ <TAG_NAME>last_name</TAG_NAME>
79
+ <VALUE><![CDATA[Zaizar]]></VALUE>
80
+ </PERSONALIZATION>
81
+ </RECIPIENT>
82
+ </XTMAILING>
83
+ ```
84
+
85
+ ### Response:
86
+
87
+ Succcess:
88
+
89
+ ```
90
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
91
+ <XTMAILING_RESPONSE>
92
+ <CAMPAIGN_ID>1807752</CAMPAIGN_ID>
93
+ <RECIPIENTS_RECEIVED>1</RECIPIENTS_RECEIVED>
94
+ <EMAILS_SENT>1</EMAILS_SENT>
95
+ <NUMBER_ERRORS>0</NUMBER_ERRORS>
96
+ <STATUS>0</STATUS>
97
+ <ERROR_CODE></ERROR_CODE>
98
+ <ERROR_STRING></ERROR_STRING>
99
+ </XTMAILING_RESPONSE>
100
+ ```
101
+
102
+ When something is wrong:
103
+
104
+ ```
105
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
106
+ <XTMAILING_RESPONSE>
107
+ <CAMPAIGN_ID>1807752</CAMPAIGN_ID>
108
+ <RECIPIENTS_RECEIVED>1</RECIPIENTS_RECEIVED>
109
+ <EMAILS_SENT>0</EMAILS_SENT>
110
+ <NUMBER_ERRORS>1</NUMBER_ERRORS>
111
+ <STATUS>2</STATUS>
112
+ <ERROR_CODE>2</ERROR_CODE>
113
+ <ERROR_STRING>something wrong!</ERROR_STRING>
114
+ </XTMAILING_RESPONSE>
115
+ ```
116
+
117
+ Contributing
118
+ ------------
119
+
120
+ 1. Fork it
121
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
122
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
123
+ 4. Push to the branch (`git push origin my-new-feature`)
124
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,88 @@
1
+ module PlanetExpress
2
+ class Delivery
3
+ # Everybody needs log in your life
4
+ cattr_accessor :logger
5
+ self.logger = Logger.new(STDOUT)
6
+
7
+ def prepare campaign_id, recipient, personalizations={}
8
+ # Is a better way to do this?
9
+ @campaign_id = campaign_id
10
+ @recipient = recipient
11
+ @personalizations = personalizations
12
+
13
+ logger.info "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
14
+ logger.info "campaign_id => #{@campaign_id}"
15
+ logger.info "recipient => #{@recipient}"
16
+ logger.info "personalizations => #{@personalizations}"
17
+ logger.info "personalizations total => #{@personalizations.count}"
18
+
19
+ @personalizations.merge!({ :timestamp => Time.now, :email_template => @campaign_id })
20
+ build_request
21
+ end
22
+
23
+ def deliver!
24
+ url = URI.parse 'https://transact5.silverpop.com/XTMail'
25
+ http, resp = Net::HTTP.new(url.host, url.port), ''
26
+ http.use_ssl = true
27
+
28
+ http.start do |h|
29
+ path = url.path
30
+ resp = h.post path, @request.to_s, { 'Content-type' => 'text/xml' }
31
+ end
32
+
33
+ build_response(resp.body)
34
+ end
35
+
36
+ private
37
+
38
+ def build_request
39
+ fields_xml = ''
40
+
41
+ @personalizations.each_pair do |name, value|
42
+ fields_xml +=
43
+ "<PERSONALIZATION>" +
44
+ " <TAG_NAME>#{name}</TAG_NAME>" +
45
+ " <VALUE><![CDATA[#{value}]]></VALUE>" +
46
+ "</PERSONALIZATION>"
47
+ end
48
+
49
+ recipient_xml =
50
+ "<RECIPIENT>" +
51
+ " <EMAIL>" + @recipient + "</EMAIL>" +
52
+ " <BODY_TYPE>HTML</BODY_TYPE>" +
53
+ " #{fields_xml}" +
54
+ "</RECIPIENT>"
55
+
56
+ @request =
57
+ "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" +
58
+ "<XTMAILING>" +
59
+ " <CAMPAIGN_ID>#{@campaign_id}</CAMPAIGN_ID>" +
60
+ " <SHOW_ALL_SEND_DETAIL>true</SHOW_ALL_SEND_DETAIL>" +
61
+ " <SEND_AS_BATCH>false</SEND_AS_BATCH>" +
62
+ " <NO_RETRY_ON_FAILURE>false</NO_RETRY_ON_FAILURE>" +
63
+ # " <TRANSACTION_ID>" + @transaction_id + "</TRANSACTION_ID>" +
64
+ " #{recipient_xml}" +
65
+ "</XTMAILING>"
66
+
67
+ logger.info "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
68
+ logger.info "request => #{@request}"
69
+
70
+ @request
71
+ end
72
+
73
+ def build_response response
74
+ @response = Hpricot::XML(response)
75
+ logger.info "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
76
+ logger.info "response => #{response.inspect}"
77
+
78
+ status = @response.at('STATUS').innerHTML.to_i
79
+ error_string = @response.at('ERROR_STRING').innerHTML
80
+ recipients_received = @response.at('RECIPIENTS_RECEIVED').innerHTML
81
+ emails_sent = @response.at('EMAILS_SENT').innerHTML
82
+
83
+ return { status: false, emails_sent: emails_sent, recipients_received: recipients_received, message: 'The request has not been executed.' } if @response.nil?
84
+ return { status: false, emails_sent: emails_sent, recipients_received: recipients_received, message: error_string } if status == 2
85
+ return { status: true, emails_sent: emails_sent, recipients_received: recipients_received } if status == 0
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,3 @@
1
+ module PlanetExpress
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'hpricot'
4
+
5
+ require "planet_express/version"
6
+ require "planet_express/delivery"
7
+
8
+ module PlanetExpress
9
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'planet_express/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "planet_express"
8
+ gem.version = PlanetExpress::VERSION
9
+ gem.authors = ["Mario Zaizar"]
10
+ gem.email = ["mariozaizar@gmail.com"]
11
+ gem.description = %q{An intergalactic email delivery library to send Emails with Silverpop provider.}
12
+ gem.summary = %q{Planet Express, Inc. is an intergalactic email delivery library built in Ruby. Is meant to be used with Silverpop mailing system, to provide an easy way to send emails. We're using it with Rails 3 apps.}
13
+ gem.homepage = "https://github.com/mariozaizar/planet_express"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'activesupport'
21
+ gem.add_dependency 'hpricot'
22
+
23
+ gem.add_development_dependency 'guard'
24
+ gem.add_development_dependency 'guard-bundler'
25
+ gem.add_development_dependency 'guard-rspec'
26
+ gem.add_development_dependency 'rspec'
27
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,10 @@
1
+ require 'active_support/all'
2
+
3
+ require_relative '../lib/planet_express'
4
+
5
+ RSpec.configure do |config|
6
+ config.treat_symbols_as_metadata_keys_with_true_values = true
7
+ config.run_all_when_everything_filtered = true
8
+ config.filter_run :focus
9
+ config.order = 'random'
10
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: planet_express
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mario Zaizar
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: hpricot
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: An intergalactic email delivery library to send Emails with Silverpop
111
+ provider.
112
+ email:
113
+ - mariozaizar@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .document
119
+ - .gitignore
120
+ - .rbenv-version
121
+ - .rvmrc
122
+ - DEVELOP.md
123
+ - Gemfile
124
+ - Gemfile.lock
125
+ - Guardfile
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - lib/planet_express.rb
130
+ - lib/planet_express/delivery.rb
131
+ - lib/planet_express/version.rb
132
+ - planet_express.gemspec
133
+ - spec/planet_express_spec.rb
134
+ - spec/spec_helper.rb
135
+ homepage: https://github.com/mariozaizar/planet_express
136
+ licenses: []
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ segments:
148
+ - 0
149
+ hash: 4224548502706184700
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ segments:
157
+ - 0
158
+ hash: 4224548502706184700
159
+ requirements: []
160
+ rubyforge_project:
161
+ rubygems_version: 1.8.23
162
+ signing_key:
163
+ specification_version: 3
164
+ summary: Planet Express, Inc. is an intergalactic email delivery library built in
165
+ Ruby. Is meant to be used with Silverpop mailing system, to provide an easy way
166
+ to send emails. We're using it with Rails 3 apps.
167
+ test_files:
168
+ - spec/planet_express_spec.rb
169
+ - spec/spec_helper.rb