ficonabses 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -1
- data/lib/ficonabses/base.rb +29 -2
- data/test/test_ficonabses.rb +16 -4
- data/test/test_hashparams.rb +35 -0
- data/test/test_localhost.rb +23 -7
- data/test/test_templates.rb +12 -1
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -31,7 +31,7 @@ A simple way to send emails from your application using amazon ses. Register at
|
|
31
31
|
f.send_textemail(@destination,'This is the subject','text contents of the email')
|
32
32
|
|
33
33
|
== SYNOPSIS USING A TEMPLATE:
|
34
|
-
* The subject and contents of the template are defined on the system. See admin.ses.sg.estormtech.com[http:admin.ses.sg.estormtech.com]. As well as a bcc variable is also possible to be defined to automatically copy an
|
34
|
+
* The subject and contents of the template are defined on the system. See admin.ses.sg.estormtech.com[http:admin.ses.sg.estormtech.com]. As well as a bcc variable is also possible to be defined to automatically copy an addresss. The template may be an email or an apple push notification.
|
35
35
|
|
36
36
|
* res =FiconabSES::Base.send_template_direct(@account,@passwd,@destination,templatename)
|
37
37
|
* or similarly using objects
|
@@ -40,6 +40,15 @@ A simple way to send emails from your application using amazon ses. Register at
|
|
40
40
|
res =f.send_template(@destination,'testtemplate')
|
41
41
|
|
42
42
|
== SYNOPSIS USING A TEMPLATE PLUS PARAMETERS
|
43
|
+
* This allows you to have a dynamic template and fill in the details in the template dynamically. (eg insert url, customer name) into the template just by attaching the values to the call in a ruby hash.
|
44
|
+
|
45
|
+
* res =FiconabSES::Base.send_template_params_direct(@account,@passwd,@destination,templatename,options)
|
46
|
+
* or similarly using objects
|
47
|
+
f=FiconabSES::Base.new
|
48
|
+
options={}
|
49
|
+
options['customername']='Mr Test' #in the template {customername} will be replaced with Mr Test
|
50
|
+
f.set_credentials(@account,@passwd,options)
|
51
|
+
res =f.send_template(@destination,'testtemplate')
|
43
52
|
|
44
53
|
== REQUIREMENTS:
|
45
54
|
|
data/lib/ficonabses/base.rb
CHANGED
@@ -4,7 +4,19 @@ gem 'httpclient'
|
|
4
4
|
require 'httpclient'
|
5
5
|
gem 'nokogiri'
|
6
6
|
require 'nokogiri'
|
7
|
-
|
7
|
+
class Object
|
8
|
+
def to_query(key)
|
9
|
+
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
|
10
|
+
"#{CGI.escape(key.to_s)}=#{CGI.escape(self.to_s)}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
class Hash
|
14
|
+
def to_param(namespace = nil)
|
15
|
+
collect do |key, value|
|
16
|
+
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
|
17
|
+
end.sort * '&'
|
18
|
+
end
|
19
|
+
end
|
8
20
|
module FiconabSES
|
9
21
|
class Base
|
10
22
|
attr_accessor :host,:account,:password,:uri,:clnt,:extheader
|
@@ -36,6 +48,11 @@ module FiconabSES
|
|
36
48
|
f.set_credentials(account,password)
|
37
49
|
f.send_template(destination,templatename)
|
38
50
|
end
|
51
|
+
def self.send_template_params_direct(account,password,destination,templatename,options={})
|
52
|
+
f=FiconabSES::Base.new
|
53
|
+
f.set_credentials(account,password)
|
54
|
+
f.send_template(destination,templatename,options)
|
55
|
+
end
|
39
56
|
def perform(url)
|
40
57
|
@uri=URI.parse(url)
|
41
58
|
raise 'credentials not set' if @account==nil
|
@@ -68,6 +85,10 @@ module FiconabSES
|
|
68
85
|
url="#{self.action_url('ficonabsimpletemplate',destination)}&template=#{URI.encode(templatename)}"
|
69
86
|
url
|
70
87
|
end
|
88
|
+
def template_url_params(destination,templatename,options)
|
89
|
+
url="#{self.action_url('ficonabcomplextemplate',destination)}&template=#{URI.encode(templatename)}&#{options.to_param}"
|
90
|
+
url
|
91
|
+
end
|
71
92
|
def html_url(destination,subject,contents,html)
|
72
93
|
contents='' if contents==nil
|
73
94
|
url="#{self.text_url(destination,subject,contents)}&html=#{URI.encode(html)}"
|
@@ -80,10 +101,16 @@ module FiconabSES
|
|
80
101
|
end
|
81
102
|
def send_template(destination,templatename)
|
82
103
|
url=self.template_url(destination,templatename)
|
83
|
-
|
104
|
+
# puts "url is: #{url}"
|
84
105
|
perform(url)
|
85
106
|
# res
|
86
107
|
end
|
108
|
+
def send_template_params(destination,templatename,options={})
|
109
|
+
url=self.template_url_params(destination,templatename,options)
|
110
|
+
puts "url is: #{url}"
|
111
|
+
perform(url)
|
112
|
+
# res
|
113
|
+
end
|
87
114
|
def send_htmlemail(destination,subject,htmlcontents,textcontents=nil)
|
88
115
|
textcontents='-' if textcontents==nil
|
89
116
|
url=self.html_url(destination,subject,textcontents,htmlcontents)
|
data/test/test_ficonabses.rb
CHANGED
@@ -7,18 +7,20 @@ class TestFiconabses < Test::Unit::TestCase
|
|
7
7
|
@account=ACCOUNT #in test_secret.rb put ACCOUNT='youraccount' or insert your parameters direclty here eg @ACCOUNT='myaccount'
|
8
8
|
@passwd=PASSWD #in test_secret.rb put PASSWD='yourpasswd'
|
9
9
|
@destination=DESTINATION # eg your email address 'xxx@yyyy.com'
|
10
|
-
|
10
|
+
@tsipid = TSIPID
|
11
11
|
end
|
12
12
|
def test_creds
|
13
13
|
puts "CREDENTIALS ARE: account: #{@account} passwd: #{@passwd}"
|
14
14
|
# self assert true
|
15
15
|
end
|
16
|
+
|
16
17
|
def test_send_text_direct
|
17
18
|
puts 'SEND TEXT DIRECT'
|
18
19
|
res =FiconabSES::Base.send_textemail_direct(@account,@passwd,@destination,'This is the subject','contents of the email')
|
19
20
|
#puts "RES is: #{res}"
|
20
21
|
assert res.include? '200'
|
21
22
|
end
|
23
|
+
|
22
24
|
def test_send_html_direct
|
23
25
|
puts "SEND HTML DIRECT"
|
24
26
|
res =FiconabSES::Base.send_htmlemail_direct(@account,@passwd,@destination,'This is the HTML subject','<h1>HTML Contents</h1><p>hi from paragraph</p>','text contents of the email')
|
@@ -26,7 +28,7 @@ class TestFiconabses < Test::Unit::TestCase
|
|
26
28
|
assert res.include? '200'
|
27
29
|
assert false==(res.include? 'Error')
|
28
30
|
end
|
29
|
-
|
31
|
+
|
30
32
|
def test_send_html_nil_text
|
31
33
|
puts "SEND HTML with NIL text"
|
32
34
|
res =FiconabSES::Base.send_htmlemail_direct(@account,@passwd,@destination,'This is HTML Subject nil text','<h1>HTML Contents</h1><p>hi from paragraph</p>') #no text portion
|
@@ -34,7 +36,7 @@ class TestFiconabses < Test::Unit::TestCase
|
|
34
36
|
assert res.include? '200'
|
35
37
|
assert false==(res.include? 'Error')
|
36
38
|
end
|
37
|
-
|
39
|
+
|
38
40
|
def test_send_emails
|
39
41
|
f=FiconabSES::Base.new
|
40
42
|
f.set_credentials(@account,@passwd)
|
@@ -46,7 +48,17 @@ class TestFiconabses < Test::Unit::TestCase
|
|
46
48
|
assert res.include? '200'
|
47
49
|
assert false==(res.include? 'Error')
|
48
50
|
end
|
49
|
-
|
51
|
+
|
52
|
+
def test_apn_template_params
|
53
|
+
options={}
|
54
|
+
options['hello']='TESTING'
|
55
|
+
f=FiconabSES::Base.new
|
56
|
+
f.set_credentials(@account,@passwd)
|
57
|
+
res =f.send_template_params(@tsipid,'apn_template',options) #no text portion
|
58
|
+
puts "RES is: #{res}"
|
59
|
+
assert res.include? '200'
|
60
|
+
assert false==(res.include? 'Error')
|
61
|
+
end
|
50
62
|
def test_no_credentials
|
51
63
|
f=FiconabSES::Base.new
|
52
64
|
assert_raise RuntimeError do #should raise runtime error
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/test_secret.rb' #FILL IN ACCOUNT/PASSWD AS GLOBALS IN THIS
|
3
|
+
|
4
|
+
class TestFiconabses < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@account=ACCOUNT #in test_secret.rb put ACCOUNT='youraccount' or insert your parameters direclty here eg @ACCOUNT='myaccount'
|
8
|
+
@passwd=PASSWD #in test_secret.rb put PASSWD='yourpasswd'
|
9
|
+
@destination=DESTINATION # eg your email address 'xxx@yyyy.com'
|
10
|
+
@f=FiconabSES::Base.new
|
11
|
+
@f.set_credentials('scott','scott123')
|
12
|
+
@f.set_debug
|
13
|
+
@destination='scott.sproule@gmail.com'
|
14
|
+
@tsipid ='7923044488'
|
15
|
+
end
|
16
|
+
def test_hash
|
17
|
+
options={}
|
18
|
+
options['hello']='TESTING'
|
19
|
+
res=options.to_param
|
20
|
+
assert res=="hello=TESTING","res is: #{res}"
|
21
|
+
options['hello2']='TESTING2'
|
22
|
+
res=options.to_param
|
23
|
+
assert res=="hello2=TESTING2&hello=TESTING","res is: #{res}"
|
24
|
+
end
|
25
|
+
def test_local_apn_template_params
|
26
|
+
options={}
|
27
|
+
options['hello']='TESTING'
|
28
|
+
res =@f.send_template_params(@tsipid,'apn_template',options) #no text portion
|
29
|
+
puts "RES is: #{res}"
|
30
|
+
assert res.include? '200'
|
31
|
+
assert false==(res.include? 'Error')
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/test/test_localhost.rb
CHANGED
@@ -23,21 +23,37 @@ class TestFiconabses < Test::Unit::TestCase
|
|
23
23
|
assert res.include? '200'
|
24
24
|
assert false==(res.include? 'Error')
|
25
25
|
end
|
26
|
-
def test_local_send_template
|
27
|
-
|
26
|
+
def test_local_send_template
|
28
27
|
res =@f.send_template(@destination,'testtemplate') #no text portion
|
29
28
|
puts "RES is: #{res}"
|
30
29
|
assert res.include? '200'
|
31
|
-
assert false==(res.include? 'Error')
|
32
|
-
|
33
|
-
end
|
30
|
+
assert false==(res.include? 'Error')
|
31
|
+
end
|
34
32
|
def test_local_apn_template
|
35
|
-
|
36
33
|
res =@f.send_template(@tsipid,'apn_template') #no text portion
|
37
34
|
puts "RES is: #{res}"
|
38
35
|
assert res.include? '200'
|
39
36
|
assert false==(res.include? 'Error')
|
40
|
-
|
41
37
|
end
|
38
|
+
|
39
|
+
def test_local_apn_template_params
|
40
|
+
options={}
|
41
|
+
options['hello']='TESTING'
|
42
|
+
res =@f.send_template_params(@tsipid,'apn_template',options) #no text portion
|
43
|
+
puts "RES is: #{res}"
|
44
|
+
assert res.include? '200'
|
45
|
+
assert false==(res.include? 'Error')
|
46
|
+
|
47
|
+
end
|
48
|
+
def test_local_apn_template_params
|
49
|
+
options={}
|
50
|
+
options['hello']='TESTING'
|
51
|
+
options['bcinfo']='+6590683565'
|
52
|
+
res =@f.send_template_params(@tsipid,'apn_template',options) #no text portion
|
53
|
+
puts "RES is: #{res}"
|
54
|
+
assert res.include? '200'
|
55
|
+
assert false==(res.include? 'Error')
|
56
|
+
|
57
|
+
end
|
42
58
|
|
43
59
|
end
|
data/test/test_templates.rb
CHANGED
@@ -6,7 +6,7 @@ class TestFiconabses < Test::Unit::TestCase
|
|
6
6
|
def setup
|
7
7
|
@account=ACCOUNT #in test_secret.rb put ACCOUNT='youraccount' or insert your parameters direclty here eg @ACCOUNT='myaccount'
|
8
8
|
@passwd=PASSWD #in test_secret.rb put PASSWD='yourpasswd'
|
9
|
-
|
9
|
+
# puts "CREDENTIALS ARE: account: #{@account} passwd: #{@passwd}"
|
10
10
|
@destination=DESTINATION
|
11
11
|
@tsipid=TSIPID
|
12
12
|
end
|
@@ -25,4 +25,15 @@ class TestFiconabses < Test::Unit::TestCase
|
|
25
25
|
assert res.include? '200'
|
26
26
|
|
27
27
|
end
|
28
|
+
|
29
|
+
def test_apn_template_params
|
30
|
+
options={}
|
31
|
+
options['hello']='TESTING'
|
32
|
+
f=FiconabSES::Base.new
|
33
|
+
f.set_credentials(@account,@passwd)
|
34
|
+
res =f.send_template_params(@tsipid,'apn_template',options) #no text portion
|
35
|
+
puts "RES is: #{res}"
|
36
|
+
assert res.include? '200'
|
37
|
+
assert false==(res.include? 'Error')
|
38
|
+
end
|
28
39
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 6
|
9
|
+
version: 0.1.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Scott Sproule
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- lib/ficonabses/base.rb
|
31
31
|
- lib/ficonabses.rb
|
32
32
|
- test/test_ficonabses.rb
|
33
|
+
- test/test_hashparams.rb
|
33
34
|
- test/test_helper.rb
|
34
35
|
- test/test_localhost.rb
|
35
36
|
- test/test_secret.rb
|