pushkin-library 0.1.3
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +36 -0
- data/app/assets/config/pushkin_manifest.js +2 -0
- data/app/assets/javascripts/pushkin/application.js +14 -0
- data/app/assets/javascripts/pushkin/firebase/push_notifications.js +100 -0
- data/app/assets/javascripts/pushkin/main.js +5 -0
- data/app/assets/stylesheets/pushkin/application.css +15 -0
- data/app/controllers/pushkin/api/v1/concerns/api_helper.rb +43 -0
- data/app/controllers/pushkin/api/v1/concerns/tokens_helper.rb +94 -0
- data/app/controllers/pushkin/application_controller.rb +5 -0
- data/app/fabrics/pushkin/notification_fabric.rb +83 -0
- data/app/helpers/pushkin/application_helper.rb +4 -0
- data/app/jobs/pushkin/application_job.rb +4 -0
- data/app/jobs/pushkin/send_job.rb +11 -0
- data/app/mailers/pushkin/application_mailer.rb +6 -0
- data/app/models/pushkin/application_record.rb +5 -0
- data/app/models/pushkin/concerns/pushkin_user.rb +10 -0
- data/app/models/pushkin/notification.rb +42 -0
- data/app/models/pushkin/payload.rb +21 -0
- data/app/models/pushkin/push_sending_result.rb +13 -0
- data/app/models/pushkin/token.rb +19 -0
- data/app/models/pushkin/token_result.rb +39 -0
- data/app/models/pushkin/tokens_provider.rb +22 -0
- data/app/models/pushkin/tokens_provider_user.rb +12 -0
- data/app/services/pushkin/fcm/send_android_push_service.rb +22 -0
- data/app/services/pushkin/fcm/send_fcm_push_service.rb +120 -0
- data/app/services/pushkin/fcm/send_ios_push_service.rb +22 -0
- data/app/services/pushkin/fcm/send_web_push_service.rb +22 -0
- data/app/services/pushkin/send_push_service.rb +39 -0
- data/app/services/pushkin/token_filters/android_token_filter.rb +15 -0
- data/app/services/pushkin/token_filters/ios_token_filter.rb +15 -0
- data/app/services/pushkin/token_filters/token_filter.rb +24 -0
- data/app/services/pushkin/token_filters/web_token_filter.rb +15 -0
- data/app/views/layouts/pushkin/application.html.erb +14 -0
- data/lib/generators/pushkin/setup_generator.rb +27 -0
- data/lib/generators/pushkin/templates/create_pushkin_tables.rb +89 -0
- data/lib/generators/pushkin/templates/tokens_controller.rb +16 -0
- data/lib/pushkin-library.rb +1 -0
- data/lib/pushkin.rb +29 -0
- data/lib/pushkin/engine.rb +5 -0
- data/lib/pushkin/version.rb +3 -0
- data/lib/tasks/pushkin_tasks.rake +4 -0
- metadata +128 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
module Pushkin
|
2
|
+
module TokenFilters
|
3
|
+
class AndroidTokenFilter < TokenFilter
|
4
|
+
|
5
|
+
def necessary?(token)
|
6
|
+
token.android?
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_sending_service(tokens, payload)
|
10
|
+
Fcm::SendAndroidPushService.new(tokens, payload)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Фильтрует токены по принадлежности к платформе
|
2
|
+
# и предоставляет сервис по отправке уведомлений на эту конкретную платформу
|
3
|
+
module Pushkin
|
4
|
+
module TokenFilters
|
5
|
+
class TokenFilter
|
6
|
+
|
7
|
+
# Фильтрует токены по принадлежности к платформе и возвращает новый список
|
8
|
+
def filter_tokens(tokens)
|
9
|
+
(tokens.to_a || []).select { |token| self.necessary?(token) }
|
10
|
+
end
|
11
|
+
|
12
|
+
# Возвращает true, если переданный token принадлежит нужной платформе
|
13
|
+
def necessary?(token)
|
14
|
+
raise Exception.new("You must implement 'necessary?' method")
|
15
|
+
end
|
16
|
+
|
17
|
+
# Возвращает экземпляр сервиса по отправке уведомлений на конкретную платформу
|
18
|
+
def get_sending_service(tokens, payload)
|
19
|
+
raise Exception.new("You must implement 'get_sending_service' method")
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Pushkin</title>
|
5
|
+
<%= stylesheet_link_tag "pushkin/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "pushkin/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Pushkin
|
2
|
+
class SetupGenerator < Rails::Generators::Base
|
3
|
+
|
4
|
+
include ::Rails::Generators::Migration
|
5
|
+
include ::Rails::Generators::Migration
|
6
|
+
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
8
|
+
|
9
|
+
def self.next_migration_number(dir)
|
10
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup_application
|
14
|
+
file_name = "tokens_controller.rb"
|
15
|
+
copy_file file_name, "app/controllers/pushkin/api/v1/#{file_name}"
|
16
|
+
migration_template "create_pushkin_tables.rb", "db/migrate/create_pushkin_tables.rb"
|
17
|
+
|
18
|
+
route "namespace :pushkin do\n" +
|
19
|
+
" namespace :api do\n" +
|
20
|
+
" namespace :v1 do\n" +
|
21
|
+
" resources :tokens, only: [:create]\n" +
|
22
|
+
" end\n" +
|
23
|
+
" end\n" +
|
24
|
+
" end\n"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
class CreatePushkinTables < ActiveRecord::Migration[5.1]
|
2
|
+
def change
|
3
|
+
create_table :pushkin_tokens do |t|
|
4
|
+
t.integer :user_id
|
5
|
+
t.integer :platform
|
6
|
+
t.boolean :is_active, default: true
|
7
|
+
t.string :token
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index :pushkin_tokens, [:user_id, :is_active]
|
13
|
+
add_index :pushkin_tokens, [:token, :platform], unique: true
|
14
|
+
|
15
|
+
create_table :pushkin_notifications do |t|
|
16
|
+
t.datetime :start_at
|
17
|
+
t.datetime :started_at
|
18
|
+
t.datetime :finished_at
|
19
|
+
t.integer :tokens_provider_id
|
20
|
+
t.string :tokens_provider_type
|
21
|
+
t.integer :payload_id
|
22
|
+
t.string :payload_type
|
23
|
+
t.string :notification_type
|
24
|
+
|
25
|
+
t.timestamps
|
26
|
+
end
|
27
|
+
|
28
|
+
add_index :pushkin_notifications, [:start_at, :started_at]
|
29
|
+
add_index :pushkin_notifications, [:tokens_provider_type, :tokens_provider_id],
|
30
|
+
name: 'index_pushkin_nots_on_toks_provider_type_and_toks_provider_id'
|
31
|
+
add_index :pushkin_notifications, [:payload_type, :payload_id]
|
32
|
+
add_index :pushkin_notifications, [:notification_type, :start_at]
|
33
|
+
|
34
|
+
create_table :pushkin_payloads do |t|
|
35
|
+
t.string :title
|
36
|
+
t.string :body
|
37
|
+
t.string :web_click_action
|
38
|
+
t.string :android_click_action
|
39
|
+
t.string :ios_click_action
|
40
|
+
t.string :web_icon
|
41
|
+
t.string :android_icon
|
42
|
+
t.string :ios_icon
|
43
|
+
t.string :data
|
44
|
+
t.boolean :is_android_data_message, default: false
|
45
|
+
t.boolean :is_ios_data_message, default: false
|
46
|
+
t.boolean :is_web_data_message, default: false
|
47
|
+
|
48
|
+
t.timestamps
|
49
|
+
end
|
50
|
+
|
51
|
+
create_table :pushkin_tokens_providers do |t|
|
52
|
+
|
53
|
+
t.timestamps
|
54
|
+
end
|
55
|
+
|
56
|
+
create_table :pushkin_tokens_provider_users do |t|
|
57
|
+
t.integer :tokens_provider_id
|
58
|
+
t.integer :user_id
|
59
|
+
|
60
|
+
t.timestamps
|
61
|
+
end
|
62
|
+
|
63
|
+
add_index :pushkin_tokens_provider_users, :tokens_provider_id
|
64
|
+
add_index :pushkin_tokens_provider_users, :user_id
|
65
|
+
|
66
|
+
create_table :pushkin_push_sending_results do |t|
|
67
|
+
t.boolean :success
|
68
|
+
t.string :error
|
69
|
+
t.datetime :started_at
|
70
|
+
t.datetime :finished_at
|
71
|
+
t.integer :notification_id
|
72
|
+
t.integer :platform
|
73
|
+
|
74
|
+
t.timestamps
|
75
|
+
end
|
76
|
+
|
77
|
+
add_index :pushkin_push_sending_results, :notification_id
|
78
|
+
|
79
|
+
create_table :pushkin_token_results do |t|
|
80
|
+
t.string :status
|
81
|
+
t.string :error
|
82
|
+
t.integer :push_sending_result_id
|
83
|
+
t.integer :token_id
|
84
|
+
end
|
85
|
+
|
86
|
+
add_index :pushkin_token_results, :push_sending_result_id
|
87
|
+
add_index :pushkin_token_results, :token_id
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Pushkin::Api::V1::TokensController < ApplicationController
|
2
|
+
|
3
|
+
skip_before_action :verify_authenticity_token
|
4
|
+
|
5
|
+
# Добавить здесь свою логику авторизации пользователя
|
6
|
+
#include AuthenticationHelper
|
7
|
+
#before_action :authenticate_user
|
8
|
+
|
9
|
+
include Pushkin::Api::V1::Concerns::TokensHelper
|
10
|
+
|
11
|
+
def current_pushkin_user
|
12
|
+
# Возвратить ссылку на авторизованного пользователя
|
13
|
+
#current_user
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'pushkin'
|
data/lib/pushkin.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "pushkin/engine"
|
2
|
+
|
3
|
+
module Pushkin
|
4
|
+
|
5
|
+
def self.android_provider
|
6
|
+
@@android_provider ||= :fcm
|
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
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pushkin-library
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bazov Peter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: faraday
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.12'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0.16'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.12'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0.16'
|
53
|
+
description: Library for planning and sending Push-Notifications on iOS, Android and
|
54
|
+
Web
|
55
|
+
email:
|
56
|
+
- petr@sequenia.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- MIT-LICENSE
|
62
|
+
- README.md
|
63
|
+
- Rakefile
|
64
|
+
- app/assets/config/pushkin_manifest.js
|
65
|
+
- app/assets/javascripts/pushkin/application.js
|
66
|
+
- app/assets/javascripts/pushkin/firebase/push_notifications.js
|
67
|
+
- app/assets/javascripts/pushkin/main.js
|
68
|
+
- app/assets/stylesheets/pushkin/application.css
|
69
|
+
- app/controllers/pushkin/api/v1/concerns/api_helper.rb
|
70
|
+
- app/controllers/pushkin/api/v1/concerns/tokens_helper.rb
|
71
|
+
- app/controllers/pushkin/application_controller.rb
|
72
|
+
- app/fabrics/pushkin/notification_fabric.rb
|
73
|
+
- app/helpers/pushkin/application_helper.rb
|
74
|
+
- app/jobs/pushkin/application_job.rb
|
75
|
+
- app/jobs/pushkin/send_job.rb
|
76
|
+
- app/mailers/pushkin/application_mailer.rb
|
77
|
+
- app/models/pushkin/application_record.rb
|
78
|
+
- app/models/pushkin/concerns/pushkin_user.rb
|
79
|
+
- app/models/pushkin/notification.rb
|
80
|
+
- app/models/pushkin/payload.rb
|
81
|
+
- app/models/pushkin/push_sending_result.rb
|
82
|
+
- app/models/pushkin/token.rb
|
83
|
+
- app/models/pushkin/token_result.rb
|
84
|
+
- app/models/pushkin/tokens_provider.rb
|
85
|
+
- app/models/pushkin/tokens_provider_user.rb
|
86
|
+
- app/services/pushkin/fcm/send_android_push_service.rb
|
87
|
+
- app/services/pushkin/fcm/send_fcm_push_service.rb
|
88
|
+
- app/services/pushkin/fcm/send_ios_push_service.rb
|
89
|
+
- app/services/pushkin/fcm/send_web_push_service.rb
|
90
|
+
- app/services/pushkin/send_push_service.rb
|
91
|
+
- app/services/pushkin/token_filters/android_token_filter.rb
|
92
|
+
- app/services/pushkin/token_filters/ios_token_filter.rb
|
93
|
+
- app/services/pushkin/token_filters/token_filter.rb
|
94
|
+
- app/services/pushkin/token_filters/web_token_filter.rb
|
95
|
+
- app/views/layouts/pushkin/application.html.erb
|
96
|
+
- lib/generators/pushkin/setup_generator.rb
|
97
|
+
- lib/generators/pushkin/templates/create_pushkin_tables.rb
|
98
|
+
- lib/generators/pushkin/templates/tokens_controller.rb
|
99
|
+
- lib/pushkin-library.rb
|
100
|
+
- lib/pushkin.rb
|
101
|
+
- lib/pushkin/engine.rb
|
102
|
+
- lib/pushkin/version.rb
|
103
|
+
- lib/tasks/pushkin_tasks.rake
|
104
|
+
homepage: http://sequenia.com/
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.6.14
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Push-Notifications Library
|
128
|
+
test_files: []
|