griddler 1.0.0.pre.alpha.2 → 1.0.0.pre.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/griddler/emails_controller.rb +13 -2
- data/lib/griddler.rb +0 -9
- data/lib/griddler/configuration.rb +2 -25
- data/lib/griddler/email.rb +5 -17
- data/lib/griddler/email_parser.rb +1 -1
- data/lib/griddler/testing.rb +33 -1
- data/lib/griddler/version.rb +1 -1
- metadata +16 -4
- data/lib/griddler/adapters/cloudmailin_adapter.rb +0 -34
- data/lib/griddler/adapters/postmark_adapter.rb +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5db84495ea1dd75d93ad77af6b7b345471658418
|
4
|
+
data.tar.gz: ab4522dd7709770a8fa825c1328a034fc42abe8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3a1251948e7b861c2fea3ba5e526a90c14dbe352ab9b00d64dacb18fb9cd0a3e3dd77f3a910ed0f709eb9802ef81a031dbe624d4392902d1bb6877df04ca6d3
|
7
|
+
data.tar.gz: 3df07fd60447f539702466ea27e5d6890e2e68d25266b0a9e3cc98d6b134b15125d2cea2cd4dfe835b0501bbfd9f8aecf29b3ada57064af1eb1ac79f32702932
|
@@ -1,14 +1,25 @@
|
|
1
1
|
class Griddler::EmailsController < ActionController::Base
|
2
2
|
def create
|
3
3
|
normalized_params.each do |p|
|
4
|
-
Griddler::Email.new(p)
|
4
|
+
process_email Griddler::Email.new(p)
|
5
5
|
end
|
6
|
+
|
6
7
|
head :ok
|
7
8
|
end
|
8
9
|
|
9
10
|
private
|
10
11
|
|
12
|
+
delegate :processor_class, :processor_method, :email_service, to: :griddler_configuration
|
13
|
+
|
11
14
|
def normalized_params
|
12
|
-
Array.wrap(
|
15
|
+
Array.wrap(email_service.normalize_params(params))
|
16
|
+
end
|
17
|
+
|
18
|
+
def process_email(email)
|
19
|
+
processor_class.new(email).public_send(processor_method)
|
20
|
+
end
|
21
|
+
|
22
|
+
def griddler_configuration
|
23
|
+
Griddler.configuration
|
13
24
|
end
|
14
25
|
end
|
data/lib/griddler.rb
CHANGED
@@ -7,12 +7,3 @@ require 'griddler/email_parser'
|
|
7
7
|
require 'griddler/configuration'
|
8
8
|
require 'griddler/route_extensions'
|
9
9
|
require 'griddler/adapter_registry'
|
10
|
-
require 'griddler/adapters/cloudmailin_adapter'
|
11
|
-
require 'griddler/adapters/postmark_adapter'
|
12
|
-
|
13
|
-
require 'griddler/sendgrid'
|
14
|
-
require 'griddler/mandrill'
|
15
|
-
require 'griddler/mailgun'
|
16
|
-
|
17
|
-
Griddler.adapter_registry.register(:cloudmailin, Griddler::Adapters::CloudmailinAdapter)
|
18
|
-
Griddler.adapter_registry.register(:postmark, Griddler::Adapters::PostmarkAdapter)
|
@@ -16,30 +16,7 @@ module Griddler
|
|
16
16
|
end
|
17
17
|
|
18
18
|
class Configuration
|
19
|
-
attr_accessor :processor_class, :processor_method, :reply_delimiter
|
20
|
-
|
21
|
-
def to
|
22
|
-
@to ||= :hash
|
23
|
-
end
|
24
|
-
|
25
|
-
def to=(type)
|
26
|
-
if type == :token
|
27
|
-
Kernel.warn <<-WARN.strip_heredoc
|
28
|
-
[Deprecation] the :token option is deprecated and will be removed in v0.6.
|
29
|
-
For tokens use :hash and retrieve the token from email.to[:token] or choose any of [:email, :full, :hash]
|
30
|
-
WARN
|
31
|
-
end
|
32
|
-
|
33
|
-
@to = type
|
34
|
-
end
|
35
|
-
|
36
|
-
def cc
|
37
|
-
@cc ||= :email
|
38
|
-
end
|
39
|
-
|
40
|
-
def from
|
41
|
-
@from ||= :email
|
42
|
-
end
|
19
|
+
attr_accessor :processor_class, :processor_method, :reply_delimiter
|
43
20
|
|
44
21
|
def processor_class
|
45
22
|
@processor_class ||=
|
@@ -65,7 +42,7 @@ module Griddler
|
|
65
42
|
end
|
66
43
|
|
67
44
|
def email_service
|
68
|
-
@email_service_adapter ||= Griddler.adapter_registry[:
|
45
|
+
@email_service_adapter ||= Griddler.adapter_registry[:default]
|
69
46
|
end
|
70
47
|
|
71
48
|
def email_service=(new_email_service)
|
data/lib/griddler/email.rb
CHANGED
@@ -10,7 +10,7 @@ module Griddler
|
|
10
10
|
@params = params
|
11
11
|
|
12
12
|
@to = recipients(:to)
|
13
|
-
@from = extract_address(params[:from]
|
13
|
+
@from = extract_address(params[:from])
|
14
14
|
@subject = params[:subject]
|
15
15
|
|
16
16
|
@body = extract_body
|
@@ -27,12 +27,6 @@ module Griddler
|
|
27
27
|
@attachments = params[:attachments]
|
28
28
|
end
|
29
29
|
|
30
|
-
def process
|
31
|
-
processor_class = config.processor_class
|
32
|
-
processor_method = config.processor_method
|
33
|
-
processor_class.public_send(processor_method, self)
|
34
|
-
end
|
35
|
-
|
36
30
|
private
|
37
31
|
|
38
32
|
attr_reader :params
|
@@ -41,18 +35,12 @@ module Griddler
|
|
41
35
|
@config ||= Griddler.configuration
|
42
36
|
end
|
43
37
|
|
44
|
-
def recipients(type
|
45
|
-
params[type].to_a.map { |recipient| extract_address(recipient
|
38
|
+
def recipients(type)
|
39
|
+
params[type].to_a.map { |recipient| extract_address(recipient) }
|
46
40
|
end
|
47
41
|
|
48
|
-
def extract_address(address
|
49
|
-
|
50
|
-
|
51
|
-
if type == :hash
|
52
|
-
parsed
|
53
|
-
else
|
54
|
-
parsed[type]
|
55
|
-
end
|
42
|
+
def extract_address(address)
|
43
|
+
EmailParser.parse_address(address)
|
56
44
|
end
|
57
45
|
|
58
46
|
def extract_body
|
@@ -76,7 +76,7 @@ module Griddler::EmailParser
|
|
76
76
|
reply_delimeter_regex,
|
77
77
|
/^\s*[-]+\s*Original Message\s*[-]+\s*$/i,
|
78
78
|
/^\s*--\s*$/,
|
79
|
-
/^\s*\>?\s*On.*\r?\n?\s*.*\s*wrote
|
79
|
+
/^\s*\>?\s*On.*\r?\n?\s*.*\s*wrote:\r?\n?$/,
|
80
80
|
/On.*wrote:/,
|
81
81
|
/From:.*$/i,
|
82
82
|
/^\s*\d{4}\/\d{1,2}\/\d{1,2}\s.*\s<.*>?$/i
|
data/lib/griddler/testing.rb
CHANGED
@@ -51,7 +51,39 @@ shared_examples_for 'Griddler adapter' do |adapter, service_params|
|
|
51
51
|
email: 'hi@example.com',
|
52
52
|
name: 'Hello World',
|
53
53
|
}])
|
54
|
-
email.cc.should eq [
|
54
|
+
email.cc.should eq [{
|
55
|
+
token: 'emily',
|
56
|
+
host: 'example.com',
|
57
|
+
email: 'emily@example.com',
|
58
|
+
full: 'emily@example.com',
|
59
|
+
name: nil
|
60
|
+
}]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
RSpec::Matchers.define :be_normalized_to do |expected|
|
66
|
+
failure_message do |actual|
|
67
|
+
message = ""
|
68
|
+
expected.each do |k, v|
|
69
|
+
if actual[k] != expected[k]
|
70
|
+
message << "expected :#{k} to be normalized to #{expected[k].inspect}, "\
|
71
|
+
"but received #{actual[k].inspect}\n"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
message
|
75
|
+
end
|
76
|
+
|
77
|
+
description do
|
78
|
+
"be normalized to #{expected}"
|
79
|
+
end
|
80
|
+
|
81
|
+
match do |actual|
|
82
|
+
expected.each do |k, v|
|
83
|
+
case v
|
84
|
+
when Regexp then actual[k].should =~ v
|
85
|
+
else actual[k].should === v
|
86
|
+
end
|
55
87
|
end
|
56
88
|
end
|
57
89
|
end
|
data/lib/griddler/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: griddler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.
|
4
|
+
version: 1.0.0.pre.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Thompson
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-06-
|
14
|
+
date: 2014-06-25 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -69,6 +69,20 @@ dependencies:
|
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: pry
|
74
|
+
requirement: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
72
86
|
- !ruby/object:Gem::Dependency
|
73
87
|
name: jquery-rails
|
74
88
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,8 +113,6 @@ files:
|
|
99
113
|
- config/initializers/griddler.rb
|
100
114
|
- lib/griddler.rb
|
101
115
|
- lib/griddler/adapter_registry.rb
|
102
|
-
- lib/griddler/adapters/cloudmailin_adapter.rb
|
103
|
-
- lib/griddler/adapters/postmark_adapter.rb
|
104
116
|
- lib/griddler/configuration.rb
|
105
117
|
- lib/griddler/email.rb
|
106
118
|
- lib/griddler/email_parser.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Griddler
|
2
|
-
module Adapters
|
3
|
-
class CloudmailinAdapter
|
4
|
-
def initialize(params)
|
5
|
-
@params = params
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.normalize_params(params)
|
9
|
-
adapter = new(params)
|
10
|
-
adapter.normalize_params
|
11
|
-
end
|
12
|
-
|
13
|
-
def normalize_params
|
14
|
-
{
|
15
|
-
to: params[:envelope][:to].split(','),
|
16
|
-
cc: ccs,
|
17
|
-
from: params[:envelope][:from],
|
18
|
-
subject: params[:headers][:Subject],
|
19
|
-
text: params[:plain],
|
20
|
-
attachments: params.fetch(:attachments) { [] },
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
attr_reader :params
|
27
|
-
|
28
|
-
def ccs
|
29
|
-
params[:headers][:Cc].to_s.split(',').map(&:strip)
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module Griddler
|
2
|
-
module Adapters
|
3
|
-
class PostmarkAdapter
|
4
|
-
def initialize(params)
|
5
|
-
@params = params
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.normalize_params(params)
|
9
|
-
adapter = new(params)
|
10
|
-
adapter.normalize_params
|
11
|
-
end
|
12
|
-
|
13
|
-
def normalize_params
|
14
|
-
{
|
15
|
-
to: extract_recipients(:ToFull),
|
16
|
-
cc: extract_recipients(:CcFull),
|
17
|
-
from: full_email(params[:FromFull]),
|
18
|
-
subject: params[:Subject],
|
19
|
-
text: params[:TextBody],
|
20
|
-
html: params[:HtmlBody],
|
21
|
-
attachments: attachment_files,
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
attr_reader :params
|
28
|
-
|
29
|
-
def extract_recipients(key)
|
30
|
-
params[key].to_a.map { |recipient| full_email(recipient) }
|
31
|
-
end
|
32
|
-
|
33
|
-
def full_email(contact_info)
|
34
|
-
email = contact_info[:Email]
|
35
|
-
if contact_info[:Name].present?
|
36
|
-
"#{contact_info[:Name]} <#{email}>"
|
37
|
-
else
|
38
|
-
email
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def attachment_files
|
43
|
-
attachments = Array(params[:Attachments])
|
44
|
-
|
45
|
-
attachments.map do |attachment|
|
46
|
-
ActionDispatch::Http::UploadedFile.new({
|
47
|
-
filename: attachment[:Name],
|
48
|
-
type: attachment[:ContentType],
|
49
|
-
tempfile: create_tempfile(attachment)
|
50
|
-
})
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def create_tempfile(attachment)
|
55
|
-
filename = attachment[:Name]
|
56
|
-
tempfile = Tempfile.new(filename, Dir::tmpdir, encoding: 'ascii-8bit')
|
57
|
-
tempfile.write(Base64.decode64(attachment[:Content]))
|
58
|
-
tempfile.rewind
|
59
|
-
tempfile
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|