griddler-ses 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e8a8dc6b0a47c33b42449f0d33681023887dee6
4
- data.tar.gz: 9e4c2cdafbf1bfcb04e8847ea5b62e00b6427f34
3
+ metadata.gz: a254412f4d73e3ca99782daa1c8f067cbf916f99
4
+ data.tar.gz: cf45a3a5826cf3954b21dfe3adf6ca31eba93517
5
5
  SHA512:
6
- metadata.gz: 760e0626163545aca32eefbe2634ef9f98b7de781a830667e23590321add74bfb0b2b1331ff733a30e5008941f2cb97a76fd1c65d5daf3e83d2fe1a25fb9f056
7
- data.tar.gz: 626135972c580d7c952460cd45d56d170aa1b134026841333e8b2692c8156217aaf7324f660786b24ed60aad0ce5f9869a2b5b2785d57e9c8026e2a763b01987
6
+ metadata.gz: b78e58bd0a0541c9fb4111a53beaed53747281a9cb0de2cab6f4e2241cc95f3196f9ff2b1e2871202391addd6441b4c542f1c417756774e1fd7e8da4badf19b8
7
+ data.tar.gz: 3945b1b7c8f13796a06fd15d3b27963379b781bd57e4ae357f9d2a49e86fc76e4ce7eea31c26b273f02c01d5468de8c07a5b42864b894af6c375d9f08918e889
@@ -5,15 +5,14 @@ require 'net/http'
5
5
  module Griddler
6
6
  module Ses
7
7
  class Adapter
8
- attr_reader :params, :raw_request
8
+ attr_reader :sns_json
9
9
 
10
- def initialize(params, raw_request)
11
- @params = params
12
- @raw_request = raw_request
10
+ def initialize(params)
11
+ @sns_json = params
13
12
  end
14
13
 
15
14
  def self.normalize_params(params)
16
- adapter = new(params, self.raw_request)
15
+ adapter = new(params)
17
16
  adapter.normalize_params
18
17
  end
19
18
 
@@ -29,7 +28,7 @@ module Griddler
29
28
  {}
30
29
  when :Notification
31
30
  ensure_valid_notification_type!
32
- params.merge(
31
+ sns_json.merge(
33
32
  to: recipients,
34
33
  from: sender,
35
34
  cc: cc,
@@ -46,10 +45,6 @@ module Griddler
46
45
  end
47
46
 
48
47
  private
49
- def sns_json
50
- @sns_json ||= JSON.parse(raw_request.raw_post)
51
- end
52
-
53
48
  def email_json
54
49
  @email_json ||= JSON.parse(sns_json['Message'])
55
50
  end
@@ -135,12 +130,6 @@ module Griddler
135
130
  confirmation_endpoint = URI.parse(sns_json['SubscribeURL'])
136
131
  Net::HTTP.get confirmation_endpoint
137
132
  end
138
-
139
- def self.raw_request
140
- # TODO: this is an ugly hack using introspection to get the request from the calling controller; should update Griddler
141
- # to provide the full request context
142
- raw_request = binding.of_caller(2).eval('request')
143
- end
144
133
  end
145
134
  end
146
135
  end
@@ -0,0 +1,25 @@
1
+ module Griddler
2
+ module Ses
3
+ class Middleware
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ # a bug on the AWS side doesn't set the content type to application/json type properly,
10
+ # so we have to intercept and do this in order for Griddler's controller to correctly
11
+ # parse the parameters (see https://forums.aws.amazon.com/thread.jspa?messageID=418160)
12
+ if env['REQUEST_PATH'] == griddler_path
13
+ env['CONTENT_TYPE'] = 'application/json; charset=UTF-8'
14
+ end
15
+
16
+ @app.call(env)
17
+ end
18
+
19
+ private
20
+ def griddler_path
21
+ @griddler_path ||= Rails.application.routes.url_helpers.url_for(controller: 'griddler/emails', action: 'create', only_path: true)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ module Griddler
2
+ module Ses
3
+ class Railtie < Rails::Railtie
4
+ initializer "griddler_ses.configure_rails_initialization" do |app|
5
+ Rails.application.middleware.insert_before ActionDispatch::ParamsParser, Griddler::Ses::Middleware
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module Griddler
2
2
  module Ses
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
data/lib/griddler/ses.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'griddler'
2
2
  require 'griddler/ses/version'
3
3
  require 'griddler/ses/adapter'
4
+ require 'griddler/ses/middleware'
5
+ require 'griddler/ses/railtie'
4
6
 
5
7
  module Griddler
6
8
  module Ses
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: griddler-ses
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kent Mewhort @ Coupa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-13 00:00:00.000000000 Z
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: griddler
@@ -111,6 +111,8 @@ files:
111
111
  - griddler-ses.gemspec
112
112
  - lib/griddler/ses.rb
113
113
  - lib/griddler/ses/adapter.rb
114
+ - lib/griddler/ses/middleware.rb
115
+ - lib/griddler/ses/railtie.rb
114
116
  - lib/griddler/ses/version.rb
115
117
  homepage: https://github.com/85x14/griddler-ses
116
118
  licenses: