README.rdoc in mandrill-rails-1.1.1 vs README.rdoc in mandrill-rails-1.2.0
- old
+ new
@@ -108,12 +108,35 @@
Note that Mandrill may send multiple event payloads in a single request, but you don't need
to worry about that. Each event payload will be unpacked from the request and dispatched to
your handler individually.
-And if you don't care to handle a specific payload type - then just don't implement the associated handler.
+=== Do I need to handle all the event payloads that Mandrill send?
+No. It is optional. If you don't care to handle a specific payload type - then just don't implement the associated handler method.
+
+For example, your code in production only has a `handle_inbound` method, but you turn on click webhooks. What should happen?
+
+By default, click events will simply be ignored and logged (as errors) in the Rails log.
+
+You can change this behaviour. To completely ignore unhandled events (not even logging), add the `ignore_unhandled_events!`
+directive to your controller:
+
+ class InboxController < ApplicationController
+ include Mandrill::Rails::WebHookProcessor
+ ignore_unhandled_events!
+ end
+
+At the other extreme, if you want unhandled events to raise a hard exception, add the `unhandled_events_raise_exceptions!`
+directive to your controller:
+
+ class InboxController < ApplicationController
+ include Mandrill::Rails::WebHookProcessor
+ unhandled_events_raise_exceptions!
+ end
+
+
=== How can I authenticate Mandrill Webhooks?
Mandrill now supports {webhook authentication}[http://help.mandrill.com/entries/23704122-Authenticating-webhook-requests] which can help prevent unauthorised posting to your webhook handlers. You can lookup and reset your API keys on the
{Mandrill WebHook settings}[https://mandrillapp.com/settings/webhooks] page.
@@ -170,11 +193,11 @@
If you would like examples of the actual data structures sent by Mandrill for different event types,
some are included in the project source under spec/fixtures/webhook_examples.
=== What additional methods does event_payload provide to help extract payload-specific elements?
-In addition to prividing full Hash-like access to the raw message, the <tt>event_payload</tt> object
+In addition to providing full Hash-like access to the raw message, the <tt>event_payload</tt> object
(a Mandrill::WebHook::EventDecorator) provides a range of helper methods for some of the more obvious
things you might need to do with the payload. Here are some examples (see
{Mandrill::WebHook::EventDecorator class documentation}[http://rubydoc.info/gems/mandrill-rails/Mandrill/WebHook/EventDecorator]
for full details)
@@ -244,18 +267,48 @@
a1.name
# => e.g. 'sample.pdf'
a1.type
# => e.g. 'application/pdf'
+ a1.base64
+ # => true
a1.content
- # => this is the raw content provided by Mandrill, and will be base64-encoded if not plain text
+ # => this is the raw content provided by Mandrill, and may be base64-encoded
# e.g. 'JVBERi0xLjMKJcTl8uXrp/Og0MTGCjQgMCBvY ... (etc)'
a1.decoded_content
# => this is the content decoded by Mandrill::Rails, ready to be written as a File or whatever
# e.g. '%PDF-1.3\n%\xC4\xE5 ... (etc)'
end
end
+
+
+=== How do I extract images from an inbound email?
+
+The EventDecorator class provides an <tt>images</tt> method to access an array of images (if any).
+Each image is encapsulated in a class that describes the name, mime type, raw and decoded content.
+
+For example:
+
+ def handle_inbound(event_payload)
+ if images = event_payload.images.presence
+ # yes, we have at least 1 image. Lets look at the first:
+ a1 = images.first
+ a1.name
+ # => e.g. 'sample.png'
+ a1.type
+ # => e.g. 'image/png'
+ a1.base64
+ # => true # always
+ a1.content
+ # => this is the raw content provided by Mandrill (always base64)
+ # e.g. 'iVBORw0K ... (etc)'
+ a1.decoded_content
+ # => this is the content decoded by Mandrill::Rails, ready to be written as a File or whatever
+ # e.g. '\x89PNG\r\n ... (etc)'
+ end
+ end
+
=== How do I use Mandrill API features with Mandrill::Rails?
Mandrill::Rails currently does not need or require any direct Mandrill API integration (such as provided by
various {Mandrill}[https://rubygems.org/search?utf8=%E2%9C%93&query=mandrill]