Class: CIQuantum::Utils::Mailer
- Inherits:
-
Object
- Object
- CIQuantum::Utils::Mailer
- Defined in:
- lib/ciquantum/utils/mailer.rb
Constant Summary collapse
- Captions =
{ failed: "Build failed", still_failed: "Buils hasn't been repaired yet", repaired: "Build repaired", worked: "Build worked" }
Instance Attribute Summary collapse
-
#project ⇒ Object
Returns the value of attribute project.
-
#roles_with_keys ⇒ Object
Returns the value of attribute roles_with_keys.
Instance Method Summary collapse
-
#initialize(project, roles_with_keys) ⇒ Mailer
constructor
A new instance of Mailer.
- #send_html(build, status) ⇒ Object
- #send_mail(type, subject, body) ⇒ Object
- #send_plain(build, status) ⇒ Object
- #send_template(template, build, status) ⇒ Object
- #template(name, template_path = nil) ⇒ Object
Constructor Details
#initialize(project, roles_with_keys) ⇒ Mailer
Returns a new instance of Mailer.
20 21 22 23 |
# File 'lib/ciquantum/utils/mailer.rb', line 20 def initialize project, roles_with_keys @project = project @roles_with_keys = roles_with_keys end |
Instance Attribute Details
#project ⇒ Object
Returns the value of attribute project.
18 19 20 |
# File 'lib/ciquantum/utils/mailer.rb', line 18 def project @project end |
#roles_with_keys ⇒ Object
Returns the value of attribute roles_with_keys.
17 18 19 |
# File 'lib/ciquantum/utils/mailer.rb', line 17 def roles_with_keys @roles_with_keys end |
Instance Method Details
#send_html(build, status) ⇒ Object
53 54 55 |
# File 'lib/ciquantum/utils/mailer.rb', line 53 def send_html build, status send_template :html, build, status end |
#send_mail(type, subject, body) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ciquantum/utils/mailer.rb', line 25 def send_mail type, subject, body data = "email=" + CGI::escape({subject: subject, body: body, type: type}.to_json) @roles_with_keys.each do |role, api_key| uri = URI.parse "https://sqauth.socialquantum.com/send_email/#{@project}/#{role}/#{api_key}" http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE response = http.post(uri.path, data, { 'Content-Type' => 'application/x-www-form-urlencoded' }) end end |
#send_plain(build, status) ⇒ Object
57 58 59 |
# File 'lib/ciquantum/utils/mailer.rb', line 57 def send_plain build, status send_template :text, build, status end |
#send_template(template, build, status) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ciquantum/utils/mailer.rb', line 42 def send_template template, build, status @build = build @status = status @caption = Captions[status] body = template(template.to_s).result(binding) subject = "CIServer: state on branch #{build.branch}" send_mail template.to_s, subject, body end |
#template(name, template_path = nil) ⇒ Object
36 37 38 39 40 |
# File 'lib/ciquantum/utils/mailer.rb', line 36 def template name, template_path = nil template_path ||= File. "#{File.dirname __FILE__}/../views/mailer" template = File.read(File.join template_path, "#{name}.erb") ERB.new(template) end |