capistrano-mailgun 1.0.1 → 1.0.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.
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Mailgun
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
@@ -6,6 +6,9 @@ require 'erb'
6
6
  module Capistrano
7
7
  module Mailgun
8
8
 
9
+ # Load the base configuration into the given Capistrano::Instance.
10
+ # This is primarily used for testing and is executed automatically when requiring
11
+ # the library in a Capistrano recipe.
9
12
  def self.load_into(config)
10
13
  config.load do
11
14
 
@@ -31,14 +34,26 @@ module Capistrano
31
34
  end # config.load
32
35
  end
33
36
 
34
- # simple wrapper for sending an email with a given template
37
+ # Simple wrapper for sending an email with a given template
38
+ # Supports all options that the Mailgun API supports. In addition, it also accepts:
39
+ # +:text_template+ -- the path to the template for the text body. It will be processed and interpolated and set the +text+ field when doing the API call.
40
+ # +:html_template+ -- the path to the template for the html body. It will be processed and interpolated and set the +html+ field when doing the API call.
35
41
  def send_email(options)
36
42
  options = process_send_email_options(options)
37
43
 
38
44
  RestClient.post build_mailgun_uri( mailgun_api_key, mailgun_domain ), options
39
45
  end
40
46
 
41
- # does a deploy notification leveraging variables defined in capistrano.
47
+ # Sends the email via the Mailgun API using variables configured in Capistrano.
48
+ # It depends on the following Capistrano vars in addition to the default:
49
+ # +mailgun_recipients+
50
+ # +mailgun_from+
51
+ # +mailgun_subject+
52
+ # Requires one or both of the following:
53
+ # +mailgun_text_template+
54
+ # +mailgun_html_template+
55
+ #
56
+ # See README for explanations of the above variables.
42
57
  def notify_of_deploy
43
58
  options = {
44
59
  :to => build_recipients( fetch(:mailgun_recipients) ),
@@ -56,13 +71,14 @@ module Capistrano
56
71
  send_email options
57
72
  end
58
73
 
59
- # kinda unused function for locating a provided template
74
+ # Placeholder method for hunting down templates. Currently does nothing.
60
75
  def find_template(t)
61
76
  return t
62
77
  File.join( File.dirname(__FILE__), t )
63
78
  end
64
79
 
65
- # regenerates the recipients list using the mailgun_domain for any reciients without domains
80
+ # Given an array of +recipients+, it returns a comma-delimited, deduplicated string, suitable for populating the +to+ field of a Mailgun API call.
81
+ # Optionally, it will take a +default_domain+ which will automatically be appended to any unqualified recipients (eg: 'spike' => 'spike@example.com')
66
82
  def build_recipients(recipients, default_domain=nil)
67
83
  [*recipients].map do |r|
68
84
  if r.match /.+?@.+?$/ # the email contains an @ so it's fully-qualified.
@@ -86,6 +102,7 @@ module Capistrano
86
102
  options
87
103
  end
88
104
 
105
+ # builds the Mailgun API URI from the given options.
89
106
  def build_mailgun_uri(mailgun_api_key, mailgun_domain)
90
107
  "https://api:#{ mailgun_api_key }@api.mailgun.net/v2/#{ mailgun_domain }/messages"
91
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-mailgun
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -79,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  segments:
81
81
  - 0
82
- hash: 3847962389882699004
82
+ hash: -2168870135844714304
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  segments:
90
90
  - 0
91
- hash: 3847962389882699004
91
+ hash: -2168870135844714304
92
92
  requirements: []
93
93
  rubyforge_project:
94
94
  rubygems_version: 1.8.24