Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for the SendGrid event notification API #30

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/controllers/griddler/events_controller.rb
@@ -0,0 +1,6 @@
class Griddler::EventsController < ActionController::Base
def create
Griddler::Event.process(request.raw_body)
head :ok
end
end
4 changes: 4 additions & 0 deletions lib/griddler/configuration.rb
Expand Up @@ -26,6 +26,10 @@ def processor_class
@processor_class ||= EmailProcessor
end

def event_processor_class
@event_processor_class ||= EmailEventProcessor
end

def reply_delimiter
@reply_delimiter ||= 'Reply ABOVE THIS LINE'
end
Expand Down
41 changes: 41 additions & 0 deletions lib/griddler/event.rb
@@ -0,0 +1,41 @@
require 'yajl'

class Griddler::Event
attr_reader :attributes

def self.process(body)
parser = Yajl::Parser.new
parser.on_parse_complete = proc do |event_attributes|
config.event_processor_class.process Event.new(event_attributes)
end
parser.parse(body)
end

def initialize(attributes)
@attributes = attributes
end

def event
@attributes[:event]
end

def email
@attributes[:email]
end

def timestamp
@timestamp ||= Time.at (@attribute[:timestamp] || Time.now).to_i
end

def [](key)
@attributes[key]
end

class << self
private

def config
Griddler.configuration
end
end
end