pushkin-library 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb822d5b68c0e5d26f9c37f0b091508d6bb5b056
4
- data.tar.gz: f20025303caaf0a5efc2c2b57a4280c8b9f5e544
3
+ metadata.gz: d63bca932152d5300789620e58aed1cb32a6f29d
4
+ data.tar.gz: 6489241bb5b0632c53c315b9e6b007924c6b1593
5
5
  SHA512:
6
- metadata.gz: 3ff5c5fa8eaee6d5e1f55314830a835ec3a005387f75140fabba0ee7723f1938f3f49d6374c7d1cfd6e01c166c62732835a87df223400d41ca362d0a0095bc13
7
- data.tar.gz: 9916574f41a35ac1bb47b5bfce669f3dfa0fe93eafe5e57a98cd276f37ea73fd9919e5238525c7e732a9f8f44bfcaa612c1575e2aafdf347c2413986b3e97582
6
+ metadata.gz: 54261e0229655d0e8956d7c527cb571e8cef7fdbbdb4c465bfa519aa6dcd36154377ba5ca670c5f56b7c44a3f02a1eb5afe864c35ac770d7dfe9db0d6a5e6c75
7
+ data.tar.gz: 61d1a58a89713a33bb07da65d8b4622d82d3967ce265696af6fe0e5a86562ceb36f46daed3508c54563ece57e6871fcad2f592fe1d9670339acc18e4b37aacc7
data/README.md CHANGED
@@ -1,149 +1 @@
1
- # Pushkin
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.
4
1
 
5
- ## Usage
6
-
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
76
- Add this line to your application's Gemfile:
77
-
78
- ```ruby
79
- gem 'pushkin-library'
80
- ```
81
-
82
- And then execute:
83
- ```bash
84
- $ bundle install
85
- ```
86
-
87
- Execute in command line:
88
- ```bash
89
- $ bin/rails generate pushkin:setup
90
- ```
91
-
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:
98
- ```bash
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();
144
- ```
145
-
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.
147
-
148
- ## License
149
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -4,18 +4,6 @@ module Pushkin::Api::V1::Concerns::ApiHelper
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- WRONG_API_KEY = "Wrong API key"
8
-
9
- # Проверяет переданный ключ API и возвращает ошибку в случае несовпадения.
10
- # Для минимальной защиты от несанкционированного доступа.
11
- def check_api_key!
12
- api_key = ENV["PUSHKIN_API_KEY"]
13
- raise Exception.new("No PUSHKIN_API_KEY in ENV") if api_key.blank?
14
-
15
- if api_key != params[:push_api_key]
16
- render :status => 403, :json => { :success => false, :info => WRONG_API_KEY }
17
- end
18
- end
19
7
 
20
8
  def render_bad_request(info, errors = nil)
21
9
  render_error(400, info, errors)
@@ -7,7 +7,6 @@ module Pushkin::Api::V1::Concerns::TokensHelper
7
7
 
8
8
  include Pushkin::Api::V1::Concerns::ApiHelper
9
9
 
10
- before_action :check_api_key!
11
10
  before_action :init_creation_params!, only: [:create]
12
11
 
13
12
  EMPTY_TOKEN_ERROR = "param 'token' is empty"
@@ -13,8 +13,7 @@ module Pushkin
13
13
  def initialize(tokens, payload)
14
14
  @tokens = tokens
15
15
  @payload = payload
16
- @server_key = ENV["FCM_SERVER_KEY"]
17
- raise Exception.new("No FCM_SERVER_KEY in ENV") if @server_key.blank?
16
+ @server_key = Pushkin.config.fcm_server_key
18
17
  end
19
18
 
20
19
  def call
data/lib/pushkin.rb CHANGED
@@ -1,7 +1,16 @@
1
1
  require "pushkin/engine"
2
+ require "pushkin/configuration"
2
3
 
3
4
  module Pushkin
4
5
 
6
+ def self.config
7
+ Pushkin::Configuration.instance
8
+ end
9
+
10
+ def self.configure(&block)
11
+ block.call(Pushkin.config)
12
+ end
13
+
5
14
  def self.simple_notification_to_users(*args)
6
15
  Pushkin::NotificationFabric.new.simple_notification_to_users(*args)
7
16
  end
@@ -0,0 +1,13 @@
1
+ module Pushkin
2
+ class Configuration
3
+
4
+ include Singleton
5
+
6
+ attr_accessor :fcm_server_key
7
+
8
+ def fcm_server_key
9
+ @fcm_server_key ||= ENV["FCM_SERVER_KEY"]
10
+ end
11
+
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Pushkin
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushkin-library
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bazov Peter
@@ -98,6 +98,7 @@ files:
98
98
  - lib/generators/pushkin/templates/tokens_controller.rb
99
99
  - lib/pushkin-library.rb
100
100
  - lib/pushkin.rb
101
+ - lib/pushkin/configuration.rb
101
102
  - lib/pushkin/engine.rb
102
103
  - lib/pushkin/version.rb
103
104
  - lib/tasks/pushkin_tasks.rake