pushkin-library 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +130 -9
- data/app/models/pushkin/notification.rb +2 -2
- data/lib/pushkin.rb +2 -22
- data/lib/pushkin/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb822d5b68c0e5d26f9c37f0b091508d6bb5b056
|
4
|
+
data.tar.gz: f20025303caaf0a5efc2c2b57a4280c8b9f5e544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ff5c5fa8eaee6d5e1f55314830a835ec3a005387f75140fabba0ee7723f1938f3f49d6374c7d1cfd6e01c166c62732835a87df223400d41ca362d0a0095bc13
|
7
|
+
data.tar.gz: 9916574f41a35ac1bb47b5bfce669f3dfa0fe93eafe5e57a98cd276f37ea73fd9919e5238525c7e732a9f8f44bfcaa612c1575e2aafdf347c2413986b3e97582
|
data/README.md
CHANGED
@@ -1,28 +1,149 @@
|
|
1
1
|
# Pushkin
|
2
|
-
|
2
|
+
Pushkin sends push notifications to Android, iOS and Web clients through the unified simple interface using FCM.
|
3
|
+
You can also show Web Push Notifications using Pushkin implementation.
|
3
4
|
|
4
5
|
## Usage
|
5
|
-
How to use my plugin.
|
6
6
|
|
7
|
-
|
7
|
+
### How to create notifications
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
notification = Pushkin.simple_notification_to_users({
|
11
|
+
notification_type: "poem",
|
12
|
+
users: User.all,
|
13
|
+
title: "Ruslan and Ludmila",
|
14
|
+
body: "The story of the abduction of Ludmila, the daughter of Prince Vladimir of Kiev, by an evil wizard and the attempt by the brave knight Ruslan to find and rescue her"
|
15
|
+
})
|
16
|
+
```
|
17
|
+
|
18
|
+
It creates a push notification with static content to the specified users. Actual user tokens will be queried from the database at the time of sending.
|
19
|
+
|
20
|
+
Run this code to send notification immediately using ActiveJob:
|
21
|
+
```ruby
|
22
|
+
notification.send_now
|
23
|
+
```
|
24
|
+
|
25
|
+
You can also send notifications synchronously:
|
26
|
+
```ruby
|
27
|
+
notification.send_now(async: false)
|
28
|
+
```
|
29
|
+
|
30
|
+
### Creation parameters
|
31
|
+
|
32
|
+
| Parameter | Usage | Description |
|
33
|
+
| ------------------ | ------------------------ | ------------------------------------------------------------------ |
|
34
|
+
| :notification_type | Required, String | Custom string to distinguish notifications from each other |
|
35
|
+
| :users | Required, Array/Relation | List of users to send push notifications |
|
36
|
+
| :title | Required, String | Notification title |
|
37
|
+
| :body | Optional, String | Notification text |
|
38
|
+
| :click_action | Optional, Hash | Click actions of each platform |
|
39
|
+
| :icon | Optional, Hash | Notification icon for web and android platforms |
|
40
|
+
| :is_data_message | Optional, Hash | Specifies if you want to send data message instead of notification |
|
41
|
+
| :data | Optional, Hash | Any notification data that will be sent in the notification |
|
42
|
+
|
43
|
+
In any case, :data hash will include following parameters:
|
44
|
+
|
45
|
+
| Parameter | Usage | description |
|
46
|
+
| ----------------------- | -------------------- | -------------------------------------------- |
|
47
|
+
| :notification_type | Required, String | Value of :notification_type parameter |
|
48
|
+
| :notification_id | Required, Integer | Unique identifier of created notification |
|
49
|
+
|
50
|
+
**:click_action hash keys**
|
51
|
+
|
52
|
+
| Parameter | Usage | description |
|
53
|
+
| --------- | -------------------- | ------------------------------------ |
|
54
|
+
| :web | Optional, String | URL to open in the browser |
|
55
|
+
| :ios | Optional, String | Category in the APNs payload |
|
56
|
+
| :android | Optional, String | Intent filter to launch the Activity |
|
57
|
+
|
58
|
+
**:icon hash keys**
|
59
|
+
|
60
|
+
| key | value type | description |
|
61
|
+
| -------- | -------------------- | -------------------------------- |
|
62
|
+
| :web | Optional, String | Public absolute URL of icon |
|
63
|
+
| :android | Optional, String | Drawable resource name |
|
64
|
+
|
65
|
+
**:is_data_message hash keys**
|
66
|
+
|
67
|
+
| key | value type | description |
|
68
|
+
| -------- | -------------------- | -------------------------------- |
|
69
|
+
| :web | Optional, Boolean | True, if you want to send data message to web client |
|
70
|
+
| :ios | Optional, Boolean | True, if you want to send data message to ios client |
|
71
|
+
| :android | Optional, Boolean | True, if you want to send data message to android client |
|
72
|
+
|
73
|
+
In case of data messages all notification attributes like title and body will be sent in data instead of notification.
|
74
|
+
|
75
|
+
## Gem Installation
|
8
76
|
Add this line to your application's Gemfile:
|
9
77
|
|
10
78
|
```ruby
|
11
|
-
gem 'pushkin'
|
79
|
+
gem 'pushkin-library'
|
12
80
|
```
|
13
81
|
|
14
82
|
And then execute:
|
15
83
|
```bash
|
16
|
-
$ bundle
|
84
|
+
$ bundle install
|
85
|
+
```
|
86
|
+
|
87
|
+
Execute in command line:
|
88
|
+
```bash
|
89
|
+
$ bin/rails generate pushkin:setup
|
17
90
|
```
|
18
91
|
|
19
|
-
|
92
|
+
It will generate:
|
93
|
+
* migration *CreatePushkinTables* to create tables for notifications sending.
|
94
|
+
* controller *Pushkin::Api::V1::TokensController* for managing device tokens.
|
95
|
+
* routes for tokens controller.
|
96
|
+
|
97
|
+
And then run migration:
|
20
98
|
```bash
|
21
|
-
$
|
99
|
+
$ rake db:migrate
|
100
|
+
```
|
101
|
+
|
102
|
+
Add the following to your environment variables:
|
103
|
+
```bash
|
104
|
+
PUSHKIN_API_KEY=ANY_API_KEY_FOR_REQUEST_AUTHORIZATION
|
105
|
+
FCM_SERVER_KEY=YOUR_FCM_SERVER_KEY_FROM_FCM_CONSOLE
|
106
|
+
```
|
107
|
+
|
108
|
+
If you want to attach device tokens to users, you need to implement authentication logic in *Pushkin::Api::V1::TokensController* and add this line to *User* model:
|
109
|
+
```ruby
|
110
|
+
include Pushkin::Concerns::PushkinUser
|
111
|
+
```
|
112
|
+
|
113
|
+
## Web Push Notifications Setup
|
114
|
+
|
115
|
+
Add JavaScript FCM Client App to your Rails App ([instructions](https://firebase.google.com/docs/cloud-messaging/js/client)) without permission request, token access and notifications showing. You just need to create FCM project in FCM console, link FCM libraries and put manifest file to public directory.
|
116
|
+
|
117
|
+
Add this lines to your layout file:
|
118
|
+
```erb
|
119
|
+
<script src="https://www.gstatic.com/firebasejs/5.4.1/firebase-app.js"></script>
|
120
|
+
<script src="https://www.gstatic.com/firebasejs/5.4.1/firebase-messaging.js"></script>
|
121
|
+
<link rel="manifest" href="/manifest.json">
|
122
|
+
<%= javascript_include_tag "pushkin/application" %>
|
123
|
+
```
|
124
|
+
|
125
|
+
Init FCM messaging object in javascript code and save it to Pushkin:
|
126
|
+
```javascript
|
127
|
+
firebase.initializeApp(yourFirebaseSettings);
|
128
|
+
var messaging = firebase.messaging();
|
129
|
+
messaging.usePublicVapidKey(YOUR_PUBLIC_VAPID_KEY);
|
130
|
+
PUSHKIN.messaging = messaging;
|
131
|
+
```
|
132
|
+
|
133
|
+
Implement token sending:
|
134
|
+
```javascript
|
135
|
+
Pushkin.prototype.sendFirebaseTokenToServer = function (currentToken) {
|
136
|
+
// Send currentToken to server using Pushkin API
|
137
|
+
}
|
138
|
+
```
|
139
|
+
|
140
|
+
Init notifications showing, access to token and permission request:
|
141
|
+
```javascript
|
142
|
+
PUSHKIN.initNotifications();
|
143
|
+
PUSHKIN.requestPermission();
|
22
144
|
```
|
23
145
|
|
24
|
-
|
25
|
-
Contribution directions go here.
|
146
|
+
**Attention!** If you want to show push notifications while browser is closed, you still needs to implement this logic in *firebase-messaging-sw.js* yourself.
|
26
147
|
|
27
148
|
## License
|
28
149
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -31,12 +31,12 @@ module Pushkin
|
|
31
31
|
validates :notification_type, presence: true
|
32
32
|
|
33
33
|
# Отправляет уведомление прямо сейчас
|
34
|
-
def send_now
|
34
|
+
def send_now(async: true)
|
35
35
|
# Заполняем как дату, в которую нужно отправить, так и дату, в которую началась отправка.
|
36
36
|
# Это позволит периодической операции по отправке уведомлений не отвлекаться на такое уведомление.
|
37
37
|
now = DateTime.now
|
38
38
|
self.update_attributes(start_at: now, started_at: now)
|
39
|
-
SendJob.perform_later(self.id)
|
39
|
+
async ? SendJob.perform_later(self.id) : SendPushService.new(self.id).call
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
data/lib/pushkin.rb
CHANGED
@@ -2,28 +2,8 @@ require "pushkin/engine"
|
|
2
2
|
|
3
3
|
module Pushkin
|
4
4
|
|
5
|
-
def self.
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.ios_provider
|
10
|
-
@@ios_provider ||= :fcm
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.web_provider
|
14
|
-
@@web_provider ||= :fcm
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.android_provider=(value)
|
18
|
-
@@android_provider = value
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.ios_provider=(value)
|
22
|
-
@@ios_provider = value
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.web_provider=(value)
|
26
|
-
@@web_provider = value
|
5
|
+
def self.simple_notification_to_users(*args)
|
6
|
+
Pushkin::NotificationFabric.new.simple_notification_to_users(*args)
|
27
7
|
end
|
28
8
|
|
29
9
|
end
|
data/lib/pushkin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pushkin-library
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bazov Peter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|