Skip to content

Commit

Permalink
Update for :uuid and find_by_uuid usage, document MailObserver usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Puchalski committed Mar 26, 2012
1 parent 2ee41c4 commit 4e3a677
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions README.md
Expand Up @@ -35,9 +35,11 @@ SendgridPostback.configure do |config|
# proc that accepts an exception for reporting
config.report_exception = proc { |exc| ... } # Optional

# Proc that returns an instance for the given uuid.
# Required proc that returns an instance for the given uuid.
# The class should mix in SendgridPostback::EventReceiver
config.find_receiver_by_uuid = proc { |uuid| ... } # Required
config.find_receiver_by_uuid = proc do |uuid|
Notification.find_by_uuid(uuid) # for example
end
end
```

Expand All @@ -49,11 +51,13 @@ This module adds attributes that should be persisted, `sendgrid_events` and `sen
```ruby
class AddEventsAndState < ActiveRecord::Migration
def self.up
add_column :notifications, :uuid, :string
add_column :notifications, :state, :string
add_column :notifications, :events, :text
end

def self.down
remove_column :notifications, :uuid
remove_column :notifications, :state
remove_column :notifications, :events
end
Expand All @@ -67,6 +71,29 @@ class Notification < ActiveRecord::Base
end
```

Add a new or adapt your existing MailObserver to trap email after they are sent to create a receiver instance.
You may wish to also persist the email content itself.

```ruby
class MailObserver

# Capture UUID set by MailInterceptor and create a new Notification record
def self.delivered_email(email)
Notification.create!({
uuid: email.uuid
to: email.to.to_a.join(', '),
subject: email.subject,
email: email.to_s
})
end

def self.register
ActionMailer::Base.register_observer(self)
end

end
```

## Contributing

1. Fork it
Expand Down

0 comments on commit 4e3a677

Please sign in to comment.