pusher-push-notifications 2.0.1 → 2.0.2
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/.coveralls.yml +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +1 -2
- data/lib/pusher/push_notifications/use_cases/delete_user.rb +3 -22
- data/lib/pusher/push_notifications/use_cases/generate_token.rb +4 -21
- data/lib/pusher/push_notifications/use_cases/publish.rb +8 -32
- data/lib/pusher/push_notifications/use_cases/publish_to_users.rb +2 -22
- data/lib/pusher/push_notifications/version.rb +1 -1
- data/lib/pusher/push_notifications.rb +26 -7
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b6ed8156fc1fb15e299754cc324357877136643d3fb11b9ee2df005eac629a0
|
4
|
+
data.tar.gz: 2beec8b29a6f2a8760490e4e8bb50e33cb0a6216147a964ee55f45522c5a3c71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 995111be0507cf0010fc3dbd1dd0a7661ad23ba64409e74cd72f222ed8e938b28df8d751fb28c2fe19bfff13cde35ece544937bf0b314ead0abf651c16b4459f
|
7
|
+
data.tar.gz: b293b85bbd4c64bf6300dc7b2191afc33076736ae722fd56482c89d4b934190ad0da3c2b5da522c6a961c24c9d5473fd4d33a9c3bcf02887abd79cfe34c3bbb1
|
data/.coveralls.yml
CHANGED
@@ -1 +1 @@
|
|
1
|
-
repo_token:
|
1
|
+
repo_token: secret
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Pusher Beams Ruby Server SDK
|
2
2
|
|
3
|
-
[](https://coveralls.io/github/pusher/push-notifications-ruby?branch=update-sdk)
|
3
|
+
[](https://github.com/pusher/push-notifications-ruby/actions/workflows/test.yml) [](https://coveralls.io/github/pusher/push-notifications-ruby) [](https://rubygems.org/gems/pusher-push-notifications)
|
5
4
|
|
6
5
|
Pusher Beams using the Pusher system.
|
7
6
|
|
@@ -6,37 +6,18 @@ module Pusher
|
|
6
6
|
class DeleteUser
|
7
7
|
class UserDeletionError < RuntimeError; end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(user:)
|
16
|
-
@user = user
|
17
|
-
@user_id = Pusher::PushNotifications::UserId.new
|
18
|
-
|
9
|
+
# Contacts the Beams service
|
10
|
+
# to remove all the devices of the given user.
|
11
|
+
def self.delete_user(client, user:)
|
19
12
|
raise UserDeletionError, 'User Id cannot be empty.' if user.empty?
|
20
13
|
|
21
14
|
if user.length > UserId::MAX_USER_ID_LENGTH
|
22
15
|
raise UserDeletionError, 'User id length too long ' \
|
23
16
|
"(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1} characters)"
|
24
17
|
end
|
25
|
-
end
|
26
18
|
|
27
|
-
# Contacts the Beams service
|
28
|
-
# to remove all the devices of the given user.
|
29
|
-
def delete_user
|
30
19
|
client.delete(user)
|
31
20
|
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
attr_reader :user
|
36
|
-
|
37
|
-
def client
|
38
|
-
@client ||= PushNotifications::Client.new
|
39
|
-
end
|
40
21
|
end
|
41
22
|
end
|
42
23
|
end
|
@@ -6,35 +6,18 @@ module Pusher
|
|
6
6
|
class GenerateToken
|
7
7
|
class GenerateTokenError < RuntimeError; end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
new(*args, **kwargs).generate_token
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(user:)
|
16
|
-
@user = user
|
17
|
-
@user_id = Pusher::PushNotifications::UserId.new
|
18
|
-
|
9
|
+
# Creates a signed JWT for a user id.
|
10
|
+
def self.generate_token(user:)
|
19
11
|
raise GenerateTokenError, 'User Id cannot be empty.' if user.empty?
|
20
12
|
|
21
13
|
if user.length > UserId::MAX_USER_ID_LENGTH
|
22
14
|
raise GenerateTokenError, 'User id length too long ' \
|
23
15
|
"(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1} characters)"
|
24
16
|
end
|
25
|
-
end
|
26
17
|
|
27
|
-
|
28
|
-
def generate_token
|
29
|
-
{ 'token' => jwt_token.generate(user) }
|
30
|
-
end
|
18
|
+
jwt_token = PushNotifications::Token.new
|
31
19
|
|
32
|
-
|
33
|
-
|
34
|
-
attr_reader :user
|
35
|
-
|
36
|
-
def jwt_token
|
37
|
-
@jwt_token ||= PushNotifications::Token.new
|
20
|
+
{ 'token' => jwt_token.generate(user) }
|
38
21
|
end
|
39
22
|
end
|
40
23
|
end
|
@@ -6,21 +6,16 @@ module Pusher
|
|
6
6
|
class Publish
|
7
7
|
class PublishError < RuntimeError; end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
new(*args, **kwargs).publish_to_interests
|
16
|
-
end
|
9
|
+
# Publish the given payload to the specified interests.
|
10
|
+
# <b>DEPRECATED:</b> Please use <tt>publish_to_interests</tt> instead.
|
11
|
+
def self.publish(client, interests:, payload: {})
|
12
|
+
warn "[DEPRECATION] `publish` is deprecated. \
|
13
|
+
Please use `publish_to_interests` instead."
|
14
|
+
publish_to_interests(client, interests: interests, payload: payload)
|
17
15
|
end
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
@payload = payload
|
22
|
-
@user_id = Pusher::PushNotifications::UserId.new
|
23
|
-
|
17
|
+
# Publish the given payload to the specified interests.
|
18
|
+
def self.publish_to_interests(client, interests:, payload: {})
|
24
19
|
valid_interest_pattern = /^(_|-|=|@|,|\.|:|[A-Z]|[a-z]|[0-9])*$/
|
25
20
|
|
26
21
|
interests.each do |interest|
|
@@ -38,29 +33,10 @@ module Pusher
|
|
38
33
|
raise PublishError, "Number of interests #{interests.length}" \
|
39
34
|
' exceeds maximum of 100'
|
40
35
|
end
|
41
|
-
end
|
42
36
|
|
43
|
-
# Publish the given payload to the specified interests.
|
44
|
-
# <b>DEPRECATED:</b> Please use <tt>publish_to_interests</tt> instead.
|
45
|
-
def publish
|
46
|
-
warn "[DEPRECATION] `publish` is deprecated. \
|
47
|
-
Please use `publish_to_interests` instead."
|
48
|
-
publish_to_interests
|
49
|
-
end
|
50
|
-
|
51
|
-
# Publish the given payload to the specified interests.
|
52
|
-
def publish_to_interests
|
53
37
|
data = { interests: interests }.merge!(payload)
|
54
38
|
client.post('publishes', data)
|
55
39
|
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
attr_reader :interests, :payload
|
60
|
-
|
61
|
-
def client
|
62
|
-
@client ||= PushNotifications::Client.new
|
63
|
-
end
|
64
40
|
end
|
65
41
|
end
|
66
42
|
end
|
@@ -6,17 +6,8 @@ module Pusher
|
|
6
6
|
class PublishToUsers
|
7
7
|
class UsersPublishError < RuntimeError; end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
new(*args, **kwargs).publish_to_users
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(users:, payload: {})
|
16
|
-
@users = users
|
17
|
-
@user_id = Pusher::PushNotifications::UserId.new
|
18
|
-
@payload = payload
|
19
|
-
|
9
|
+
# Publish the given payload to the specified users.
|
10
|
+
def self.publish_to_users(client, users:, payload: {})
|
20
11
|
users.each do |user|
|
21
12
|
raise UsersPublishError, 'User Id cannot be empty.' if user.empty?
|
22
13
|
|
@@ -33,21 +24,10 @@ module Pusher
|
|
33
24
|
raise UsersPublishError, "Number of user ids #{users.length} "\
|
34
25
|
"exceeds maximum of #{UserId::MAX_NUM_USER_IDS}."
|
35
26
|
end
|
36
|
-
end
|
37
27
|
|
38
|
-
# Publish the given payload to the specified users.
|
39
|
-
def publish_to_users
|
40
28
|
data = { users: users }.merge!(payload)
|
41
29
|
client.post('publishes/users', data)
|
42
30
|
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
attr_reader :users, :payload
|
47
|
-
|
48
|
-
def client
|
49
|
-
@client ||= PushNotifications::Client.new
|
50
|
-
end
|
51
31
|
end
|
52
32
|
end
|
53
33
|
end
|
@@ -14,15 +14,8 @@ module Pusher
|
|
14
14
|
class PushError < RuntimeError; end
|
15
15
|
|
16
16
|
class << self
|
17
|
-
extend Forwardable
|
18
|
-
|
19
17
|
attr_reader :instance_id, :secret_key
|
20
18
|
|
21
|
-
def_delegators UseCases::Publish, :publish, :publish_to_interests
|
22
|
-
def_delegators UseCases::PublishToUsers, :publish_to_users
|
23
|
-
def_delegators UseCases::DeleteUser, :delete_user
|
24
|
-
def_delegators UseCases::GenerateToken, :generate_token
|
25
|
-
|
26
19
|
def configure
|
27
20
|
yield(self)
|
28
21
|
# returning a duplicate of `self` to allow multiple clients to be
|
@@ -53,6 +46,32 @@ module Pusher
|
|
53
46
|
|
54
47
|
"https://#{@instance_id}.pushnotifications.pusher.com"
|
55
48
|
end
|
49
|
+
|
50
|
+
def publish(interests:, payload: {})
|
51
|
+
UseCases::Publish.publish(client, interests: interests, payload: payload)
|
52
|
+
end
|
53
|
+
|
54
|
+
def publish_to_interests(interests:, payload: {})
|
55
|
+
UseCases::Publish.publish_to_interests(client, interests: interests, payload: payload)
|
56
|
+
end
|
57
|
+
|
58
|
+
def publish_to_users(users:, payload: {})
|
59
|
+
UseCases::PublishToUsers.publish_to_users(client, users: users, payload: payload)
|
60
|
+
end
|
61
|
+
|
62
|
+
def delete_user(user:)
|
63
|
+
UseCases::DeleteUser.delete_user(client, user: user)
|
64
|
+
end
|
65
|
+
|
66
|
+
def generate_token(user:)
|
67
|
+
UseCases::GenerateToken.generate_token(user: user)
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def client
|
73
|
+
@client ||= Client.new(config: self)
|
74
|
+
end
|
56
75
|
end
|
57
76
|
end
|
58
77
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pusher-push-notifications
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Medeiros
|
8
8
|
- Pusher
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jwt
|
@@ -229,7 +229,7 @@ dependencies:
|
|
229
229
|
- - ">="
|
230
230
|
- !ruby/object:Gem::Version
|
231
231
|
version: 3.0.1
|
232
|
-
description:
|
232
|
+
description:
|
233
233
|
email:
|
234
234
|
- lucastoc@gmail.com
|
235
235
|
- support@pusher.com
|
@@ -271,7 +271,7 @@ homepage: https://github.com/pusher/push-notifications-ruby
|
|
271
271
|
licenses:
|
272
272
|
- MIT
|
273
273
|
metadata: {}
|
274
|
-
post_install_message:
|
274
|
+
post_install_message:
|
275
275
|
rdoc_options: []
|
276
276
|
require_paths:
|
277
277
|
- lib
|
@@ -287,7 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
287
287
|
version: '0'
|
288
288
|
requirements: []
|
289
289
|
rubygems_version: 3.1.2
|
290
|
-
signing_key:
|
290
|
+
signing_key:
|
291
291
|
specification_version: 4
|
292
292
|
summary: Pusher Push Notifications Ruby server SDK
|
293
293
|
test_files: []
|