snipe 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c7ce8078d54c22c52088df0a148c85032df3d7fc
4
+ data.tar.gz: 32a79637eef715ffc36eec5257a5bbc1aa151c0a
5
+ SHA512:
6
+ metadata.gz: 424594ca4a87919147f8fe3f174291f63d2b6feac85ca2da0035692c72b0c5fa210aa9bec0b8b504928694cf346583f003f720a5351a5531840ddca5e3f93929
7
+ data.tar.gz: 234955bd85995130cf0308fce07af8c781bf57fd42772c5de9aa765271cc51da4ce180740998a4509632cf5c00910871b56271654511a85380c8fa6aaf2712dc
data/.editorconfig ADDED
@@ -0,0 +1,13 @@
1
+ # editorconfig.org
2
+
3
+ root = true
4
+
5
+ [*]
6
+ charset = utf-8
7
+ indent_size = 2
8
+ indent_style = space
9
+ insert_final_newline = true
10
+ trim_trailing_whitespace = true
11
+
12
+ [*.md]
13
+ trim_trailing_whitespace = false
data/.gitbugtraq ADDED
@@ -0,0 +1,3 @@
1
+ [bugtraq "pivotal"]
2
+ url = https://www.pivotaltracker.com/story/show/%BUGID%
3
+ logRegex = (\\b\\d{8}\\b)
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ .DS_Store
2
+
3
+ *.gem
4
+ *.rbc
5
+ /.config
6
+ /coverage/
7
+ /InstalledFiles
8
+ /pkg/
9
+ /spec/reports/
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ ## Specific to RubyMotion:
15
+ .dat*
16
+ .repl_history
17
+ build/
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalisation:
26
+ /.bundle/
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,79 @@
1
+ # This is the configuration used to check the rubocop source code.
2
+
3
+ AllCops:
4
+ DisplayCopNames: true
5
+ Exclude:
6
+ - 'resources/*'
7
+ - 'pkg/*'
8
+ - 'docs/*'
9
+ - 'spec/spec_helper.rb'
10
+ - 'spec/fixtures/**/*'
11
+
12
+ Style/RescueModifier:
13
+ Enabled: false
14
+
15
+ Lint/EndAlignment:
16
+ Enabled: false
17
+
18
+ Metrics/MethodLength:
19
+ Enabled: false
20
+
21
+ Metrics/LineLength:
22
+ Enabled: false
23
+
24
+ Style/EachWithObject:
25
+ Enabled: false
26
+
27
+ Style/Documentation:
28
+ Enabled: false
29
+
30
+ Style/GuardClause:
31
+ Enabled: false
32
+
33
+ Style/RedundantReturn:
34
+ Enabled: false
35
+
36
+ Style/SpaceBeforeBlockBraces:
37
+ Enabled: false
38
+
39
+ Style/StringLiterals:
40
+ Enabled: false
41
+
42
+ Style/TrailingWhitespace:
43
+ Enabled: false
44
+
45
+ Metrics/AbcSize:
46
+ Enabled: false
47
+
48
+ Metrics/ClassLength:
49
+ Enabled: false
50
+
51
+ Style/ElseAlignment:
52
+ Enabled: false
53
+
54
+ Style/HashSyntax:
55
+ Enabled: false
56
+
57
+ Style/MultilineOperationIndentation:
58
+ Enabled: false
59
+
60
+ Style/Semicolon:
61
+ AllowAsExpressionSeparator: true
62
+
63
+ Style/IndentationWidth:
64
+ Enabled: false
65
+
66
+ Style/SingleLineBlockParams:
67
+ Enabled: false
68
+
69
+ Metrics/CyclomaticComplexity:
70
+ Max: 10
71
+
72
+ Metrics/PerceivedComplexity:
73
+ Max: 8
74
+
75
+ Style/FileName:
76
+ Enabled: false
77
+
78
+ Style/SpecialGlobalVars:
79
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## Releases
2
+
3
+ ## 1.0.0
4
+
5
+ - Initial Release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ snipe (1.0.0)
5
+ claide (~> 0.8, >= 0.8.0)
6
+ colored (~> 1.2)
7
+ highline (~> 1.7, >= 1.7.8)
8
+ mailgun-ruby (~> 1.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ claide (0.9.1)
14
+ colored (1.2)
15
+ domain_name (0.5.20160310)
16
+ unf (>= 0.0.5, < 1.0.0)
17
+ highline (1.7.8)
18
+ http-cookie (1.0.2)
19
+ domain_name (~> 0.5)
20
+ json (1.8.3)
21
+ mailgun-ruby (1.1.0)
22
+ json (~> 1.8)
23
+ rest-client (~> 1.6)
24
+ mime-types (2.99.1)
25
+ netrc (0.11.0)
26
+ rake (10.5.0)
27
+ rest-client (1.8.0)
28
+ http-cookie (>= 1.0.2, < 2.0)
29
+ mime-types (>= 1.16, < 3.0)
30
+ netrc (~> 0.7)
31
+ unf (0.1.4)
32
+ unf_ext
33
+ unf_ext (0.0.7.2)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler (~> 1.7)
40
+ rake (~> 10.0)
41
+ snipe!
42
+
43
+ BUNDLED WITH
44
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Michaël Fortin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # snipe
2
+
3
+ [![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/fortinmike/snipe/blob/master/LICENSE)
4
+
5
+ Easily send one-off emails from scripts using MailGun
6
+
7
+ ## Installation
8
+
9
+ snipe is distributed as a cross-platform Ruby Gem:
10
+
11
+ $ gem install snipe
12
+
13
+ # Usage
14
+
15
+ 1. Configure snipe (first time only):
16
+
17
+ $ snipe init
18
+
19
+ 2. Send emails
20
+
21
+ $ echo "Hello snipe!" | snipe --target="someone@domain.com"
22
+ $ snipe --target=someone@domain.com --message="Hello mister!"
23
+ $ snipe -to=someone@domain.com -m="Hello mister!"
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/snipe ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "claide"
4
+ require "snipe/commands/commands"
5
+
6
+ Snipe::Command.run(ARGV)
@@ -0,0 +1,72 @@
1
+ require "claide"
2
+ require "mailgun"
3
+
4
+ require "snipe/snipe_exception"
5
+ require "snipe/info"
6
+ require "snipe/logic/config"
7
+
8
+ module Snipe
9
+ class Command < CLAide::Command
10
+ self.command = "snipe"
11
+ self.version = VERSION
12
+ self.description = DESCRIPTION
13
+
14
+ def self.options
15
+ [
16
+ ['--target|--to', 'The address to send the email to'],
17
+ ['--message', 'A message to send'],
18
+ ['[--subject]', 'Derived from the message by default'],
19
+ ['[--from]', 'Override the default "from" address'],
20
+ ].concat(super)
21
+ end
22
+
23
+ def initialize(argv)
24
+ assert_configured!
25
+
26
+ config = Config.new
27
+ config.load
28
+
29
+ @api_key = config.api_key
30
+ @domain = config.domain
31
+ @from = argv.option("f") || argv.option("from") || config.from
32
+ @to = argv.option("t") || argv.option("to") || argv.option("target")
33
+ @message = argv.option("message")
34
+ @subject = argv.option("subject") || create_subject(@message)
35
+
36
+ super
37
+ end
38
+
39
+ def run
40
+ client = Mailgun::Client.new(@api_key)
41
+ params = { from: @from, to: @to, subject: @subject, text: @message }
42
+ response = client.send_message(@domain, params)
43
+
44
+ output_message = response.code == 200 ? "Email Sent" : "Error"
45
+ body = JSON.parse(response.body)
46
+ puts "[#{response.code}] #{output_message} : #{body["message"]}"
47
+ end
48
+
49
+ def assert_configured!
50
+ fail SnipeException, "Run `snipe init` first!" unless Config.exists?
51
+ end
52
+
53
+ def validate!
54
+ help! "You must provide a valid `--from`" unless Validate.email!(@from)
55
+ help! "You must provide a valid `--target`" unless Validate.email!(@to)
56
+ help! "You must provide a `--message`" unless @message
57
+ end
58
+
59
+ def create_subject(message)
60
+ return nil unless message
61
+ message.split(" ").take(8).join(" ")
62
+ end
63
+
64
+ def self.report_error(exception)
65
+ if exception.instance_of?(SnipeException)
66
+ puts exception.message
67
+ exit 1
68
+ end
69
+ fail exception
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,2 @@
1
+ require_relative "command"
2
+ require_relative "init_command"
@@ -0,0 +1,34 @@
1
+ require "highline"
2
+ require "snipe/logic/config"
3
+ require "snipe/logic/validate"
4
+
5
+ module Snipe
6
+ class InitCommand < Command
7
+ self.command = "init"
8
+ self.summary = "Configures snipe for sending email"
9
+
10
+ def initialize(argv)
11
+ # Prevent super from initializing stuff
12
+ end
13
+
14
+ def validate!
15
+ # Prevent super from validating stuff
16
+ end
17
+
18
+ def run
19
+ config = Config.new
20
+ cli = HighLine.new
21
+
22
+ config.api_key = cli.ask("MailGun API Key?")
23
+ config.domain = cli.ask("Sending Domain?")
24
+ config.from = cli.ask("Default \"From\" Address?") { |q|
25
+ q.validate = Validate::EMAIL_REGEX
26
+ # TODO: Better response on validation error
27
+ }
28
+
29
+ config.save
30
+
31
+ puts "All done! You can now send email with snipe."
32
+ end
33
+ end
34
+ end
data/lib/snipe/info.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Snipe
2
+ NAME = "snipe"
3
+ VERSION = "1.0.0"
4
+ DESCRIPTION = "Easily send one-off emails from scripts using MailGun"
5
+ SUMMARY = DESCRIPTION
6
+ end
@@ -0,0 +1,36 @@
1
+ require 'fileutils'
2
+ require 'psych'
3
+
4
+ module Snipe
5
+ class Config
6
+ FILE = File.expand_path("~/.snipe")
7
+
8
+ attr_accessor :api_key
9
+ attr_accessor :domain
10
+ attr_accessor :from
11
+
12
+ def self.exists?
13
+ File.exists?(FILE)
14
+ end
15
+
16
+ def load
17
+ yaml = File.read(FILE)
18
+ loaded = Psych.load(yaml)
19
+
20
+ @api_key = loaded["api_key"]
21
+ @domain = loaded["domain"]
22
+ @from = loaded["from"]
23
+ end
24
+
25
+ def save
26
+ to_save = {
27
+ "api_key" => @api_key,
28
+ "domain" => @domain,
29
+ "from" => @from
30
+ }
31
+
32
+ yaml = Psych.dump(to_save)
33
+ File.write(FILE, yaml)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,9 @@
1
+ module Snipe
2
+ class Validate
3
+ EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
4
+
5
+ def self.email!(email)
6
+ EMAIL_REGEX =~ email
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ require "claide/informative_error"
2
+
3
+ module Snipe
4
+ class SnipeException < StandardError
5
+ end
6
+ end
data/snipe.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "snipe/info"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = Snipe::NAME
8
+ spec.version = Snipe::VERSION
9
+ spec.authors = ["Michaël Fortin"]
10
+ spec.email = ["fortinmike@irradiated.net"]
11
+ spec.summary = Snipe::SUMMARY
12
+ spec.description = Snipe::DESCRIPTION
13
+ spec.homepage = "https://github.com/fortinmike/snipe"
14
+ spec.license = "MIT"
15
+
16
+ spec.required_ruby_version = "~> 2.0"
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+
25
+ spec.add_runtime_dependency "claide", "~> 0.8", ">= 0.8.0"
26
+ spec.add_runtime_dependency "colored", "~> 1.2"
27
+ spec.add_runtime_dependency "highline", "~> 1.7", ">= 1.7.8"
28
+ spec.add_runtime_dependency "mailgun-ruby", "~> 1.1"
29
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: snipe
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Michaël Fortin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: claide
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.8.0
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '0.8'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.8.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: colored
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.2'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.2'
75
+ - !ruby/object:Gem::Dependency
76
+ name: highline
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.7'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 1.7.8
85
+ type: :runtime
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '1.7'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 1.7.8
95
+ - !ruby/object:Gem::Dependency
96
+ name: mailgun-ruby
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '1.1'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '1.1'
109
+ description: Easily send one-off emails from scripts using MailGun
110
+ email:
111
+ - fortinmike@irradiated.net
112
+ executables:
113
+ - snipe
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - ".editorconfig"
118
+ - ".gitbugtraq"
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".rubocop.yml"
122
+ - CHANGELOG.md
123
+ - Gemfile
124
+ - Gemfile.lock
125
+ - LICENSE
126
+ - README.md
127
+ - Rakefile
128
+ - bin/snipe
129
+ - lib/snipe/.DS_Store
130
+ - lib/snipe/commands/.DS_Store
131
+ - lib/snipe/commands/command.rb
132
+ - lib/snipe/commands/commands.rb
133
+ - lib/snipe/commands/init_command.rb
134
+ - lib/snipe/info.rb
135
+ - lib/snipe/logic/config.rb
136
+ - lib/snipe/logic/validate.rb
137
+ - lib/snipe/snipe_exception.rb
138
+ - snipe.gemspec
139
+ homepage: https://github.com/fortinmike/snipe
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '2.0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.5.1
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Easily send one-off emails from scripts using MailGun
163
+ test_files: []