sendgrid_cli_mailer 0.5.3 → 0.6.0
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.md +18 -2
- data/bin/sg_mail +35 -0
- data/lib/sendgrid_cli_mailer.rb +6 -0
- data/lib/sendgrid_cli_mailer/version.rb +1 -1
- metadata +4 -4
- data/bin/sg_cli +0 -21
data/README.md
CHANGED
@@ -23,14 +23,30 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
+
### Using command line arguments
|
27
|
+
|
26
28
|
You can send a message with a body specified via arguments:
|
27
29
|
|
28
|
-
|
30
|
+
sg_mail mail --from 'admin@yourjoint.com' --to 'hank@me.com' --subject 'Testing CLI' --body 'Short Body' --user 'sg@foo.com' --key '1234'"
|
29
31
|
|
30
32
|
OR use your body input in other ways like so:
|
31
33
|
|
32
|
-
|
34
|
+
sg_mail mail --from 'admin@yourjoint.com' --to 'hank@me.com' --subject 'Testing CLI' --user 'sg@foo.com' --key '1234'" --body `cat /etc/hosts`
|
35
|
+
|
36
|
+
### Using less command line arguments
|
37
|
+
|
38
|
+
You can save a file called .sg_mail in your home directory and this file
|
39
|
+
can make using a little easier.
|
40
|
+
|
41
|
+
~/.sg_mail example:
|
42
|
+
|
43
|
+
user: foo@bar.com
|
44
|
+
key: 12351
|
45
|
+
from: server1@staging.yourdomain.com
|
46
|
+
|
47
|
+
Then the command line is a little more terse and similar to unix mail:
|
33
48
|
|
49
|
+
sg_mail mail -f devops@yourco.com -t hank@mydomain.com -s "Database Backup complete!" -b "`cat /var/log/db.log`"
|
34
50
|
|
35
51
|
## Contributing
|
36
52
|
|
data/bin/sg_mail
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
+
require 'sendgrid_toolkit'
|
4
|
+
require "thor"
|
5
|
+
require 'yaml'
|
6
|
+
require 'sendgrid_cli_mailer'
|
7
|
+
|
8
|
+
class SendgridCliMailerCommand < Thor
|
9
|
+
desc "mail", "Sends an email via SendGrid API, will attempt to read user, key and from address from ~/.sg_mail"
|
10
|
+
method_option :user, :aliases => "-u", :desc => "SendGrid API User", :required => false
|
11
|
+
method_option :key, :aliases => "-k", :desc => "SendGrid API key", :required => false
|
12
|
+
method_option :to, :aliases => "-t", :desc => "Email 'to' address", :required => true
|
13
|
+
method_option :from, :aliases => "-f", :desc => "Email 'from' address", :required => false
|
14
|
+
method_option :subject, :aliases => "-s", :desc => "Email 'subject'", :required => true
|
15
|
+
method_option :body, :aliases => "-b", :desc => "Email 'body'", :required => false
|
16
|
+
def mail
|
17
|
+
mailer_settings = {}
|
18
|
+
sg_dotfile = File.join(File.expand_path('~'),".sg_mail")
|
19
|
+
if File.exists?(sg_dotfile)
|
20
|
+
mailer_settings = YAML.load_file sg_dotfile
|
21
|
+
else
|
22
|
+
mailer_settings['user'] = options[:user]
|
23
|
+
mailer_settings['key'] = options[:key]
|
24
|
+
mailer_settings['from'] = options[:from]
|
25
|
+
end
|
26
|
+
unless(mailer_settings['user'] && mailer_settings['key'] && mailer_settings['from'])
|
27
|
+
raise "Not all arguments supplied or .sg_mail doesn't have user,key and from"
|
28
|
+
end
|
29
|
+
body = options[:body] || "No Message Body"
|
30
|
+
|
31
|
+
::SendgridCliMailer::Runner.new(mailer_settings,options,body)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
SendgridCliMailerCommand.start
|
35
|
+
|
data/lib/sendgrid_cli_mailer.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
require "sendgrid_cli_mailer/version"
|
2
2
|
module SendgridCliMailer
|
3
3
|
#other code can go here
|
4
|
+
class Runner
|
5
|
+
def initialize(mailer_settings,options,body)
|
6
|
+
SendgridToolkit::Mail.new(mailer_settings['user'], mailer_settings['key']).send_mail :to => options[:to], :from => mailer_settings['from'],
|
7
|
+
:subject => options[:subject], :text => body
|
8
|
+
end
|
9
|
+
end
|
4
10
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid_cli_mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sendgrid_toolkit
|
@@ -47,7 +47,7 @@ description: Simple CLI mailer for Sendgrid via API
|
|
47
47
|
email:
|
48
48
|
- hbeaver@gmail.com
|
49
49
|
executables:
|
50
|
-
-
|
50
|
+
- sg_mail
|
51
51
|
extensions: []
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
@@ -56,7 +56,7 @@ files:
|
|
56
56
|
- LICENSE
|
57
57
|
- README.md
|
58
58
|
- Rakefile
|
59
|
-
- bin/
|
59
|
+
- bin/sg_mail
|
60
60
|
- lib/sendgrid_cli_mailer.rb
|
61
61
|
- lib/sendgrid_cli_mailer/version.rb
|
62
62
|
- sendgrid_cli_mailer.gemspec
|
data/bin/sg_cli
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
-
require 'sendgrid_toolkit'
|
4
|
-
require "thor"
|
5
|
-
|
6
|
-
class SendgridCliMailerCommand < Thor
|
7
|
-
desc "mail", "Sends an email via SendGrid API"
|
8
|
-
method_option :user, :aliases => "-u", :desc => "SendGrid API User", :required => true
|
9
|
-
method_option :key, :aliases => "-k", :desc => "SendGrid API key", :required => true
|
10
|
-
method_option :to, :aliases => "-t", :desc => "Email 'to' address", :required => true
|
11
|
-
method_option :from, :aliases => "-f", :desc => "Email 'from' address", :required => true
|
12
|
-
method_option :subject, :aliases => "-s", :desc => "Email 'subject'", :required => true
|
13
|
-
method_option :body, :aliases => "-b", :desc => "Email 'body'", :required => false
|
14
|
-
def mail
|
15
|
-
body = options.body || "No Message Body"
|
16
|
-
SendgridToolkit::Mail.new(options[:user], options[:key]).send_mail :to => options[:to], :from => options[:from],
|
17
|
-
:subject => options[:subject], :text => body
|
18
|
-
end
|
19
|
-
end
|
20
|
-
SendgridCliMailerCommand.start
|
21
|
-
|