Commit fbe110cf authored by Andi Saurer's avatar Andi Saurer

add event notifications and update readme

parent 5da49bc8
......@@ -37,6 +37,10 @@ Create a message and deliver it:
@sms.deliver
```
## Delivery Report
ShortMessage listens for status updates on `/short_message/messages/status`. Provide `:id` and `:status` by either `POST` or `GET`.
## Customization
### Status Codes
......@@ -59,3 +63,13 @@ ShortMessage::Message.module_eval do
end
end
```
### Events
ShortMessage sends event notifications on message delivery `short_message.delivered` and on status update `short_message.status_updated`. Add following code to an initializer to listen:
```ruby
ActiveSupport::Notifications.subscribe('short_message.status_updated') do |name, start, finish, id, payload|
Activity.create(successful: true, message: "Message #{payload[:options][:key]} has now status #{payload[:options][:status]}.")
end
```
......@@ -8,6 +8,7 @@ module ShortMessage
message.status_code = params[:status]
message.save!
ActiveSupport::Notifications.instrument('short_message.status_updated', options: { key: params[:id], status: params[:status] })
message = "Message #{params[:id]} has now status #{params[:status]}"
else
message = "Message #{params[:id]} not found!"
......
......@@ -20,6 +20,7 @@ module ShortMessage
end
self.message_key = result_set[2] unless result_set[2].blank?
ActiveSupport::Notifications.instrument('short_message.delivered', options: { key: (result_set[2] unless result_set[2].blank?) })
return self.save
else
ShortMessage::Mailer.error_notification(self, response).deliver_now unless ShortMessage.config.admin_notification_email.blank?
......
module ShortMessage
VERSION = "1.0.2"
VERSION = "1.1.0"
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment