Skip to content

Commit

Permalink
increments version to 1.0.3 and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nflorentin committed Nov 4, 2015
1 parent 26cd154 commit f457349
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ Wupee is a opinionated solution which assumes that users needs to:
* be able to receive notifications by email
* be able to configure if they wants to either receive emails AND notifications or emails or only notifications or nothing

Right now, only the receiver can configure what he wants to receive. You can't create an *email only* notification or a *app only* notification but that could be a near future feature.
Right now, only the receiver can configure what he wants to receive. You can't create an *email only* notification or a *app only* notification but that could be a near future feature.

The main object of the solution is the `Wupee::Notification` which stores:
* receiver (polymorphic): the recipient of the message
* attached_object (polymorphic): the subject of the notification
* notification_type_id: a reference to a `Wupee::NotificationType` object
* is_read: boolean


## Install:

To use it, add it to your Gemfile:
Expand Down Expand Up @@ -50,10 +50,10 @@ Running the generator will do a few things:
# config/initializers/wupee.rb
Wupee.mailer = NotificationsMailer # the class of the mailer you will use to send the emails
Wupee.deliver_when = :now # use :later if you already configured a queuing system

Wupee::NotificationType.class_eval do
create_configurations_for 'User' # class name of your notification receivers, can be various 'User', 'Admin',
end # enable callbacks to create Wupee::NotificationTypeConfiguration object of
end # enable callbacks to create Wupee::NotificationTypeConfiguration object of
# each user when you create a new Wupee::NotificationType
```
3. create a mailer `NotificationsMailer` which inheritates from `Wupee::NotificationsMailer`
Expand All @@ -65,7 +65,7 @@ Running the generator will do a few things:
layout false
end
```

4. adds wupee to your locale yml file (for email subjects)
```yml
# config/locales/en.yml
Expand All @@ -76,7 +76,7 @@ Running the generator will do a few things:
## Getting started:
### Generate a new notification type
### Generate a new notification type
```bash
rails g wupee:notification_type user_has_been_created
Expand All @@ -90,31 +90,31 @@ Will execute a few things:
en:
wupee:
email_subjects:
user_has_been_created: "user_has_been_created"
user_has_been_created: "user_has_been_created"
```
Feel free to edit the subject, you can put variables, example
```yml
...
user_has_been_created: "New user created: %{user_full_name}"
```
2. create a json template for the notification:
```ruby
json.subject ""
json.body ""
json.url ""
# none of this json attribute are mandatory!
# none of this json attribute are mandatory!
```
In this template, you have access to the **notification** variable.
You can customize it to fit your need, this is just an example.

3. create an empty html template for the notification:
```html
<!-- app/views/wupee/notifications/_user_has_been_created.html.erb -->
```

4. You will have to create your email template as the generator doesn't create it.
4. You will have to create your email template as the generator doesn't create it.
For example, if your mailer is named `NotificationsMailer`, your template will take place in
`app/views/notifications_mailer/user_has_been_created.html.erb`

Expand Down Expand Up @@ -142,7 +142,7 @@ Including the concern `Wupee::Receiver` in your receiver class (probably the `Us
* get notifications_type_configurations of a user: `@user.notifications_type_configurations`
* execute an after_create callback to create `Wupee::NotificationTypeConfiguration` for each `Wupee::NotificationType` object for the receiver
* destroy `Wupee::Notification` and `Wupee::NotificationTypeConfiguration` associated to the receiver from db if it is destroyed

#### Wupee::AttachedObject

Including the concern `Wupee::AttachedObject` in your attached object classe(s) permits a few things:
Expand All @@ -154,12 +154,12 @@ Including the concern `Wupee::AttachedObject` in your attached object classe(s)
Imagine that you want to notify all admin that a new user signed up in your app and that you have a scope `admin` in your `User` class.

```ruby
Wupee.notify do
attached_object @the_new_user
notif_type :user_has_been_created # you can also pass an instance of a Wupee::NotificationType class to this method
subject_vars user_full_name: Proc.new { |notification| notification.attached_object.full_name } # variables to be interpolated the fill in the subject of the email (obviously optional)
receivers User.admin # you can use the method receiver instead of receivers for clarity if you pass only one instance of a receiver
deliver :now # you can overwrite global configuration here, optional
Wupee.notify do |n|
n.attached_object @the_new_user
n.notif_type :user_has_been_created # you can also pass an instance of a Wupee::NotificationType class to this method
n.subject_vars user_full_name: Proc.new { |notification| notification.attached_object.full_name } # variables to be interpolated the fill in the subject of the email (obviously optional)
n.receivers User.admin # you can use the method receiver instead of receivers for clarity if you pass only one instance of a receiver
n.deliver :now # you can overwrite global configuration here, optional
end
```

Expand All @@ -171,12 +171,12 @@ You can also use the method `notify` this way:

The method will take care to check receiver's configurations to only send emails to those who want them.

## Wupee::Api::NotificationsController
## Wupee::Api::NotificationsController

In order to make this controller work, you need a method `current_user` which return the user currently signed in.

The controller have various actions all scoped for the current user:
* `wupee/api/notifications#index` : fetch notifications, take an optional parameter `is_read` (false by default)
* `wupee/api/notifications#index` : fetch notifications, take an optional parameter `is_read` (false by default)
* `wupee/api/notifications#show` : fetch a notification
* `wupee/api/notifications#update` : mark as read a notification
* `wupee/api/notifications#update_all` : mark as read all notifications
Expand All @@ -186,7 +186,7 @@ The controller have various actions all scoped for the current user:
The class also define 2 methods which you could use (in your views for example):
* `wants_email?` : return a boolean
* `wants_notification?` : return a boolean

## Important to know!

The system relies on the fact that you have an object in db for each couple of [receiver, `Wupee::NotificationType`]. Even if the gem provides callbacks to take care of that, be sure that those objects are created otherwise notifications won't be sent for thoses receivers.
Expand Down
2 changes: 1 addition & 1 deletion lib/wupee/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Wupee
VERSION = "1.0.2"
VERSION = "1.0.3"
end

0 comments on commit f457349

Please sign in to comment.