pusher-push-notifications 1.0.0 → 2.0.0

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
- SHA1:
3
- metadata.gz: a5743e409a77439ec93c6f2efbab6c36fd70ba8c
4
- data.tar.gz: be4eb6f2ebbac73b421749c3fa6348a75b444fb3
2
+ SHA256:
3
+ metadata.gz: 30b4e2f22bdd9f95ca9c3b8e436a6593555756f2cd38937fedc3694873dd59e6
4
+ data.tar.gz: 4828505ed28d2d7104c616ad64b4a26bed4630e723681d013bef102a960029e6
5
5
  SHA512:
6
- metadata.gz: fed75d5d1582553fc451ca1a1dd52ba91a5c66f98b0b6fde9dc0d221a8c926d16ff951a3357df247f53bba126265b014bb6acc6fcb0c47e22d89e41801c4f5cd
7
- data.tar.gz: 8baf8200d1ae31939e26dde92142b5b4b388ddf8ebdb17bba487cb5da5e691d392c9e3d978c7f03f45549a520a1d08e02f92618bb0145e5ee0ff7d53eb3b534a
6
+ metadata.gz: 20cc5786f0d326c6b2c87542a7410f68988d9c90b79099305b59946e610777d0c99e09c020922986e5b62a160038556e00dd3c79cc5428762880a63e40877d4f
7
+ data.tar.gz: 6c0b2c93006323f152d0ee61ec6002f548e54bbe6d9a6a70a36c1ae54fadf943974c81243567b56dbde6a6941523206eafbbc3f3aad49fa2721fab50420ae110
data/.github/stale.yml ADDED
@@ -0,0 +1,26 @@
1
+ # Configuration for probot-stale - https://github.com/probot/stale
2
+
3
+ # Number of days of inactivity before an Issue or Pull Request becomes stale
4
+ daysUntilStale: 90
5
+
6
+ # Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
7
+ # Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
8
+ daysUntilClose: 7
9
+
10
+ # Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled)
11
+ onlyLabels: []
12
+
13
+ # Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
14
+ exemptLabels:
15
+ - pinned
16
+ - security
17
+
18
+ # Set to true to ignore issues with an assignee (defaults to false)
19
+ exemptAssignees: true
20
+
21
+ # Comment to post when marking as stale. Set to `false` to disable
22
+ markComment: >
23
+ This issue has been automatically marked as stale because it has not had
24
+ recent activity. It will be closed if no further activity occurs. If you'd
25
+ like this issue to stay open please leave a comment indicating how this issue
26
+ is affecting you. Thank you.
@@ -0,0 +1,35 @@
1
+ name: Github Release
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+
7
+ jobs:
8
+ create-release:
9
+ name: Create Release
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: Checkout code
13
+ uses: actions/checkout@v2
14
+ - name: Setup git
15
+ run: |
16
+ git config user.email "pusher-ci@pusher.com"
17
+ git config user.name "Pusher CI"
18
+ - name: Prepare description
19
+ run: |
20
+ csplit -s CHANGELOG.md "/##/" {1}
21
+ cat xx01 > CHANGELOG.tmp
22
+ - name: Prepare tag
23
+ run: |
24
+ export TAG=$(head -1 CHANGELOG.tmp | cut -d' ' -f2)
25
+ echo "TAG=$TAG" >> $GITHUB_ENV
26
+ - name: Create Release
27
+ uses: actions/create-release@v1
28
+ env:
29
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30
+ with:
31
+ tag_name: ${{ env.TAG }}
32
+ release_name: ${{ env.TAG }}
33
+ body_path: CHANGELOG.tmp
34
+ draft: false
35
+ prerelease: false
@@ -0,0 +1,17 @@
1
+ name: RubyGems release
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - uses: actions/checkout@v1
13
+
14
+ - name: Publish gem
15
+ uses: dawidd6/action-publish-gem@v1
16
+ with:
17
+ api_key: ${{secrets.RUBYGEMS_API_KEY}}
@@ -0,0 +1,71 @@
1
+ name: Release
2
+
3
+ on:
4
+ pull_request:
5
+ types: [ labeled ]
6
+ branches:
7
+ - master
8
+
9
+ jobs:
10
+ prepare-release:
11
+ name: Prepare release
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - name: Set major release
16
+ if: ${{ github.event.label.name == 'release-major' }}
17
+ run: echo "RELEASE=major" >> $GITHUB_ENV
18
+ - name: Set minor release
19
+ if: ${{ github.event.label.name == 'release-minor' }}
20
+ run: echo "RELEASE=minor" >> $GITHUB_ENV
21
+ - name: Set patch release
22
+ if: ${{ github.event.label.name == 'release-patch' }}
23
+ run: echo "RELEASE=patch" >> $GITHUB_ENV
24
+ - name: Check release env
25
+ run: |
26
+ if [[ -z "${{ env.RELEASE }}" ]];
27
+ then
28
+ echo "You need to set a release label on PRs to the main branch"
29
+ exit 1
30
+ else
31
+ exit 0
32
+ fi
33
+ - name: Install semver-tool
34
+ run: |
35
+ export DIR=$(mktemp -d)
36
+ cd $DIR
37
+ curl https://github.com/fsaintjacques/semver-tool/archive/3.2.0.tar.gz -L -o semver.tar.gz
38
+ tar -xvf semver.tar.gz
39
+ sudo cp semver-tool-3.2.0/src/semver /usr/local/bin
40
+ - name: Bump version
41
+ run: |
42
+ export CURRENT=$(gem info pusher-push-notifications --remote --exact | grep -o "pusher-push-notifications ([0-9]*\.[0-9]*\.[0-9]*)" | awk -F '[()]' '{print $2}')
43
+ export NEW_VERSION=$(semver bump ${{ env.RELEASE }} $CURRENT)
44
+ echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV
45
+ - name: Checkout code
46
+ uses: actions/checkout@v2
47
+ - name: Setup git
48
+ run: |
49
+ git config user.email "pusher-ci@pusher.com"
50
+ git config user.name "Pusher CI"
51
+ git fetch
52
+ git checkout ${{ github.event.pull_request.head.ref }}
53
+ - name: Prepare CHANGELOG
54
+ run: |
55
+ echo "${{ github.event.pull_request.body }}" | csplit -s - "/##/"
56
+ echo "# Changelog
57
+
58
+ ## ${{ env.VERSION }}
59
+ " >> CHANGELOG.tmp
60
+ grep "^*" xx01 >> CHANGELOG.tmp
61
+ grep -v "^# " CHANGELOG.md >> CHANGELOG.tmp
62
+ cp CHANGELOG.tmp CHANGELOG.md
63
+ - name: Prepare version.rb
64
+ run: |
65
+ sed -i "s|VERSION = '[^']*'|VERSION = '${{ env.VERSION }}'|" lib/pusher/push_notifications/version.rb
66
+ - name: Commit changes
67
+ run: |
68
+ git add CHANGELOG.md lib/pusher/push_notifications/version.rb
69
+ git commit -m "Bump to version ${{ env.VERSION }}"
70
+ - name: Push
71
+ run: git push
@@ -0,0 +1,31 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ ruby-version: ['2.6', '2.7', '3.0']
16
+
17
+ env:
18
+ PUSHER_INSTANCE_ID: 1b880590-6301-4bb5-b34f-45db1c5f5644
19
+ PUSHER_SECRET_KEY: abc
20
+
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - name: Set up Ruby
24
+ uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby-version }}
27
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
28
+ - name: Run tests
29
+ run: bundle exec rake
30
+ - name: Run rubocop
31
+ run: bundle exec rubocop
data/.rubocop.yml CHANGED
@@ -5,19 +5,23 @@ AllCops:
5
5
  TargetRubyVersion: 2.4.0
6
6
 
7
7
  Metrics/LineLength:
8
- Max: 100
8
+ Enabled:
9
+ Max: 80
10
+
11
+ Style/GuardClause:
12
+ Enabled: false
9
13
 
10
14
  Metrics/MethodLength:
11
- Exclude:
12
- - 'spec/**/*.rb'
15
+ Enabled: false
13
16
 
14
- Exclude:
15
- - 'spec/**/*.rb'
17
+ Metrics/AbcSize:
18
+ Enabled: false
16
19
 
17
20
  Metrics/ModuleLength:
18
21
  Exclude:
19
- - 'spec/**/*.rb'
22
+ - "spec/**/*.rb"
20
23
 
21
24
  Metrics/BlockLength:
22
25
  Exclude:
23
- - 'spec/**/*.rb'
26
+ - "spec/**/*.rb"
27
+ - "pusher-push-notifications.gemspec"
data/CHANGELOG.md CHANGED
@@ -1,12 +1,27 @@
1
1
  # Changelog
2
2
 
3
- All notable changes to this project will be documented in this file.
3
+ ## 2.0.0
4
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).
5
+ * [ADDED] Support for Ruby 3.0.
6
+ * [REMOVED] Support for Ruby 2.5 and below.
7
+ * [CHANGED] Refactor tests to avoid caze dependency.
7
8
 
8
- ## [Unreleased](https://github.com/pusher/push-notifications-ruby/compare/1.0.0...HEAD)
9
+ ## 1.3.0
9
10
 
10
- ## [1.0.0](https://github.com/pusher/push-notifications-ruby/compare/v0.3.0...1.0.0) - 2018-07-31
11
+ * [ADDED] Support for multiple instances of Beams clients to exist for more advanced use cases.
11
12
 
12
- - General availability (GA) release.
13
+ ## 1.2.1
14
+
15
+ * [FIXED] Endpoint also allows the scheme to be configured to enable for local development.
16
+
17
+ ## 1.2.0
18
+
19
+ * [ADDED] Support for "endpoint" overrides to allow for internal integration testing.
20
+
21
+ ## 1.1.0
22
+
23
+ * [ADDED] Support for "Authenticated Users" feature: publishToUsers, generateToken and deleteUser.
24
+
25
+ ## 1.0.0
26
+
27
+ * [ADDED] General availability (GA) release.
data/Gemfile CHANGED
@@ -6,5 +6,3 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
7
  # Specify your gem's dependencies in pusher-push_notifications.gemspec
8
8
  gemspec
9
-
10
- gem 'codecov', :require => false, :group => :test
data/Gemfile.lock CHANGED
@@ -1,132 +1,126 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pusher-push-notifications (1.0.0)
5
- caze
6
- rest-client
4
+ pusher-push-notifications (1.3.0)
5
+ jwt (~> 2.1, >= 2.1.0)
6
+ rest-client (~> 2.0, >= 2.0.2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (5.2.0)
12
- concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 0.7, < 2)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
16
- addressable (2.5.2)
17
- public_suffix (>= 2.0.2, < 4.0)
18
- ast (2.3.0)
19
- byebug (9.1.0)
20
- caze (0.2.2)
21
- activesupport (>= 3)
22
- codecov (0.1.10)
23
- json
24
- simplecov
25
- url
26
- coderay (1.1.2)
27
- concurrent-ruby (1.0.5)
28
- coveralls (0.8.21)
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ast (2.4.2)
14
+ byebug (11.1.3)
15
+ codecov (0.5.1)
16
+ simplecov (>= 0.15, < 0.22)
17
+ coderay (1.1.3)
18
+ coveralls (0.8.23)
29
19
  json (>= 1.8, < 3)
30
- simplecov (~> 0.14.1)
20
+ simplecov (~> 0.16.1)
31
21
  term-ansicolor (~> 1.3)
32
- thor (~> 0.19.4)
22
+ thor (>= 0.19.4, < 2.0)
33
23
  tins (~> 1.6)
34
- crack (0.4.3)
35
- safe_yaml (~> 1.0.0)
36
- diff-lcs (1.3)
37
- docile (1.1.5)
38
- domain_name (0.5.20180417)
24
+ crack (0.4.5)
25
+ rexml
26
+ diff-lcs (1.4.4)
27
+ docile (1.3.5)
28
+ domain_name (0.5.20190701)
39
29
  unf (>= 0.0.5, < 1.0.0)
40
- dotenv (2.2.1)
41
- hashdiff (0.3.7)
30
+ dotenv (2.7.6)
31
+ hashdiff (1.0.1)
32
+ http-accept (1.7.0)
42
33
  http-cookie (1.0.3)
43
34
  domain_name (~> 0.5)
44
- i18n (1.0.1)
45
- concurrent-ruby (~> 1.0)
46
- json (2.1.0)
47
- method_source (0.9.0)
48
- mime-types (3.1)
35
+ json (2.5.1)
36
+ jwt (2.2.2)
37
+ method_source (1.0.0)
38
+ mime-types (3.3.1)
49
39
  mime-types-data (~> 3.2015)
50
- mime-types-data (3.2016.0521)
51
- minitest (5.11.3)
40
+ mime-types-data (3.2021.0225)
52
41
  netrc (0.11.0)
53
- parallel (1.12.1)
54
- parser (2.4.0.2)
55
- ast (~> 2.3)
56
- powerpack (0.1.1)
57
- pry (0.11.3)
58
- coderay (~> 1.1.0)
59
- method_source (~> 0.9.0)
60
- pry-byebug (3.5.1)
61
- byebug (~> 9.1)
62
- pry (~> 0.10)
63
- public_suffix (3.0.1)
42
+ parallel (1.20.1)
43
+ parser (3.0.0.0)
44
+ ast (~> 2.4.1)
45
+ pry (0.13.1)
46
+ coderay (~> 1.1)
47
+ method_source (~> 1.0)
48
+ pry-byebug (3.9.0)
49
+ byebug (~> 11.0)
50
+ pry (~> 0.13.0)
51
+ public_suffix (4.0.6)
64
52
  rainbow (3.0.0)
65
- rake (10.5.0)
66
- rest-client (2.0.2)
53
+ rake (13.0.3)
54
+ rb-readline (0.5.5)
55
+ regexp_parser (2.1.1)
56
+ rest-client (2.1.0)
57
+ http-accept (>= 1.7.0, < 2.0)
67
58
  http-cookie (>= 1.0.2, < 2.0)
68
59
  mime-types (>= 1.16, < 4.0)
69
60
  netrc (~> 0.8)
70
- rspec (3.7.0)
71
- rspec-core (~> 3.7.0)
72
- rspec-expectations (~> 3.7.0)
73
- rspec-mocks (~> 3.7.0)
74
- rspec-core (3.7.0)
75
- rspec-support (~> 3.7.0)
76
- rspec-expectations (3.7.0)
61
+ rexml (3.2.4)
62
+ rspec (3.10.0)
63
+ rspec-core (~> 3.10.0)
64
+ rspec-expectations (~> 3.10.0)
65
+ rspec-mocks (~> 3.10.0)
66
+ rspec-core (3.10.1)
67
+ rspec-support (~> 3.10.0)
68
+ rspec-expectations (3.10.1)
77
69
  diff-lcs (>= 1.2.0, < 2.0)
78
- rspec-support (~> 3.7.0)
79
- rspec-mocks (3.7.0)
70
+ rspec-support (~> 3.10.0)
71
+ rspec-mocks (3.10.2)
80
72
  diff-lcs (>= 1.2.0, < 2.0)
81
- rspec-support (~> 3.7.0)
82
- rspec-support (3.7.0)
83
- rubocop (0.52.0)
73
+ rspec-support (~> 3.10.0)
74
+ rspec-support (3.10.2)
75
+ rubocop (1.11.0)
84
76
  parallel (~> 1.10)
85
- parser (>= 2.4.0.2, < 3.0)
86
- powerpack (~> 0.1)
77
+ parser (>= 3.0.0.0)
87
78
  rainbow (>= 2.2.2, < 4.0)
79
+ regexp_parser (>= 1.8, < 3.0)
80
+ rexml
81
+ rubocop-ast (>= 1.2.0, < 2.0)
88
82
  ruby-progressbar (~> 1.7)
89
- unicode-display_width (~> 1.0, >= 1.0.1)
90
- ruby-progressbar (1.9.0)
91
- safe_yaml (1.0.4)
92
- simplecov (0.14.1)
93
- docile (~> 1.1.0)
83
+ unicode-display_width (>= 1.4.0, < 3.0)
84
+ rubocop-ast (1.4.1)
85
+ parser (>= 2.7.1.5)
86
+ ruby-progressbar (1.11.0)
87
+ simplecov (0.16.1)
88
+ docile (~> 1.1)
94
89
  json (>= 1.8, < 3)
95
90
  simplecov-html (~> 0.10.0)
96
91
  simplecov-html (0.10.2)
97
- term-ansicolor (1.6.0)
92
+ sync (0.5.0)
93
+ term-ansicolor (1.7.1)
98
94
  tins (~> 1.0)
99
- thor (0.19.4)
100
- thread_safe (0.3.6)
101
- tins (1.16.3)
102
- tzinfo (1.2.5)
103
- thread_safe (~> 0.1)
95
+ thor (1.1.0)
96
+ tins (1.28.0)
97
+ sync
104
98
  unf (0.1.4)
105
99
  unf_ext
106
- unf_ext (0.0.7.5)
107
- unicode-display_width (1.3.0)
108
- url (0.3.2)
100
+ unf_ext (0.0.7.7)
101
+ unicode-display_width (2.0.0)
109
102
  vcr (3.0.3)
110
- webmock (3.1.1)
103
+ webmock (3.12.0)
111
104
  addressable (>= 2.3.6)
112
105
  crack (>= 0.3.2)
113
- hashdiff
106
+ hashdiff (>= 0.4.0, < 2.0.0)
114
107
 
115
108
  PLATFORMS
116
109
  ruby
117
110
 
118
111
  DEPENDENCIES
119
- bundler (~> 1.16)
120
- codecov
112
+ bundler (~> 2.2)
113
+ codecov (~> 0)
121
114
  coveralls (~> 0.8.21)
122
115
  dotenv (~> 2.2, >= 2.2.1)
123
- pry-byebug
116
+ pry-byebug (~> 3.6, >= 3.6.0)
124
117
  pusher-push-notifications!
125
- rake (~> 10.0)
118
+ rake (~> 13.0)
119
+ rb-readline (~> 0)
126
120
  rspec (~> 3.0)
127
- rubocop
121
+ rubocop (>= 0.49.0)
128
122
  vcr (~> 3.0, >= 3.0.3)
129
123
  webmock (~> 3.0, >= 3.0.1)
130
124
 
131
125
  BUNDLED WITH
132
- 1.16.2
126
+ 2.2.13
data/README.md CHANGED
@@ -22,19 +22,25 @@ 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 Pusher Beams dashboard
33
+ Where `instance_id` and `secret_key` are the values of the instance you created in the Pusher Beams dashboard.
34
+
35
+ If multiple clients are needed, store the reference that is returned from the `configure` method.
32
36
 
33
37
  ## Usage
34
38
 
35
39
  After the configuration is done you can push notifications like this:
36
40
 
37
41
  ```ruby
42
+ require 'pusher/push_notifications'
43
+
38
44
  data = {
39
45
  apns: {
40
46
  aps: {
@@ -52,7 +58,17 @@ data = {
52
58
  }
53
59
  }
54
60
 
55
- Pusher::PushNotifications.publish(interests: ['hello'], payload: data)
61
+ # Publish the given 'data' to the specified interests.
62
+ Pusher::PushNotifications.publish_to_interests(interests: ['hello'], payload: data)
63
+
64
+ # Publish the given 'data' to the specified users.
65
+ Pusher::PushNotifications.publish_to_users(users: ['jonathan', 'jordan', 'luis', 'luka', 'mina'], payload: data)
66
+
67
+ # Authenticate User
68
+ Pusher::PushNotifications.generate_token(user: 'Elmo')
69
+
70
+ # Delete User
71
+ Pusher::PushNotifications.delete_user(user: 'Elmo')
56
72
  ```
57
73
 
58
74
  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 +77,7 @@ The return of this call is a ruby struct containing the http status code (`statu
61
77
 
62
78
  ## Errors
63
79
 
64
- The errors statuses can be:
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 |
80
+ All available error responses can be be found [here](https://docs.pusher.com/beams/reference/publish-api#error-responses).
72
81
 
73
82
  ## Development
74
83
 
data/bin/console CHANGED
@@ -6,7 +6,7 @@ require 'bundler/setup'
6
6
  require 'dotenv'
7
7
  Dotenv.load
8
8
 
9
- require 'pusher'
9
+ require 'pusher/push_notifications'
10
10
 
11
11
  Pusher::PushNotifications.configure do |config|
12
12
  config.instance_id = ENV['PUSHER_INSTANCE_ID']
@@ -1,36 +1,58 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'caze'
4
-
5
3
  require_relative './push_notifications/client'
6
4
  require_relative './push_notifications/use_cases/publish'
5
+ require_relative './push_notifications/use_cases/publish_to_users'
6
+ require_relative './push_notifications/use_cases/delete_user'
7
+ require_relative './push_notifications/use_cases/generate_token'
7
8
  require_relative './push_notifications/version'
9
+ require_relative './push_notifications/user_id'
10
+ require_relative './push_notifications/token'
8
11
 
9
12
  module Pusher
10
13
  module PushNotifications
11
- include Caze
12
-
13
14
  class PushError < RuntimeError; end
14
15
 
15
- has_use_case :publish, UseCases::Publish
16
-
17
16
  class << self
17
+ extend Forwardable
18
+
18
19
  attr_reader :instance_id, :secret_key
19
20
 
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
+
20
26
  def configure
21
27
  yield(self)
22
- self
28
+ # returning a duplicate of `self` to allow multiple clients to be
29
+ # configured without needing to reconfigure the singleton instance
30
+ dup
23
31
  end
24
32
 
25
33
  def instance_id=(instance_id)
26
34
  raise PushError, 'Invalid instance id' if instance_id.nil? || instance_id.delete(' ').empty?
35
+
27
36
  @instance_id = instance_id
28
37
  end
29
38
 
30
39
  def secret_key=(secret_key)
31
40
  raise PushError, 'Invalid secret key' if secret_key.nil? || secret_key.delete(' ').empty?
41
+
32
42
  @secret_key = secret_key
33
43
  end
44
+
45
+ def endpoint=(endpoint)
46
+ raise PushError, 'Invalid endpoint override' if !endpoint.nil? && endpoint.delete(' ').empty?
47
+
48
+ @endpoint = endpoint
49
+ end
50
+
51
+ def endpoint
52
+ return @endpoint unless @endpoint.nil?
53
+
54
+ "https://#{@instance_id}.pushnotifications.pusher.com"
55
+ end
34
56
  end
35
57
  end
36
58
  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 = build_url(resource)
19
+ url = build_publish_url(resource)
22
20
  body = payload.to_json
23
21
 
24
22
  RestClient::Request.execute(
@@ -30,7 +28,25 @@ module Pusher
30
28
  body = JSON.parse(response.body)
31
29
  Response.new(status, body, status == 200)
32
30
  else
33
- Response.new(500, nil, false)
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)
34
50
  end
35
51
  end
36
52
  end
@@ -38,17 +54,25 @@ module Pusher
38
54
  private
39
55
 
40
56
  attr_reader :config
41
- def_delegators :@config, :instance_id, :secret_key
42
57
 
43
- def build_url(resource)
44
- "https://#{instance_id}.#{BASE_URL}/#{instance_id}/#{resource}"
58
+ def_delegators :@config, :instance_id, :secret_key, :endpoint
59
+
60
+ def build_publish_url(resource)
61
+ "#{endpoint}/publish_api/v1/instances/#{instance_id}/#{resource}"
62
+ end
63
+
64
+ def build_users_url(user)
65
+ "#{endpoint}/customer_api/v1/instances/#{instance_id}/users/#{user}"
45
66
  end
46
67
 
47
68
  def headers
48
69
  {
49
70
  content_type: 'application/json',
50
71
  accept: :json,
51
- Authorization: "Bearer #{secret_key}"
72
+ Authorization: "Bearer #{secret_key}",
73
+ 'X-Pusher-Library':
74
+ 'pusher-push-notifications-ruby ' \
75
+ "#{Pusher::PushNotifications::VERSION}"
52
76
  }
53
77
  end
54
78
 
@@ -0,0 +1,27 @@
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
+
24
+ def_delegators :@config, :instance_id, :secret_key
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pusher
4
+ module PushNotifications
5
+ module UseCases
6
+ class DeleteUser
7
+ class UserDeletionError < RuntimeError; end
8
+
9
+ class << self
10
+ def delete_user(*args, **kwargs)
11
+ new(*args, **kwargs).delete_user
12
+ end
13
+ end
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
+
21
+ if user.length > UserId::MAX_USER_ID_LENGTH
22
+ raise UserDeletionError, 'User id length too long ' \
23
+ "(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1} characters)"
24
+ end
25
+ end
26
+
27
+ # Contacts the Beams service
28
+ # to remove all the devices of the given user.
29
+ def delete_user
30
+ client.delete(user)
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :user
36
+
37
+ def client
38
+ @client ||= PushNotifications::Client.new
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pusher
4
+ module PushNotifications
5
+ module UseCases
6
+ class GenerateToken
7
+ class GenerateTokenError < RuntimeError; end
8
+
9
+ class << self
10
+ def generate_token(*args, **kwargs)
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
+
19
+ raise GenerateTokenError, 'User Id cannot be empty.' if user.empty?
20
+
21
+ if user.length > UserId::MAX_USER_ID_LENGTH
22
+ raise GenerateTokenError, 'User id length too long ' \
23
+ "(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1} characters)"
24
+ end
25
+ end
26
+
27
+ # Creates a signed JWT for a user id.
28
+ def generate_token
29
+ { 'token' => jwt_token.generate(user) }
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :user
35
+
36
+ def jwt_token
37
+ @jwt_token ||= PushNotifications::Token.new
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,34 +1,55 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'caze'
4
-
5
3
  module Pusher
6
4
  module PushNotifications
7
5
  module UseCases
8
6
  class Publish
9
- include Caze
10
-
11
7
  class PublishError < RuntimeError; end
12
8
 
13
- export :call, as: :publish
9
+ class << self
10
+ def publish(*args, **kwargs)
11
+ new(*args, **kwargs).publish
12
+ end
13
+
14
+ def publish_to_interests(*args, **kwargs)
15
+ new(*args, **kwargs).publish_to_interests
16
+ end
17
+ end
14
18
 
15
19
  def initialize(interests:, payload: {})
16
- valid_interest_pattern = /^(_|\-|=|@|,|\.|:|[A-Z]|[a-z]|[0-9])*$/
20
+ @interests = interests
21
+ @payload = payload
22
+ @user_id = Pusher::PushNotifications::UserId.new
23
+
24
+ valid_interest_pattern = /^(_|-|=|@|,|\.|:|[A-Z]|[a-z]|[0-9])*$/
17
25
 
18
26
  interests.each do |interest|
19
- if (is_invalid_interest_name = !valid_interest_pattern.match(interest))
20
- raise PublishError, "Invalid interest name \nMax 164 characters and can only contain ASCII upper/lower-case letters, numbers or one of _-=@,.:"
21
- end
27
+ next if valid_interest_pattern.match?(interest)
28
+
29
+ raise PublishError,
30
+ "Invalid interest name \nMax #{UserId::MAX_USER_ID_LENGTH}" \
31
+ ' characters and can only contain ASCII upper/lower-case' \
32
+ ' letters, numbers or one of _-=@,.:'
22
33
  end
23
34
 
24
- raise PublishError, 'Must provide at least one interest' if interests.length == 0
25
- raise PublishError, "Number of interests #{interests.length} exceeds maximum of 100" if interests.length > 100
35
+ raise PublishError, 'Must provide at least one interest' if interests.empty?
26
36
 
27
- @interests = interests
28
- @payload = payload
37
+ if interests.length > 100
38
+ raise PublishError, "Number of interests #{interests.length}" \
39
+ ' exceeds maximum of 100'
40
+ end
41
+ end
42
+
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
29
49
  end
30
50
 
31
- def call
51
+ # Publish the given payload to the specified interests.
52
+ def publish_to_interests
32
53
  data = { interests: interests }.merge!(payload)
33
54
  client.post('publishes', data)
34
55
  end
@@ -38,7 +59,7 @@ module Pusher
38
59
  attr_reader :interests, :payload
39
60
 
40
61
  def client
41
- @_client ||= PushNotifications::Client.new
62
+ @client ||= PushNotifications::Client.new
42
63
  end
43
64
  end
44
65
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pusher
4
+ module PushNotifications
5
+ module UseCases
6
+ class PublishToUsers
7
+ class UsersPublishError < RuntimeError; end
8
+
9
+ class << self
10
+ def publish_to_users(*args, **kwargs)
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
+
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
+
25
+ raise UsersPublishError, 'User id length too long ' \
26
+ "(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1}" \
27
+ ' characters)'
28
+ end
29
+
30
+ raise UsersPublishError, 'Must supply at least one user id.' if users.count < 1
31
+
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
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pusher
4
+ module PushNotifications
5
+ class UserId
6
+ MAX_USER_ID_LENGTH = 164
7
+ MAX_NUM_USER_IDS = 1000
8
+ end
9
+ end
10
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Pusher
4
4
  module PushNotifications
5
- VERSION = '1.0.0'
5
+ VERSION = '2.0.0'
6
6
  end
7
7
  end
@@ -0,0 +1,7 @@
1
+ ## Description
2
+
3
+ Add a short description of the change. If this is related to an issue, please add a reference to the issue.
4
+
5
+ ## CHANGELOG
6
+
7
+ * [CHANGED] Describe your change here. Look at CHANGELOG.md to see the format.
@@ -1,11 +1,11 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
- lib = File.expand_path('../lib', __FILE__)
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
 
8
7
  Gem::Specification.new do |spec|
8
+ spec.required_ruby_version = '>= 2.4.2'
9
9
  spec.name = 'pusher-push-notifications'
10
10
  spec.version = Pusher::PushNotifications::VERSION
11
11
  spec.authors = ['Lucas Medeiros', 'Pusher']
@@ -22,16 +22,18 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'caze'
26
- spec.add_dependency 'rest-client'
25
+ spec.add_dependency 'jwt', '~> 2.1', '>= 2.1.0'
26
+ spec.add_dependency 'rest-client', '~> 2.0', '>= 2.0.2'
27
27
 
28
- spec.add_development_dependency 'bundler', '~> 1.16'
28
+ spec.add_development_dependency 'bundler', '~> 2.2'
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 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'pry-byebug', '~> 3.6', '>= 3.6.0'
33
+ spec.add_development_dependency 'rake', '~> 13.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,58 +1,84 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher-push-notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
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: 2018-07-31 00:00:00.000000000 Z
12
+ date: 2021-03-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: caze
15
+ name: jwt
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '2.1'
18
21
  - - ">="
19
22
  - !ruby/object:Gem::Version
20
- version: '0'
23
+ version: 2.1.0
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '2.1'
25
31
  - - ">="
26
32
  - !ruby/object:Gem::Version
27
- version: '0'
33
+ version: 2.1.0
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: rest-client
30
36
  requirement: !ruby/object:Gem::Requirement
31
37
  requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
32
41
  - - ">="
33
42
  - !ruby/object:Gem::Version
34
- version: '0'
43
+ version: 2.0.2
35
44
  type: :runtime
36
45
  prerelease: false
37
46
  version_requirements: !ruby/object:Gem::Requirement
38
47
  requirements:
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: '2.0'
39
51
  - - ">="
40
52
  - !ruby/object:Gem::Version
41
- version: '0'
53
+ version: 2.0.2
42
54
  - !ruby/object:Gem::Dependency
43
55
  name: bundler
44
56
  requirement: !ruby/object:Gem::Requirement
45
57
  requirements:
46
58
  - - "~>"
47
59
  - !ruby/object:Gem::Version
48
- version: '1.16'
60
+ version: '2.2'
49
61
  type: :development
50
62
  prerelease: false
51
63
  version_requirements: !ruby/object:Gem::Requirement
52
64
  requirements:
53
65
  - - "~>"
54
66
  - !ruby/object:Gem::Version
55
- version: '1.16'
67
+ version: '2.2'
68
+ - !ruby/object:Gem::Dependency
69
+ name: codecov
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
56
82
  - !ruby/object:Gem::Dependency
57
83
  name: coveralls
58
84
  requirement: !ruby/object:Gem::Requirement
@@ -91,30 +117,50 @@ dependencies:
91
117
  name: pry-byebug
92
118
  requirement: !ruby/object:Gem::Requirement
93
119
  requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '3.6'
94
123
  - - ">="
95
124
  - !ruby/object:Gem::Version
96
- version: '0'
125
+ version: 3.6.0
97
126
  type: :development
98
127
  prerelease: false
99
128
  version_requirements: !ruby/object:Gem::Requirement
100
129
  requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '3.6'
101
133
  - - ">="
102
134
  - !ruby/object:Gem::Version
103
- version: '0'
135
+ version: 3.6.0
104
136
  - !ruby/object:Gem::Dependency
105
137
  name: rake
106
138
  requirement: !ruby/object:Gem::Requirement
107
139
  requirements:
108
140
  - - "~>"
109
141
  - !ruby/object:Gem::Version
110
- version: '10.0'
142
+ version: '13.0'
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '13.0'
150
+ - !ruby/object:Gem::Dependency
151
+ name: rb-readline
152
+ requirement: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - "~>"
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
111
157
  type: :development
112
158
  prerelease: false
113
159
  version_requirements: !ruby/object:Gem::Requirement
114
160
  requirements:
115
161
  - - "~>"
116
162
  - !ruby/object:Gem::Version
117
- version: '10.0'
163
+ version: '0'
118
164
  - !ruby/object:Gem::Dependency
119
165
  name: rspec
120
166
  requirement: !ruby/object:Gem::Requirement
@@ -135,14 +181,14 @@ dependencies:
135
181
  requirements:
136
182
  - - ">="
137
183
  - !ruby/object:Gem::Version
138
- version: '0'
184
+ version: 0.49.0
139
185
  type: :development
140
186
  prerelease: false
141
187
  version_requirements: !ruby/object:Gem::Requirement
142
188
  requirements:
143
189
  - - ">="
144
190
  - !ruby/object:Gem::Version
145
- version: '0'
191
+ version: 0.49.0
146
192
  - !ruby/object:Gem::Dependency
147
193
  name: vcr
148
194
  requirement: !ruby/object:Gem::Requirement
@@ -183,7 +229,7 @@ dependencies:
183
229
  - - ">="
184
230
  - !ruby/object:Gem::Version
185
231
  version: 3.0.1
186
- description:
232
+ description:
187
233
  email:
188
234
  - lucastoc@gmail.com
189
235
  - support@pusher.com
@@ -193,10 +239,14 @@ extra_rdoc_files: []
193
239
  files:
194
240
  - ".coveralls.yml"
195
241
  - ".env.sample"
242
+ - ".github/stale.yml"
243
+ - ".github/workflows/gh-release.yml"
244
+ - ".github/workflows/publish.yml"
245
+ - ".github/workflows/release.yml"
246
+ - ".github/workflows/test.yml"
196
247
  - ".gitignore"
197
248
  - ".rspec"
198
249
  - ".rubocop.yml"
199
- - ".travis.yml"
200
250
  - CHANGELOG.md
201
251
  - Gemfile
202
252
  - Gemfile.lock
@@ -205,17 +255,23 @@ files:
205
255
  - Rakefile
206
256
  - bin/console
207
257
  - bin/setup
208
- - lib/pusher-push-notifications.rb
209
258
  - lib/pusher/push_notifications.rb
210
259
  - lib/pusher/push_notifications/client.rb
260
+ - lib/pusher/push_notifications/token.rb
261
+ - lib/pusher/push_notifications/use_cases/delete_user.rb
262
+ - lib/pusher/push_notifications/use_cases/generate_token.rb
211
263
  - lib/pusher/push_notifications/use_cases/publish.rb
264
+ - lib/pusher/push_notifications/use_cases/publish_to_users.rb
265
+ - lib/pusher/push_notifications/user_id.rb
212
266
  - lib/pusher/push_notifications/version.rb
267
+ - lib/pusher_push_notifications.rb
268
+ - pull_request_template.md
213
269
  - pusher-push-notifications.gemspec
214
270
  homepage: https://github.com/pusher/push-notifications-ruby
215
271
  licenses:
216
272
  - MIT
217
273
  metadata: {}
218
- post_install_message:
274
+ post_install_message:
219
275
  rdoc_options: []
220
276
  require_paths:
221
277
  - lib
@@ -223,16 +279,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
223
279
  requirements:
224
280
  - - ">="
225
281
  - !ruby/object:Gem::Version
226
- version: '0'
282
+ version: 2.4.2
227
283
  required_rubygems_version: !ruby/object:Gem::Requirement
228
284
  requirements:
229
285
  - - ">="
230
286
  - !ruby/object:Gem::Version
231
287
  version: '0'
232
288
  requirements: []
233
- rubyforge_project:
234
- rubygems_version: 2.6.14
235
- signing_key:
289
+ rubygems_version: 3.1.2
290
+ signing_key:
236
291
  specification_version: 4
237
292
  summary: Pusher Push Notifications Ruby server SDK
238
293
  test_files: []
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4.2
5
- before_install: gem install bundler -v 1.16.0