development_notification 0.0.4

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: 28d2600b70196fdd52b4dd3a38d76a498f854154
4
+ data.tar.gz: 84315114a54495fdc0c9a36bb1f94b19f9eb4b7e
5
+ SHA512:
6
+ metadata.gz: 24ab4a084fdfe87c0895f8d5aed0db373d00562fe358bf33294702e378cac17ecbe94518174ad6440c118f66f357cfb2c35835cb8bab6338716053d08e7cbe4a
7
+ data.tar.gz: 0470695a2cf9cb47343bc423601bc6431ea41f381cd155996d6b8ff426c70496e455fb06c34dbbaf455557e3ad2a95e2c91cc968c84bb9c9cded1df2637cfaae
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # DevelopmentNotification
2
+
3
+ ## Installation
4
+
5
+ Point to this repo (or a fork) and bundle
6
+ ```
7
+ gem 'development_notification', "0.1.0", git: 'https://github.com/CreativePublisher/development_notification', branch: 'master'
8
+ ```
9
+
10
+ Run migration
11
+ ```
12
+ $ rake db:migrate
13
+ ```
14
+
15
+ ## Configuration
16
+
17
+ ```ruby
18
+ # in /config/initializers/development_notification.rb
19
+ DevelopmentNotification.configure do |config|
20
+ config.leadersend_username = "email@example.com"
21
+ config.leadersend_api_key = "0933e545acxc063cb8a101a374cc721f"
22
+ config.domain = "example.com"
23
+ config.validate! # must be called in the very end.
24
+ end
25
+ ```
26
+
27
+ ## Usage
28
+ After setup you gain access to:
29
+ * DevelopmentNotification::Email model that logs email prepared and sent.
30
+ * DevelopmentNotification::Email.send_email(parameter_hash) #=> sends emails
31
+
32
+ ### Email sending
33
+ DevelopmentNotification::Email.send_email(title: "Systemside identifier", to: "dump@example.com", from: "creative@inbox.lv", fromname: "Creative", subject: "test", template: "html body")
34
+
35
+ ## Gotchas
36
+ * Engine uses smart migration inclusion, this works well in development, but production deployment that migrates selectively (like mina) may fail at detecting migrations. Be sure to __force migration__ in production.
37
+ * Sometimes production does not load the gem. Append `require: false` in gemfile, and add the line `require 'development_notification'` to `/config/application.rb`
38
+
39
+ ## Development
40
+ You need to configure the dummy app database in `spec/dummy/config/database.yml`
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'DevelopmentNotification'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
@@ -0,0 +1,38 @@
1
+ module DevelopmentNotification
2
+ class Email < ActiveRecord::Base
3
+ # def self.params
4
+ # return %i|title to_address subject body response status|
5
+ # end
6
+
7
+ validates :title, presence: true
8
+ validates :to_address, presence: true
9
+ validates :subject, presence: true
10
+ validates :status, presence: true
11
+
12
+ def self.send_email(title: nil, to: nil, from: nil, fromname: nil, subject: nil, template: nil, template_path: nil, locals: nil)
13
+
14
+ mailer = Leadersend::Mail.new(title: title, to: to, from: from, fromname: fromname, subject: subject, template: template)
15
+ leadersend_response_hash = mailer.send
16
+
17
+ mail_object = DevelopmentNotification::Email.create_from_leadersend_response_hash(leadersend_response_hash)
18
+
19
+ return mail_object
20
+
21
+ # TODO add differentiation based on template/template_path argument to use raw html or path accordingly.
22
+ end
23
+
24
+ # private
25
+
26
+ def self.statuses
27
+ ActiveSupport::HashWithIndifferentAccess.new(new: 0, sent: 1, error: 2)
28
+ end
29
+
30
+ def self.create_from_leadersend_response_hash(**hash)
31
+ hash[:status] = self.statuses[hash[:status]]
32
+ sent_mail = self.new(hash.symbolize_keys, :without_protection => true)
33
+ sent_mail.save
34
+ return sent_mail
35
+ end
36
+
37
+ end
38
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ DevelopmentNotification::Engine.routes.draw do
2
+ end
@@ -0,0 +1,14 @@
1
+ class CreateDevelopmentNotificationEmails < ActiveRecord::Migration
2
+ def change
3
+ create_table :development_notification_emails do |t|
4
+ t.string :title, index: true, null: false
5
+ t.string :to_address, index: true, null: false
6
+ t.string :subject, index: true, null: false
7
+ t.text :body
8
+ t.text :response
9
+ t.integer :status, index: true, null: false, default: 0
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,45 @@
1
+ require "development_notification/engine"
2
+ require 'leadersend'
3
+
4
+ module DevelopmentNotification
5
+
6
+ class << self
7
+ attr_accessor :config
8
+ end
9
+
10
+ def self.configure
11
+ self.config ||= Config.new
12
+ yield(config)
13
+ end
14
+
15
+ class Config
16
+ attr_accessor :leadersend_username, :leadersend_api_key, :domain
17
+
18
+ def validate!
19
+ raise ArgumentError.new("DevelopmentNotification did not receive all three configuration pieces!") unless @leadersend_username && @leadersend_api_key && @domain
20
+ Config.email_sending
21
+ return true
22
+ end
23
+
24
+ def self.email_sending
25
+ Leadersend.configure do |config|
26
+ config.username = DevelopmentNotification.config.leadersend_username
27
+ config.api_key = DevelopmentNotification.config.leadersend_api_key
28
+ end
29
+
30
+ ActionMailer::Base.smtp_settings = {
31
+ :address => Leadersend.config.host,
32
+ :port => '587',
33
+ :authentication => :plain,
34
+ :user_name => Leadersend.config.username,
35
+ :password => Leadersend.config.api_key,
36
+ :domain => DevelopmentNotification.config.domain
37
+ }
38
+
39
+ ActionMailer::Base.delivery_method = :smtp
40
+ ActionMailer::Base.default_url_options[:host] = DevelopmentNotification.config.domain
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,19 @@
1
+ module DevelopmentNotification
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace DevelopmentNotification
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec
7
+ g.integration_tool :rspec
8
+ end
9
+
10
+ initializer :append_migrations do |app|
11
+ unless app.root.to_s == root.to_s
12
+ config.paths["db/migrate"].expanded.each do |expanded_path|
13
+ app.config.paths["db/migrate"] << expanded_path
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module DevelopmentNotification
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :development_notification do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: development_notification
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Creative
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: leadersend
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pg
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_girl_rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: dotenv-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Enables sending simple emails to app owners. Wraps [Leadersend](http://www.leadersend.com)
112
+ mail delivery service and defines a DevelopmentNotification::Email model for logging.
113
+ email:
114
+ - hi@creative.gs
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - MIT-LICENSE
120
+ - README.md
121
+ - Rakefile
122
+ - app/models/development_notification/email.rb
123
+ - config/routes.rb
124
+ - db/migrate/20151106101824_create_development_notification_emails.rb
125
+ - lib/development_notification.rb
126
+ - lib/development_notification/engine.rb
127
+ - lib/development_notification/version.rb
128
+ - lib/tasks/development_notification_tasks.rake
129
+ homepage: http://creative.gs/
130
+ licenses: []
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.4.6
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Allow your rails app to send emails to dev team.
152
+ test_files: []