tramway-mailout 0.1.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
+ SHA256:
3
+ metadata.gz: 15bec9d36e4eda7dd77e9a3d7aa8866ef9774d89cf86166b5d33971344c0161e
4
+ data.tar.gz: 79b27fe49ab81bf845a88a10aa0617c660fecc9b70d8c53ff8949fc0e59dd90e
5
+ SHA512:
6
+ metadata.gz: 45122b076125a1224e82226fc3ae6669b38617904456562cda6819c0211a27e3856c871fb18d388f8bccd61cfd84caa7d46970daf404e45c4ce21cf2aa6083e4
7
+ data.tar.gz: 49cb42cc4a99f2e028cf2afd653ca3077f0f8eacb8d5ff57e1392d63c4bf5b7e84ac2a29f0f4efa0a80aec7f80c7af080b696a7321ef5823a002034992c2eeb1
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Pavel Kalashnikov
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,28 @@
1
+ # Tramway::Mailout
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'tramway-mailout'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install tramway-mailout
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,36 @@
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 = 'Tramway::Mailout'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/tramway/mailout .js
2
+ //= link_directory ../stylesheets/tramway/mailout .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,2 @@
1
+ class Tramway::Mailout::ApplicationCable::Channel < ActionCable::Channel::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class Tramway::Mailout::ApplicationCable::Connection < ActionCable::Connection::Base
2
+ end
@@ -0,0 +1,7 @@
1
+ module Tramway
2
+ module Mailout
3
+ class ApplicationController < ActionController::Base
4
+ protect_from_forgery with: :exception
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ class Tramway::Mailout::SessionForm < ::Tramway::Core::ApplicationForm
2
+ properties :campaign_id, :campaign_type, :mailing_state, :mailing_state_event
3
+ end
@@ -0,0 +1,6 @@
1
+ module Tramway
2
+ module Mailout
3
+ module ApplicationHelper
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Tramway
2
+ module Mailout
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ class Tramway::Mailout::MailingJob < ActiveJob::Base
2
+ queue_as :default
3
+
4
+ def perform(contacts, template, mailer, &block)
5
+ contacts.each_slice(100) do |combination|
6
+ combination.each do |contact|
7
+ mailer.constantize.delay.send :just_message, contact.email, template.title, template.body
8
+ yield if block_given?
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module Tramway
2
+ module Mailout
3
+ class ApplicationMailer < ActionMailer::Base
4
+ def just_message(email, title, body)
5
+ @body = body
6
+ mail from: sender_name, to: email, subject: title
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,42 @@
1
+ require 'tramway/mailout/job_proxy'
2
+
3
+ module Tramway::Mailout
4
+ class Session < ::Tramway::Core::ApplicationRecord
5
+ belongs_to :campaign, polymorphic: true
6
+
7
+ state_machine :mailing_state, initial: :ready, namespace: :mailing do
8
+ state :during
9
+ state :completed
10
+ state :aborted
11
+
12
+ event :start do
13
+ transition ready: :during
14
+ end
15
+
16
+ event :repeat do
17
+ transition completed: :ready
18
+ end
19
+
20
+ event :abort do
21
+ transition during: :aborted
22
+ end
23
+
24
+ event :continue do
25
+ transition aborted: :during
26
+ end
27
+
28
+ after_transition ready: :during do
29
+ end
30
+
31
+ after_transition aborted: :during do |session|
32
+ ::Tramway::Mailout::JobProxy.perform_job ::Tramway::Mailout::MailingJob,
33
+ :later,
34
+ session.campaign.contacts,
35
+ session.campaign.strategy.touches.first.mail_template,
36
+ ::Tramway::Mailout::ApplicationMailer
37
+ end
38
+ end
39
+
40
+ scope :during, -> { active.where mailing_state: :during }
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ ru:
2
+ activerecord:
3
+ state_machines:
4
+ tramway/mailout/session:
5
+ mailing_state:
6
+ states:
7
+ ready: Готово к рассылке
8
+ during: В процессе рассылки
9
+ completed: Рассылка окончена
10
+ aborted: Рассылка прервана
11
+ events:
12
+ start: Начать рассылку
13
+ repeat: Повторить рассылку
14
+ abort: Прервать рассылку
15
+ continue: Продолжить рассылку
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Tramway::Mailout::Engine.routes.draw do
2
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :tramway_mailout do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,10 @@
1
+ require 'sidekiq'
2
+
3
+ module Tramway
4
+ module Mailout
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace Tramway::Mailout
7
+ ::Sidekiq::Extensions.enable_delay!
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,22 @@
1
+ require 'rails/generators'
2
+ require 'tramway/core/generators/install_generator'
3
+
4
+ module Tramway::Mailout::Generators
5
+ class InstallGenerator < ::Tramway::Core::Generators::InstallGenerator
6
+ include Rails::Generators::Migration
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ def run_other_generators
10
+ generate 'tramway:core:install'
11
+ end
12
+
13
+ def self.next_migration_number(path)
14
+ next_migration_number = current_migration_number(path) + 1
15
+ ActiveRecord::Migration.next_migration_number next_migration_number
16
+ end
17
+
18
+ def copy_migrations
19
+ migration_template 'create_tramway_mailout_sessions.rb', 'db/migrate/create_tramway_mailout_sessions.rb'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ class CreateTramwayMailoutSessions < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :tramway_mailout_sessions do |t|
4
+ t.integer :campaign_id
5
+ t.text :state
6
+ t.text :mailing_state, default: :ready
7
+ t.text :campaign_type
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module Tramway::Mailout::JobProxy
2
+ class << self
3
+ def perform_job(job_class, mode, *args)
4
+ job_class.send "perform_#{mode}", *args.map { |a| convert a }
5
+ end
6
+
7
+ private
8
+
9
+ def convert(object)
10
+ if object.class.to_s.include? 'ActiveRecord_Associations_CollectionProxy'
11
+ object.to_a
12
+ elsif object.class == Class
13
+ object.to_s
14
+ else
15
+ object
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module Tramway
2
+ module Mailout
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require "tramway/mailout/engine"
2
+ require 'tramway/mailout/generates/install_generator'
3
+ require 'tramway/mailout/job_proxy'
4
+
5
+ module Tramway
6
+ module Mailout
7
+ # Your code goes here...
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tramway-mailout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pavel Kalashnikov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-02 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: 5.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: sidekiq
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Rails Engine for your mailouts
42
+ email:
43
+ - kalashnikovisme@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - app/assets/config/tramway_mailout_manifest.js
52
+ - app/assets/javascripts/tramway/mailout/application.js
53
+ - app/assets/stylesheets/tramway/mailout/application.css
54
+ - app/channels/tramway/mailout/application_cable/channel.rb
55
+ - app/channels/tramway/mailout/application_cable/connection.rb
56
+ - app/controllers/tramway/mailout/application_controller.rb
57
+ - app/forms/tramway/mailout/session_form.rb
58
+ - app/helpers/tramway/mailout/application_helper.rb
59
+ - app/jobs/tramway/mailout/application_job.rb
60
+ - app/jobs/tramway/mailout/mailing_job.rb
61
+ - app/mailers/tramway/mailout/application_mailer.rb
62
+ - app/models/tramway/mailout/session.rb
63
+ - config/locales/state_machines.yml
64
+ - config/routes.rb
65
+ - lib/tasks/tramway/mailout_tasks.rake
66
+ - lib/tramway/mailout.rb
67
+ - lib/tramway/mailout/engine.rb
68
+ - lib/tramway/mailout/generates/install_generator.rb
69
+ - lib/tramway/mailout/generates/templates/create_tramway_mailout_sessions.rb
70
+ - lib/tramway/mailout/job_proxy.rb
71
+ - lib/tramway/mailout/version.rb
72
+ homepage: https://github.com/kalashnikovisme/tramway-mailout
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.7.3
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Rails Engine for your mailouts
96
+ test_files: []