circuit_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27fa28d9036f01f15a25b9ad3cce938585159a76
4
+ data.tar.gz: 742f7713e8f5b6abb88af1ea18f8bb8e59024349
5
+ SHA512:
6
+ metadata.gz: dec4fa01974e4e0a925282223ac5608f6d1b68554131eee52c31b65ca8bdc524d81a5ccee053363c1e6c7c351fa623985f3195666f77046f7fd7c54b80b90229
7
+ data.tar.gz: '08433f1112da200b1dc64b5dbfc546a94e0db135c108819cda65583405bb668778e84743f4ae61d213df36771b5db8310f45fe396ffd7446d24b60f2d8047058'
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
@@ -0,0 +1,53 @@
1
+ [![Gem Version](https://badge.fury.io/rb/circuit_rails.svg)](https://badge.fury.io/rb/circuit_rails)
2
+
3
+ # circuit\_rails
4
+
5
+ *circuit_rails* is an Action Mailer adapter for sending messages to Circuit from Rails apps.
6
+ It uses the [Circuit REST API](https://circuitsandbox.net/rest/v2/swagger/ui/index.html) thru the [circuit\_client](https://github.com/benningm/circuit_client) gem.
7
+
8
+ ## Installing
9
+
10
+ In your `Gemfile`
11
+
12
+ ```ruby
13
+ gem 'circuit_rails'
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ In your environment configuration (development.rb, production.rb, ...) configure circuit settings:
19
+
20
+ ```ruby
21
+ config.action_mailer.circuit_settings = {
22
+ client_id: '<your client_id>',
23
+ client_secret: '<your client_secret>',
24
+ }
25
+ ```
26
+
27
+ If you want to set it as default delivery\_method:
28
+
29
+ ```ruby
30
+ config.action_mailer.delivery_method = :circuit
31
+ ```
32
+
33
+ Or create a base class for circuit mailers:
34
+
35
+ ```ruby
36
+ # apps/mailers/circuit_mailer.rb
37
+ class CircuitMailer < ApplicationMailer
38
+ self.delivery_method = :circuit
39
+ # default conversation: '<your default conversation>'
40
+ end
41
+ ```
42
+
43
+ Then use this class in your mailers:
44
+
45
+ ```ruby
46
+ # apps/mailers/hello_world_mailer.rb
47
+ class HelloWorldMailer < CircuitMailer
48
+ def hello_world
49
+ mail(subject: 'Hello World!', conversation: '<convId>')
50
+ end
51
+ end
52
+ ```
53
+
@@ -0,0 +1,14 @@
1
+ require 'rake/clean'
2
+ require 'rubygems'
3
+ require 'rubygems/package_task'
4
+ require 'rdoc/task'
5
+
6
+ spec = eval(File.read('circuit_rails.gemspec'))
7
+ Gem::PackageTask.new(spec) do |pkg|
8
+ end
9
+
10
+ Rake::RDocTask.new do |rd|
11
+ rd.rdoc_files.include("lib/**/*.rb")
12
+ rd.title = 'Action Mailer adapter for using Circuit in Rails apps.'
13
+ end
14
+
@@ -0,0 +1,9 @@
1
+
2
+ require 'circuit_rails/mail_ext'
3
+ require 'circuit_rails/delivery_method'
4
+
5
+ require 'circuit_rails/action_mailer' if defined?(Rails)
6
+
7
+ module CircuitRails
8
+ end
9
+
@@ -0,0 +1,3 @@
1
+ require 'action_mailer'
2
+
3
+ ActionMailer::Base.add_delivery_method :circuit, CircuitRails::DeliveryMethod
@@ -0,0 +1,38 @@
1
+ require 'circuit_client'
2
+
3
+ module CircuitRails
4
+ class DeliveryMethod
5
+ class MissingParameter < StandardError ; end
6
+
7
+ attr_accessor :settings
8
+
9
+ DEFAULTS = {
10
+ :host => 'eu.yourcircuit.com',
11
+ :client_id => nil,
12
+ :client_secret => nil,
13
+ :default_conversation => nil,
14
+ }
15
+
16
+ def initialize(values)
17
+ self.settings = DEFAULTS.merge(values)
18
+ end
19
+
20
+ def client
21
+ @client ||= CircuitClient::Client.new do |c|
22
+ c.host = settings[:host]
23
+ c.client_id = settings[:client_id]
24
+ c.client_secret = settings[:client_secret]
25
+ end
26
+ end
27
+
28
+ def deliver!(mail)
29
+ conv = mail.conversation || settings[:default_conversation]
30
+ raise MissingParameter, "a conversation or default_conversation is required for circuit delivery!" if conv.nil?
31
+ body = mail.multipart? ? mail.text_part.body.decoded : mail.body.decoded
32
+ options = {}
33
+ options[:subject] = mail.subject unless mail.subject.nil?
34
+ client.create_message(conv, body, **options)
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,12 @@
1
+
2
+ module Mail
3
+ class Message
4
+ def conversation( val = nil )
5
+ default :conversation, val
6
+ end
7
+ def conversation=( val )
8
+ header[:conversation] = val
9
+ end
10
+ end
11
+ end
12
+
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: circuit_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Markus Benning
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aruba
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: circuit_client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email: ich@markusbenning.de
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - Gemfile
76
+ - README.md
77
+ - Rakefile
78
+ - lib/circuit_rails.rb
79
+ - lib/circuit_rails/action_mailer.rb
80
+ - lib/circuit_rails/delivery_method.rb
81
+ - lib/circuit_rails/mail_ext.rb
82
+ homepage: https://github.com/benningm/circuit_rails
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.6.8
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Action Mailer adapter for using Circuit in Rails apps.
107
+ test_files: []