pusher-push-notifications 0.3.0 → 1.2.1
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 +5 -5
- data/.rubocop.yml +11 -7
- data/.travis.yml +3 -0
- data/CHANGELOG.md +30 -0
- data/Gemfile.lock +28 -18
- data/README.md +19 -12
- data/bin/console +1 -1
- data/lib/pusher/push_notifications.rb +29 -2
- data/lib/pusher/push_notifications/client.rb +43 -9
- data/lib/pusher/push_notifications/token.rb +26 -0
- data/lib/pusher/push_notifications/use_cases/delete_user.rb +42 -0
- data/lib/pusher/push_notifications/use_cases/generate_token.rb +41 -0
- data/lib/pusher/push_notifications/use_cases/publish.rb +28 -10
- data/lib/pusher/push_notifications/use_cases/publish_to_users.rb +54 -0
- data/lib/pusher/push_notifications/user_id.rb +10 -0
- data/lib/pusher/push_notifications/version.rb +1 -1
- data/lib/{pusher-push-notifications.rb → pusher_push_notifications.rb} +0 -0
- data/pusher-push-notifications.gemspec +8 -6
- metadata +78 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6fe6dbd5b9b826625951a290bfa388a362087df759c0929455df20021ef22679
|
4
|
+
data.tar.gz: 119d2dae3a329176330ce470fd375d1ed40ae559a2bab4940e5971009ee793ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6df0bbafe1b2aadf7a02c8701b9e8b7cb6507241eda2971a043d25bcecf26524d0d9bf9cf0ca58a64d745f2fbce6fd512c5ca72e652b1713385a43929af58a99
|
7
|
+
data.tar.gz: 6830c408c68b69c69dec7bb1ce21ae2e070b39fd863a64b3f3b8c02ac3a0e301164ff12e634250252d1106a19af0a0c501fbf23cd693b8f516acf8522084daeb
|
data/.rubocop.yml
CHANGED
@@ -5,19 +5,23 @@ AllCops:
|
|
5
5
|
TargetRubyVersion: 2.4.0
|
6
6
|
|
7
7
|
Metrics/LineLength:
|
8
|
-
|
8
|
+
Enabled:
|
9
|
+
Max: 80
|
10
|
+
|
11
|
+
Style/GuardClause:
|
12
|
+
Enabled: false
|
9
13
|
|
10
14
|
Metrics/MethodLength:
|
11
|
-
|
12
|
-
- 'spec/**/*.rb'
|
15
|
+
Enabled: false
|
13
16
|
|
14
|
-
|
15
|
-
|
17
|
+
Metrics/AbcSize:
|
18
|
+
Enabled: false
|
16
19
|
|
17
20
|
Metrics/ModuleLength:
|
18
21
|
Exclude:
|
19
|
-
-
|
22
|
+
- "spec/**/*.rb"
|
20
23
|
|
21
24
|
Metrics/BlockLength:
|
22
25
|
Exclude:
|
23
|
-
-
|
26
|
+
- "spec/**/*.rb"
|
27
|
+
- "pusher-push-notifications.gemspec"
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
6
|
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased](https://github.com/pusher/push-notifications-ruby/compare/v1.2.1...HEAD)
|
9
|
+
|
10
|
+
## [1.2.1](https://github.com/pusher/push-notifications-ruby/compare/v1.2.0...v1.2.1) - 2020-06-26
|
11
|
+
|
12
|
+
Fixed
|
13
|
+
|
14
|
+
Endpoint also allows the scheme to be configured to enable for local development.
|
15
|
+
|
16
|
+
## [1.2.0](https://github.com/pusher/push-notifications-ruby/compare/v1.1.0...v1.2.0) - 2020-06-25
|
17
|
+
|
18
|
+
Added
|
19
|
+
|
20
|
+
Support for "endpoint" overrides to allow for internal integration testing.
|
21
|
+
|
22
|
+
## [1.1.0](https://github.com/pusher/push-notifications-ruby/compare/v1.0.0...v1.1.0) - 2019-02-22
|
23
|
+
|
24
|
+
Added
|
25
|
+
|
26
|
+
Support for "Authenticated Users" feature: publishToUsers, generateToken and deleteUser.
|
27
|
+
|
28
|
+
## [1.0.0](https://github.com/pusher/push-notifications-ruby/compare/v0.3.0...v1.0.0) - 2018-07-31
|
29
|
+
|
30
|
+
- General availability (GA) release.
|
data/Gemfile.lock
CHANGED
@@ -1,26 +1,31 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pusher-push-notifications (
|
5
|
-
caze
|
6
|
-
|
4
|
+
pusher-push-notifications (1.2.1)
|
5
|
+
caze (~> 0)
|
6
|
+
jwt (~> 2.1, >= 2.1.0)
|
7
|
+
rest-client (~> 2.0, >= 2.0.2)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
11
|
-
activesupport (5.
|
12
|
+
activesupport (5.2.2)
|
12
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
-
i18n (
|
14
|
+
i18n (>= 0.7, < 2)
|
14
15
|
minitest (~> 5.1)
|
15
16
|
tzinfo (~> 1.1)
|
16
17
|
addressable (2.5.2)
|
17
18
|
public_suffix (>= 2.0.2, < 4.0)
|
18
19
|
ast (2.3.0)
|
19
|
-
byebug (
|
20
|
+
byebug (10.0.2)
|
20
21
|
caze (0.2.2)
|
21
22
|
activesupport (>= 3)
|
23
|
+
codecov (0.1.10)
|
24
|
+
json
|
25
|
+
simplecov
|
26
|
+
url
|
22
27
|
coderay (1.1.2)
|
23
|
-
concurrent-ruby (1.
|
28
|
+
concurrent-ruby (1.1.4)
|
24
29
|
coveralls (0.8.21)
|
25
30
|
json (>= 1.8, < 3)
|
26
31
|
simplecov (~> 0.14.1)
|
@@ -31,34 +36,36 @@ GEM
|
|
31
36
|
safe_yaml (~> 1.0.0)
|
32
37
|
diff-lcs (1.3)
|
33
38
|
docile (1.1.5)
|
34
|
-
domain_name (0.5.
|
39
|
+
domain_name (0.5.20180417)
|
35
40
|
unf (>= 0.0.5, < 1.0.0)
|
36
41
|
dotenv (2.2.1)
|
37
42
|
hashdiff (0.3.7)
|
38
43
|
http-cookie (1.0.3)
|
39
44
|
domain_name (~> 0.5)
|
40
|
-
i18n (
|
45
|
+
i18n (1.5.3)
|
41
46
|
concurrent-ruby (~> 1.0)
|
42
47
|
json (2.1.0)
|
43
|
-
|
44
|
-
|
48
|
+
jwt (2.1.0)
|
49
|
+
method_source (0.9.2)
|
50
|
+
mime-types (3.2.2)
|
45
51
|
mime-types-data (~> 3.2015)
|
46
|
-
mime-types-data (3.
|
52
|
+
mime-types-data (3.2018.0812)
|
47
53
|
minitest (5.11.3)
|
48
54
|
netrc (0.11.0)
|
49
55
|
parallel (1.12.1)
|
50
56
|
parser (2.4.0.2)
|
51
57
|
ast (~> 2.3)
|
52
58
|
powerpack (0.1.1)
|
53
|
-
pry (0.
|
59
|
+
pry (0.12.2)
|
54
60
|
coderay (~> 1.1.0)
|
55
61
|
method_source (~> 0.9.0)
|
56
|
-
pry-byebug (3.
|
57
|
-
byebug (~>
|
62
|
+
pry-byebug (3.6.0)
|
63
|
+
byebug (~> 10.0)
|
58
64
|
pry (~> 0.10)
|
59
65
|
public_suffix (3.0.1)
|
60
66
|
rainbow (3.0.0)
|
61
67
|
rake (10.5.0)
|
68
|
+
rb-readline (0.5.5)
|
62
69
|
rest-client (2.0.2)
|
63
70
|
http-cookie (>= 1.0.2, < 2.0)
|
64
71
|
mime-types (>= 1.16, < 4.0)
|
@@ -101,6 +108,7 @@ GEM
|
|
101
108
|
unf_ext
|
102
109
|
unf_ext (0.0.7.5)
|
103
110
|
unicode-display_width (1.3.0)
|
111
|
+
url (0.3.2)
|
104
112
|
vcr (3.0.3)
|
105
113
|
webmock (3.1.1)
|
106
114
|
addressable (>= 2.3.6)
|
@@ -112,15 +120,17 @@ PLATFORMS
|
|
112
120
|
|
113
121
|
DEPENDENCIES
|
114
122
|
bundler (~> 1.16)
|
123
|
+
codecov (~> 0)
|
115
124
|
coveralls (~> 0.8.21)
|
116
125
|
dotenv (~> 2.2, >= 2.2.1)
|
117
|
-
pry-byebug
|
126
|
+
pry-byebug (~> 3.6, >= 3.6.0)
|
118
127
|
pusher-push-notifications!
|
119
128
|
rake (~> 10.0)
|
129
|
+
rb-readline (~> 0)
|
120
130
|
rspec (~> 3.0)
|
121
|
-
rubocop
|
131
|
+
rubocop (>= 0.49.0)
|
122
132
|
vcr (~> 3.0, >= 3.0.3)
|
123
133
|
webmock (~> 3.0, >= 3.0.1)
|
124
134
|
|
125
135
|
BUNDLED WITH
|
126
|
-
1.16.
|
136
|
+
1.16.2
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
# Pusher
|
1
|
+
# Pusher Beams Ruby Server SDK
|
2
2
|
|
3
3
|
[](https://travis-ci.org/pusher/push-notifications-ruby)
|
4
4
|
[](https://coveralls.io/github/pusher/push-notifications-ruby?branch=update-sdk)
|
5
5
|
|
6
|
-
|
6
|
+
Pusher Beams using the Pusher system.
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -22,19 +22,23 @@ gem 'pusher-push-notifications'
|
|
22
22
|
This configuration can be done anywhere you want, but if you are using rails the better place to put it is inside an initializer
|
23
23
|
|
24
24
|
```ruby
|
25
|
+
require 'pusher/push_notifications'
|
26
|
+
|
25
27
|
Pusher::PushNotifications.configure do |config|
|
26
28
|
config.instance_id = ENV['PUSHER_INSTANCE_ID'] # or the value directly
|
27
29
|
config.secret_key = ENV['PUSHER_SECRET_KEY']
|
28
30
|
end
|
29
31
|
```
|
30
32
|
|
31
|
-
Where `instance_id` and `secret_key` are the values of the instance you created in the
|
33
|
+
Where `instance_id` and `secret_key` are the values of the instance you created in the Pusher Beams dashboard
|
32
34
|
|
33
35
|
## Usage
|
34
36
|
|
35
37
|
After the configuration is done you can push notifications like this:
|
36
38
|
|
37
39
|
```ruby
|
40
|
+
require 'pusher/push_notifications'
|
41
|
+
|
38
42
|
data = {
|
39
43
|
apns: {
|
40
44
|
aps: {
|
@@ -52,7 +56,17 @@ data = {
|
|
52
56
|
}
|
53
57
|
}
|
54
58
|
|
55
|
-
|
59
|
+
# Publish the given 'data' to the specified interests.
|
60
|
+
Pusher::PushNotifications.publish_to_interests(interests: ['hello'], payload: data)
|
61
|
+
|
62
|
+
# Publish the given 'data' to the specified users.
|
63
|
+
Pusher::PushNotifications.publish_to_users(users: ['jonathan', 'jordan', 'luis', 'luka', 'mina'], payload: data)
|
64
|
+
|
65
|
+
# Authenticate User
|
66
|
+
Pusher::PushNotifications.generate_token(user: 'Elmo')
|
67
|
+
|
68
|
+
# Delete User
|
69
|
+
Pusher::PushNotifications.delete_user(user: 'Elmo')
|
56
70
|
```
|
57
71
|
|
58
72
|
The return of this call is a ruby struct containing the http status code (`status`) the response body (`content`) and an `ok?` attribute saying if the notification was successful or not.
|
@@ -61,14 +75,7 @@ The return of this call is a ruby struct containing the http status code (`statu
|
|
61
75
|
|
62
76
|
## Errors
|
63
77
|
|
64
|
-
|
65
|
-
|
66
|
-
HTTP Status | Reason
|
67
|
-
--- | ---
|
68
|
-
401 | Incorrect secret key
|
69
|
-
400 | Payload too big (10Kb limit), Payload invalid, Payload in a wrong schema, instance_id missing
|
70
|
-
404 | Instance not found
|
71
|
-
500 | Internal server error
|
78
|
+
All available error responses can be be found [here](https://docs.pusher.com/beams/reference/publish-api#error-responses).
|
72
79
|
|
73
80
|
## Development
|
74
81
|
|
data/bin/console
CHANGED
@@ -4,7 +4,12 @@ require 'caze'
|
|
4
4
|
|
5
5
|
require_relative './push_notifications/client'
|
6
6
|
require_relative './push_notifications/use_cases/publish'
|
7
|
+
require_relative './push_notifications/use_cases/publish_to_users'
|
8
|
+
require_relative './push_notifications/use_cases/delete_user'
|
9
|
+
require_relative './push_notifications/use_cases/generate_token'
|
7
10
|
require_relative './push_notifications/version'
|
11
|
+
require_relative './push_notifications/user_id'
|
12
|
+
require_relative './push_notifications/token'
|
8
13
|
|
9
14
|
module Pusher
|
10
15
|
module PushNotifications
|
@@ -13,6 +18,10 @@ module Pusher
|
|
13
18
|
class PushError < RuntimeError; end
|
14
19
|
|
15
20
|
has_use_case :publish, UseCases::Publish
|
21
|
+
has_use_case :publish_to_interests, UseCases::Publish
|
22
|
+
has_use_case :publish_to_users, UseCases::PublishToUsers
|
23
|
+
has_use_case :delete_user, UseCases::DeleteUser
|
24
|
+
has_use_case :generate_token, UseCases::GenerateToken
|
16
25
|
|
17
26
|
class << self
|
18
27
|
attr_reader :instance_id, :secret_key
|
@@ -23,14 +32,32 @@ module Pusher
|
|
23
32
|
end
|
24
33
|
|
25
34
|
def instance_id=(instance_id)
|
26
|
-
|
35
|
+
if instance_id.nil? || instance_id.delete(' ').empty?
|
36
|
+
raise PushError, 'Invalid instance id'
|
37
|
+
end
|
27
38
|
@instance_id = instance_id
|
28
39
|
end
|
29
40
|
|
30
41
|
def secret_key=(secret_key)
|
31
|
-
|
42
|
+
if secret_key.nil? || secret_key.delete(' ').empty?
|
43
|
+
raise PushError, 'Invalid secret key'
|
44
|
+
end
|
32
45
|
@secret_key = secret_key
|
33
46
|
end
|
47
|
+
|
48
|
+
def endpoint=(endpoint)
|
49
|
+
if !endpoint.nil? && endpoint.delete(' ').empty?
|
50
|
+
raise PushError, 'Invalid endpoint override'
|
51
|
+
end
|
52
|
+
|
53
|
+
@endpoint = endpoint
|
54
|
+
end
|
55
|
+
|
56
|
+
def endpoint
|
57
|
+
return @endpoint unless @endpoint.nil?
|
58
|
+
|
59
|
+
"https://#{@instance_id}.pushnotifications.pusher.com"
|
60
|
+
end
|
34
61
|
end
|
35
62
|
end
|
36
63
|
end
|
@@ -9,8 +9,6 @@ module Pusher
|
|
9
9
|
class Client
|
10
10
|
extend Forwardable
|
11
11
|
|
12
|
-
BASE_URL = 'pushnotifications.pusher.com/publish_api/v1/instances'
|
13
|
-
|
14
12
|
Response = Struct.new(:status, :content, :ok?)
|
15
13
|
|
16
14
|
def initialize(config: PushNotifications)
|
@@ -18,7 +16,7 @@ module Pusher
|
|
18
16
|
end
|
19
17
|
|
20
18
|
def post(resource, payload = {})
|
21
|
-
url =
|
19
|
+
url = build_publish_url(resource)
|
22
20
|
body = payload.to_json
|
23
21
|
|
24
22
|
RestClient::Request.execute(
|
@@ -26,27 +24,63 @@ module Pusher
|
|
26
24
|
payload: body, headers: headers
|
27
25
|
) do |response|
|
28
26
|
status = response.code
|
29
|
-
|
30
|
-
|
27
|
+
if json?(response.body)
|
28
|
+
body = JSON.parse(response.body)
|
29
|
+
Response.new(status, body, status == 200)
|
30
|
+
else
|
31
|
+
Response.new(status, nil, false)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete(user)
|
37
|
+
url_encoded_user_id = CGI.escape(user)
|
38
|
+
url = build_users_url(url_encoded_user_id)
|
39
|
+
|
40
|
+
RestClient::Request.execute(
|
41
|
+
method: :delete, url: url,
|
42
|
+
headers: headers
|
43
|
+
) do |response|
|
44
|
+
status = response.code
|
45
|
+
case status
|
46
|
+
when 200
|
47
|
+
Response.new(status, nil, true)
|
48
|
+
else
|
49
|
+
Response.new(status, nil, false)
|
50
|
+
end
|
31
51
|
end
|
32
52
|
end
|
33
53
|
|
34
54
|
private
|
35
55
|
|
36
56
|
attr_reader :config
|
37
|
-
def_delegators :@config, :instance_id, :secret_key
|
57
|
+
def_delegators :@config, :instance_id, :secret_key, :endpoint
|
58
|
+
|
59
|
+
def build_publish_url(resource)
|
60
|
+
"#{endpoint}/publish_api/v1/instances/#{instance_id}/#{resource}"
|
61
|
+
end
|
38
62
|
|
39
|
-
def
|
40
|
-
"
|
63
|
+
def build_users_url(user)
|
64
|
+
"#{endpoint}/customer_api/v1/instances/#{instance_id}/users/#{user}"
|
41
65
|
end
|
42
66
|
|
43
67
|
def headers
|
44
68
|
{
|
45
69
|
content_type: 'application/json',
|
46
70
|
accept: :json,
|
47
|
-
Authorization: "Bearer #{secret_key}"
|
71
|
+
Authorization: "Bearer #{secret_key}",
|
72
|
+
'X-Pusher-Library':
|
73
|
+
'pusher-push-notifications-ruby ' \
|
74
|
+
"#{Pusher::PushNotifications::VERSION}"
|
48
75
|
}
|
49
76
|
end
|
77
|
+
|
78
|
+
def json?(response)
|
79
|
+
JSON.parse(response)
|
80
|
+
true
|
81
|
+
rescue JSON::ParserError
|
82
|
+
false
|
83
|
+
end
|
50
84
|
end
|
51
85
|
end
|
52
86
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'jwt'
|
4
|
+
|
5
|
+
module Pusher
|
6
|
+
module PushNotifications
|
7
|
+
class Token
|
8
|
+
extend Forwardable
|
9
|
+
def initialize(config: PushNotifications)
|
10
|
+
@config = config
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate(user)
|
14
|
+
exp = Time.now.to_i + 24 * 60 * 60 # Current time + 24h
|
15
|
+
iss = "https://#{instance_id}.pushnotifications.pusher.com"
|
16
|
+
payload = { 'sub' => user, 'exp' => exp, 'iss' => iss }
|
17
|
+
JWT.encode payload, secret_key, 'HS256'
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :config
|
23
|
+
def_delegators :@config, :instance_id, :secret_key
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'caze'
|
4
|
+
|
5
|
+
module Pusher
|
6
|
+
module PushNotifications
|
7
|
+
module UseCases
|
8
|
+
class DeleteUser
|
9
|
+
include Caze
|
10
|
+
|
11
|
+
class UserDeletionError < RuntimeError; end
|
12
|
+
|
13
|
+
export :delete_user, as: :delete_user
|
14
|
+
|
15
|
+
def initialize(user:)
|
16
|
+
@user = user
|
17
|
+
@user_id = Pusher::PushNotifications::UserId.new
|
18
|
+
|
19
|
+
raise UserDeletionError, 'User Id cannot be empty.' if user.empty?
|
20
|
+
if user.length > UserId::MAX_USER_ID_LENGTH
|
21
|
+
raise UserDeletionError, 'User id length too long ' \
|
22
|
+
"(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1} characters)"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Contacts the Beams service
|
27
|
+
# to remove all the devices of the given user.
|
28
|
+
def delete_user
|
29
|
+
client.delete(user)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :user
|
35
|
+
|
36
|
+
def client
|
37
|
+
@client ||= PushNotifications::Client.new
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'caze'
|
4
|
+
|
5
|
+
module Pusher
|
6
|
+
module PushNotifications
|
7
|
+
module UseCases
|
8
|
+
class GenerateToken
|
9
|
+
include Caze
|
10
|
+
|
11
|
+
class GenerateTokenError < RuntimeError; end
|
12
|
+
|
13
|
+
export :generate_token, as: :generate_token
|
14
|
+
|
15
|
+
def initialize(user:)
|
16
|
+
@user = user
|
17
|
+
@user_id = Pusher::PushNotifications::UserId.new
|
18
|
+
|
19
|
+
raise GenerateTokenError, 'User Id cannot be empty.' if user.empty?
|
20
|
+
if user.length > UserId::MAX_USER_ID_LENGTH
|
21
|
+
raise GenerateTokenError, 'User id length too long ' \
|
22
|
+
"(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1} characters)"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Creates a signed JWT for a user id.
|
27
|
+
def generate_token
|
28
|
+
{ 'token' => jwt_token.generate(user) }
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
attr_reader :user
|
34
|
+
|
35
|
+
def jwt_token
|
36
|
+
@jwt_token ||= PushNotifications::Token.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -10,25 +10,43 @@ module Pusher
|
|
10
10
|
|
11
11
|
class PublishError < RuntimeError; end
|
12
12
|
|
13
|
-
export :
|
13
|
+
export :publish, as: :publish
|
14
|
+
export :publish_to_interests, as: :publish_to_interests
|
14
15
|
|
15
16
|
def initialize(interests:, payload: {})
|
17
|
+
@interests = interests
|
18
|
+
@payload = payload
|
19
|
+
@user_id = Pusher::PushNotifications::UserId.new
|
20
|
+
|
16
21
|
valid_interest_pattern = /^(_|\-|=|@|,|\.|:|[A-Z]|[a-z]|[0-9])*$/
|
17
22
|
|
18
23
|
interests.each do |interest|
|
19
|
-
if
|
20
|
-
|
21
|
-
|
24
|
+
next if valid_interest_pattern.match?(interest)
|
25
|
+
raise PublishError,
|
26
|
+
"Invalid interest name \nMax #{UserId::MAX_USER_ID_LENGTH}" \
|
27
|
+
' characters and can only contain ASCII upper/lower-case' \
|
28
|
+
' letters, numbers or one of _-=@,.:'
|
22
29
|
end
|
23
30
|
|
24
|
-
|
25
|
-
|
31
|
+
if interests.empty?
|
32
|
+
raise PublishError, 'Must provide at least one interest'
|
33
|
+
end
|
34
|
+
if interests.length > 100
|
35
|
+
raise PublishError, "Number of interests #{interests.length}" \
|
36
|
+
' exceeds maximum of 100'
|
37
|
+
end
|
38
|
+
end
|
26
39
|
|
27
|
-
|
28
|
-
|
40
|
+
# Publish the given payload to the specified interests.
|
41
|
+
# <b>DEPRECATED:</b> Please use <tt>publish_to_interests</tt> instead.
|
42
|
+
def publish
|
43
|
+
warn "[DEPRECATION] `publish` is deprecated. \
|
44
|
+
Please use `publish_to_interests` instead."
|
45
|
+
publish_to_interests
|
29
46
|
end
|
30
47
|
|
31
|
-
|
48
|
+
# Publish the given payload to the specified interests.
|
49
|
+
def publish_to_interests
|
32
50
|
data = { interests: interests }.merge!(payload)
|
33
51
|
client.post('publishes', data)
|
34
52
|
end
|
@@ -38,7 +56,7 @@ module Pusher
|
|
38
56
|
attr_reader :interests, :payload
|
39
57
|
|
40
58
|
def client
|
41
|
-
@
|
59
|
+
@client ||= PushNotifications::Client.new
|
42
60
|
end
|
43
61
|
end
|
44
62
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'caze'
|
4
|
+
|
5
|
+
module Pusher
|
6
|
+
module PushNotifications
|
7
|
+
module UseCases
|
8
|
+
class PublishToUsers
|
9
|
+
include Caze
|
10
|
+
|
11
|
+
class UsersPublishError < RuntimeError; end
|
12
|
+
|
13
|
+
export :publish_to_users, as: :publish_to_users
|
14
|
+
|
15
|
+
def initialize(users:, payload: {})
|
16
|
+
@users = users
|
17
|
+
@user_id = Pusher::PushNotifications::UserId.new
|
18
|
+
@payload = payload
|
19
|
+
|
20
|
+
users.each do |user|
|
21
|
+
raise UsersPublishError, 'User Id cannot be empty.' if user.empty?
|
22
|
+
|
23
|
+
next unless user.length > UserId::MAX_USER_ID_LENGTH
|
24
|
+
raise UsersPublishError, 'User id length too long ' \
|
25
|
+
"(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1}" \
|
26
|
+
' characters)'
|
27
|
+
end
|
28
|
+
|
29
|
+
if users.count < 1
|
30
|
+
raise UsersPublishError, 'Must supply at least one user id.'
|
31
|
+
end
|
32
|
+
if users.length > UserId::MAX_NUM_USER_IDS
|
33
|
+
raise UsersPublishError, "Number of user ids #{users.length} "\
|
34
|
+
"exceeds maximum of #{UserId::MAX_NUM_USER_IDS}."
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Publish the given payload to the specified users.
|
39
|
+
def publish_to_users
|
40
|
+
data = { users: users }.merge!(payload)
|
41
|
+
client.post('publishes/users', data)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
attr_reader :users, :payload
|
47
|
+
|
48
|
+
def client
|
49
|
+
@client ||= PushNotifications::Client.new
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
File without changes
|
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
|
-
lib = File.expand_path('
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
5
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
5
|
require 'pusher/push_notifications/version'
|
7
6
|
|
@@ -22,16 +21,19 @@ Gem::Specification.new do |spec|
|
|
22
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
22
|
spec.require_paths = ['lib']
|
24
23
|
|
25
|
-
spec.add_dependency 'caze'
|
26
|
-
spec.add_dependency '
|
24
|
+
spec.add_dependency 'caze', '~> 0'
|
25
|
+
spec.add_dependency 'jwt', '~> 2.1', '>= 2.1.0'
|
26
|
+
spec.add_dependency 'rest-client', '~> 2.0', '>= 2.0.2'
|
27
27
|
|
28
28
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
29
|
+
spec.add_development_dependency 'codecov', '~> 0'
|
29
30
|
spec.add_development_dependency 'coveralls', '~> 0.8.21'
|
30
31
|
spec.add_development_dependency 'dotenv', '~> 2.2', '>= 2.2.1'
|
31
|
-
spec.add_development_dependency 'pry-byebug'
|
32
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.6', '>= 3.6.0'
|
32
33
|
spec.add_development_dependency 'rake', '~> 10.0'
|
34
|
+
spec.add_development_dependency 'rb-readline', '~> 0'
|
33
35
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
-
spec.add_development_dependency 'rubocop'
|
36
|
+
spec.add_development_dependency 'rubocop', '>= 0.49.0'
|
35
37
|
spec.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
|
36
38
|
spec.add_development_dependency 'webmock', '~> 3.0', '>= 3.0.1'
|
37
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pusher-push-notifications
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Medeiros
|
@@ -9,36 +9,62 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: caze
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: jwt
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.1.0
|
35
|
+
- - "~>"
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.1'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.1.0
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
28
48
|
- !ruby/object:Gem::Dependency
|
29
49
|
name: rest-client
|
30
50
|
requirement: !ruby/object:Gem::Requirement
|
31
51
|
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
32
55
|
- - ">="
|
33
56
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
57
|
+
version: 2.0.2
|
35
58
|
type: :runtime
|
36
59
|
prerelease: false
|
37
60
|
version_requirements: !ruby/object:Gem::Requirement
|
38
61
|
requirements:
|
62
|
+
- - "~>"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '2.0'
|
39
65
|
- - ">="
|
40
66
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
67
|
+
version: 2.0.2
|
42
68
|
- !ruby/object:Gem::Dependency
|
43
69
|
name: bundler
|
44
70
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,6 +79,20 @@ dependencies:
|
|
53
79
|
- - "~>"
|
54
80
|
- !ruby/object:Gem::Version
|
55
81
|
version: '1.16'
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: codecov
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
56
96
|
- !ruby/object:Gem::Dependency
|
57
97
|
name: coveralls
|
58
98
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,14 +133,20 @@ dependencies:
|
|
93
133
|
requirements:
|
94
134
|
- - ">="
|
95
135
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
136
|
+
version: 3.6.0
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '3.6'
|
97
140
|
type: :development
|
98
141
|
prerelease: false
|
99
142
|
version_requirements: !ruby/object:Gem::Requirement
|
100
143
|
requirements:
|
101
144
|
- - ">="
|
102
145
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
146
|
+
version: 3.6.0
|
147
|
+
- - "~>"
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '3.6'
|
104
150
|
- !ruby/object:Gem::Dependency
|
105
151
|
name: rake
|
106
152
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,6 +161,20 @@ dependencies:
|
|
115
161
|
- - "~>"
|
116
162
|
- !ruby/object:Gem::Version
|
117
163
|
version: '10.0'
|
164
|
+
- !ruby/object:Gem::Dependency
|
165
|
+
name: rb-readline
|
166
|
+
requirement: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - "~>"
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
type: :development
|
172
|
+
prerelease: false
|
173
|
+
version_requirements: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - "~>"
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
118
178
|
- !ruby/object:Gem::Dependency
|
119
179
|
name: rspec
|
120
180
|
requirement: !ruby/object:Gem::Requirement
|
@@ -135,14 +195,14 @@ dependencies:
|
|
135
195
|
requirements:
|
136
196
|
- - ">="
|
137
197
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
198
|
+
version: 0.49.0
|
139
199
|
type: :development
|
140
200
|
prerelease: false
|
141
201
|
version_requirements: !ruby/object:Gem::Requirement
|
142
202
|
requirements:
|
143
203
|
- - ">="
|
144
204
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
205
|
+
version: 0.49.0
|
146
206
|
- !ruby/object:Gem::Dependency
|
147
207
|
name: vcr
|
148
208
|
requirement: !ruby/object:Gem::Requirement
|
@@ -197,6 +257,7 @@ files:
|
|
197
257
|
- ".rspec"
|
198
258
|
- ".rubocop.yml"
|
199
259
|
- ".travis.yml"
|
260
|
+
- CHANGELOG.md
|
200
261
|
- Gemfile
|
201
262
|
- Gemfile.lock
|
202
263
|
- LICENSE.txt
|
@@ -204,11 +265,16 @@ files:
|
|
204
265
|
- Rakefile
|
205
266
|
- bin/console
|
206
267
|
- bin/setup
|
207
|
-
- lib/pusher-push-notifications.rb
|
208
268
|
- lib/pusher/push_notifications.rb
|
209
269
|
- lib/pusher/push_notifications/client.rb
|
270
|
+
- lib/pusher/push_notifications/token.rb
|
271
|
+
- lib/pusher/push_notifications/use_cases/delete_user.rb
|
272
|
+
- lib/pusher/push_notifications/use_cases/generate_token.rb
|
210
273
|
- lib/pusher/push_notifications/use_cases/publish.rb
|
274
|
+
- lib/pusher/push_notifications/use_cases/publish_to_users.rb
|
275
|
+
- lib/pusher/push_notifications/user_id.rb
|
211
276
|
- lib/pusher/push_notifications/version.rb
|
277
|
+
- lib/pusher_push_notifications.rb
|
212
278
|
- pusher-push-notifications.gemspec
|
213
279
|
homepage: https://github.com/pusher/push-notifications-ruby
|
214
280
|
licenses:
|
@@ -229,8 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
229
295
|
- !ruby/object:Gem::Version
|
230
296
|
version: '0'
|
231
297
|
requirements: []
|
232
|
-
|
233
|
-
rubygems_version: 2.6.14
|
298
|
+
rubygems_version: 3.0.8
|
234
299
|
signing_key:
|
235
300
|
specification_version: 4
|
236
301
|
summary: Pusher Push Notifications Ruby server SDK
|