mailgun-sendmail 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mailgun-sendmail.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 hogelog
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # Mailgun::Sendmail
2
+
3
+ Provide send mail command by Mailgun API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mailgun-sendmail'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mailgun-sendmail
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ $ mailgun-sendmail --setup
23
+ edit your Mailgun config
24
+ $ mailgun-sendmail
25
+ Usage:
26
+ mailgun-sendmail [options] mail_from mail_to title
27
+
28
+ Options:
29
+ --setup, -s: Setup Mailgun Account
30
+ --attach, -a <s>: Attachment file
31
+ --help, -h: Show this message
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it ( http://github.com/hogelog/mailgun-sendmail/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'trollop'
5
+ require 'mailgun-sendmail'
6
+
7
+ opts_parser = Trollop::Parser.new do
8
+ banner <<-HELP
9
+ Usage:
10
+ mailgun-sendmail [options] mail_from mail_to title
11
+
12
+ Options:
13
+ HELP
14
+
15
+ opt :setup, 'Setup Mailgun Account'
16
+ opt :attach, 'Attachment file', :type => String, :default => nil
17
+ end
18
+
19
+ opts = Trollop::with_standard_exception_handling opts_parser do
20
+ opts_parser.parse(ARGV)
21
+ end
22
+
23
+ mail_from, mail_to, title = *ARGV
24
+
25
+ if opts[:setup]
26
+ Mailgun::Sendmail.setup
27
+ puts "Mailgun account setup finished."
28
+ elsif !mail_from || !mail_to || !title
29
+ opts_parser.educate
30
+ else
31
+ body = STDIN.read
32
+ puts "Sending mail to #{mail_to}...",
33
+ Mailgun::Sendmail.mail(mail_from, mail_to, title, body, opts[:attach])
34
+ end
@@ -0,0 +1,39 @@
1
+ require "mailgun-sendmail/version"
2
+ require "rest-client"
3
+ require "pit"
4
+
5
+ module Mailgun
6
+ class Sendmail
7
+ def self.setup
8
+ Pit.get("mailgun-sendmail", :require => {
9
+ "api_key" => "Your mailgun API Key",
10
+ "domain" => "Your mailgun domain",
11
+ })
12
+ end
13
+
14
+ def self.mail(*args)
15
+ config = setup
16
+ sendmail = Sendmail.new(config['api_key'], config['domain'])
17
+ sendmail.mail(*args)
18
+ end
19
+
20
+ def initialize(api_key, domain)
21
+ @api_key = api_key
22
+ @domain = domain
23
+ end
24
+
25
+ def mail(mail_from, mail_to, title, body, attachment=nil)
26
+ api_url = "https://api:#@api_key@api.mailgun.net/v2/#@domain/messages"
27
+
28
+ options = {
29
+ :from => mail_from,
30
+ :to => mail_to,
31
+ :subject => title,
32
+ :text => body,
33
+ }
34
+ options[:attachment] = File.new(attachment, "rb") if attachment
35
+
36
+ RestClient.post(api_url, options)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module Mailgun
2
+ class Sendmail
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mailgun-sendmail/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mailgun-sendmail"
8
+ spec.version = Mailgun::Sendmail::VERSION
9
+ spec.authors = ["hogelog"]
10
+ spec.email = ["konbu.komuro@gmail.com"]
11
+ spec.summary = %q{sendmail by Mailgun API}
12
+ spec.description = %q{Provide send mail command by Mailgun API}
13
+ spec.homepage = "https://github.com/hogelog/mailgun-sendmail"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "pit"
22
+ spec.add_dependency "rest-client"
23
+ spec.add_dependency "trollop"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.5"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "webmock"
30
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ describe Mailgun::Sendmail do
4
+ describe "#mail" do
5
+ let(:sendmail) { Mailgun::Sendmail.new('api_key', 'domain') }
6
+ let(:api_url) { "https://api:api_key@api.mailgun.net/v2/domain/messages" }
7
+ it "posts /messages api" do
8
+ WebMock.stub_request(:post, api_url)
9
+ sendmail.mail('from@example.com', 'to@example.com', 'title', 'message')
10
+ expect(WebMock).to have_requested(:post, api_url)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'pry'
3
+ require 'webmock/rspec'
4
+ require 'mailgun-sendmail'
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailgun-sendmail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - hogelog
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pit
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rest-client
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: trollop
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.5'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.5'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: pry
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: webmock
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: Provide send mail command by Mailgun API
143
+ email:
144
+ - konbu.komuro@gmail.com
145
+ executables:
146
+ - mailgun-sendmail
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - .gitignore
151
+ - .travis.yml
152
+ - Gemfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - bin/mailgun-sendmail
157
+ - lib/mailgun-sendmail.rb
158
+ - lib/mailgun-sendmail/version.rb
159
+ - mailgun-sendmail.gemspec
160
+ - spec/mailgun-sendmail_spec.rb
161
+ - spec/spec_helper.rb
162
+ homepage: https://github.com/hogelog/mailgun-sendmail
163
+ licenses:
164
+ - MIT
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ! '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ none: false
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ requirements: []
182
+ rubyforge_project:
183
+ rubygems_version: 1.8.23
184
+ signing_key:
185
+ specification_version: 3
186
+ summary: sendmail by Mailgun API
187
+ test_files:
188
+ - spec/mailgun-sendmail_spec.rb
189
+ - spec/spec_helper.rb