pusher-push-notifications 1.0.0 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
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: 7b6ed8156fc1fb15e299754cc324357877136643d3fb11b9ee2df005eac629a0
4
+ data.tar.gz: 2beec8b29a6f2a8760490e4e8bb50e33cb0a6216147a964ee55f45522c5a3c71
5
5
  SHA512:
6
- metadata.gz: fed75d5d1582553fc451ca1a1dd52ba91a5c66f98b0b6fde9dc0d221a8c926d16ff951a3357df247f53bba126265b014bb6acc6fcb0c47e22d89e41801c4f5cd
7
- data.tar.gz: 8baf8200d1ae31939e26dde92142b5b4b388ddf8ebdb17bba487cb5da5e691d392c9e3d978c7f03f45549a520a1d08e02f92618bb0145e5ee0ff7d53eb3b534a
6
+ metadata.gz: 995111be0507cf0010fc3dbd1dd0a7661ad23ba64409e74cd72f222ed8e938b28df8d751fb28c2fe19bfff13cde35ece544937bf0b314ead0abf651c16b4459f
7
+ data.tar.gz: b293b85bbd4c64bf6300dc7b2191afc33076736ae722fd56482c89d4b934190ad0da3c2b5da522c6a961c24c9d5473fd4d33a9c3bcf02887abd79cfe34c3bbb1
data/.coveralls.yml CHANGED
@@ -1 +1 @@
1
- repo_token: uaAoIkOEP9l7PCLENpJSSVVrcm94JDNYO
1
+ repo_token: secret
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,74 @@
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: Prepare Gemfile.lock
67
+ run: |
68
+ sed -i "s|pusher-push-notifications ([^)]*)|pusher-push-notifications (${{ env.VERSION }})|" Gemfile.lock
69
+ - name: Commit changes
70
+ run: |
71
+ git add CHANGELOG.md lib/pusher/push_notifications/version.rb Gemfile.lock
72
+ git commit -m "Bump to version ${{ env.VERSION }}"
73
+ - name: Push
74
+ 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,31 @@
1
1
  # Changelog
2
2
 
3
- All notable changes to this project will be documented in this file.
3
+ ## 2.0.1
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
+ * [CHANGED] Update Gemfile lock on release.
7
6
 
8
- ## [Unreleased](https://github.com/pusher/push-notifications-ruby/compare/1.0.0...HEAD)
7
+ ## 2.0.0
9
8
 
10
- ## [1.0.0](https://github.com/pusher/push-notifications-ruby/compare/v0.3.0...1.0.0) - 2018-07-31
9
+ * [ADDED] Support for Ruby 3.0.
10
+ * [REMOVED] Support for Ruby 2.5 and below.
11
+ * [CHANGED] Refactor tests to avoid caze dependency.
11
12
 
12
- - General availability (GA) release.
13
+ ## 1.3.0
14
+
15
+ * [ADDED] Support for multiple instances of Beams clients to exist for more advanced use cases.
16
+
17
+ ## 1.2.1
18
+
19
+ * [FIXED] Endpoint also allows the scheme to be configured to enable for local development.
20
+
21
+ ## 1.2.0
22
+
23
+ * [ADDED] Support for "endpoint" overrides to allow for internal integration testing.
24
+
25
+ ## 1.1.0
26
+
27
+ * [ADDED] Support for "Authenticated Users" feature: publishToUsers, generateToken and deleteUser.
28
+
29
+ ## 1.0.0
30
+
31
+ * [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 (2.0.2)
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
@@ -1,7 +1,6 @@
1
1
  # Pusher Beams Ruby Server SDK
2
2
 
3
- [![Build Status](https://travis-ci.org/pusher/push-notifications-ruby.svg?branch=master)](https://travis-ci.org/pusher/push-notifications-ruby)
4
- [![Coverage Status](https://coveralls.io/repos/github/pusher/push-notifications-ruby/badge.svg?branch=update-sdk)](https://coveralls.io/github/pusher/push-notifications-ruby?branch=update-sdk)
3
+ [![Test](https://github.com/pusher/push-notifications-ruby/actions/workflows/test.yml/badge.svg)](https://github.com/pusher/push-notifications-ruby/actions/workflows/test.yml) [![Coverage Status](https://coveralls.io/repos/github/pusher/push-notifications-ruby/badge.svg)](https://coveralls.io/github/pusher/push-notifications-ruby) [![Gem](https://img.shields.io/gem/v/pusher-push-notifications)](https://rubygems.org/gems/pusher-push-notifications)
5
4
 
6
5
  Pusher Beams using the Pusher system.
7
6
 
@@ -22,19 +21,25 @@ gem 'pusher-push-notifications'
22
21
  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
22
 
24
23
  ```ruby
24
+ require 'pusher/push_notifications'
25
+
25
26
  Pusher::PushNotifications.configure do |config|
26
27
   config.instance_id = ENV['PUSHER_INSTANCE_ID'] # or the value directly
27
28
   config.secret_key = ENV['PUSHER_SECRET_KEY']
28
29
  end
29
30
  ```
30
31
 
31
- Where `instance_id` and `secret_key` are the values of the instance you created in the Pusher Beams dashboard
32
+ Where `instance_id` and `secret_key` are the values of the instance you created in the Pusher Beams dashboard.
33
+
34
+ If multiple clients are needed, store the reference that is returned from the `configure` method.
32
35
 
33
36
  ## Usage
34
37
 
35
38
  After the configuration is done you can push notifications like this:
36
39
 
37
40
  ```ruby
41
+ require 'pusher/push_notifications'
42
+
38
43
  data = {
39
44
  apns: {
40
45
  aps: {
@@ -52,7 +57,17 @@ data = {
52
57
  }
53
58
  }
54
59
 
55
- Pusher::PushNotifications.publish(interests: ['hello'], payload: data)
60
+ # Publish the given 'data' to the specified interests.
61
+ Pusher::PushNotifications.publish_to_interests(interests: ['hello'], payload: data)
62
+
63
+ # Publish the given 'data' to the specified users.
64
+ Pusher::PushNotifications.publish_to_users(users: ['jonathan', 'jordan', 'luis', 'luka', 'mina'], payload: data)
65
+
66
+ # Authenticate User
67
+ Pusher::PushNotifications.generate_token(user: 'Elmo')
68
+
69
+ # Delete User
70
+ Pusher::PushNotifications.delete_user(user: 'Elmo')
56
71
  ```
57
72
 
58
73
  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 +76,7 @@ The return of this call is a ruby struct containing the http status code (`statu
61
76
 
62
77
  ## Errors
63
78
 
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 |
79
+ All available error responses can be be found [here](https://docs.pusher.com/beams/reference/publish-api#error-responses).
72
80
 
73
81
  ## Development
74
82
 
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']
@@ -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,24 @@
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
+ # Contacts the Beams service
10
+ # to remove all the devices of the given user.
11
+ def self.delete_user(client, user:)
12
+ raise UserDeletionError, 'User Id cannot be empty.' if user.empty?
13
+
14
+ if user.length > UserId::MAX_USER_ID_LENGTH
15
+ raise UserDeletionError, 'User id length too long ' \
16
+ "(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1} characters)"
17
+ end
18
+
19
+ client.delete(user)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
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
+ # Creates a signed JWT for a user id.
10
+ def self.generate_token(user:)
11
+ raise GenerateTokenError, 'User Id cannot be empty.' if user.empty?
12
+
13
+ if user.length > UserId::MAX_USER_ID_LENGTH
14
+ raise GenerateTokenError, 'User id length too long ' \
15
+ "(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1} characters)"
16
+ end
17
+
18
+ jwt_token = PushNotifications::Token.new
19
+
20
+ { 'token' => jwt_token.generate(user) }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,45 +1,42 @@
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
+ # 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)
15
+ end
14
16
 
15
- def initialize(interests:, payload: {})
16
- valid_interest_pattern = /^(_|\-|=|@|,|\.|:|[A-Z]|[a-z]|[0-9])*$/
17
+ # Publish the given payload to the specified interests.
18
+ def self.publish_to_interests(client, interests:, payload: {})
19
+ valid_interest_pattern = /^(_|-|=|@|,|\.|:|[A-Z]|[a-z]|[0-9])*$/
17
20
 
18
21
  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
22
+ next if valid_interest_pattern.match?(interest)
23
+
24
+ raise PublishError,
25
+ "Invalid interest name \nMax #{UserId::MAX_USER_ID_LENGTH}" \
26
+ ' characters and can only contain ASCII upper/lower-case' \
27
+ ' letters, numbers or one of _-=@,.:'
22
28
  end
23
29
 
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
30
+ raise PublishError, 'Must provide at least one interest' if interests.empty?
26
31
 
27
- @interests = interests
28
- @payload = payload
29
- end
32
+ if interests.length > 100
33
+ raise PublishError, "Number of interests #{interests.length}" \
34
+ ' exceeds maximum of 100'
35
+ end
30
36
 
31
- def call
32
37
  data = { interests: interests }.merge!(payload)
33
38
  client.post('publishes', data)
34
39
  end
35
-
36
- private
37
-
38
- attr_reader :interests, :payload
39
-
40
- def client
41
- @_client ||= PushNotifications::Client.new
42
- end
43
40
  end
44
41
  end
45
42
  end
@@ -0,0 +1,34 @@
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
+ # Publish the given payload to the specified users.
10
+ def self.publish_to_users(client, users:, payload: {})
11
+ users.each do |user|
12
+ raise UsersPublishError, 'User Id cannot be empty.' if user.empty?
13
+
14
+ next unless user.length > UserId::MAX_USER_ID_LENGTH
15
+
16
+ raise UsersPublishError, 'User id length too long ' \
17
+ "(expected fewer than #{UserId::MAX_USER_ID_LENGTH + 1}" \
18
+ ' characters)'
19
+ end
20
+
21
+ raise UsersPublishError, 'Must supply at least one user id.' if users.count < 1
22
+
23
+ if users.length > UserId::MAX_NUM_USER_IDS
24
+ raise UsersPublishError, "Number of user ids #{users.length} "\
25
+ "exceeds maximum of #{UserId::MAX_NUM_USER_IDS}."
26
+ end
27
+
28
+ data = { users: users }.merge!(payload)
29
+ client.post('publishes/users', data)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ 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.2'
6
6
  end
7
7
  end
@@ -1,36 +1,77 @@
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
18
17
  attr_reader :instance_id, :secret_key
19
18
 
20
19
  def configure
21
20
  yield(self)
22
- self
21
+ # returning a duplicate of `self` to allow multiple clients to be
22
+ # configured without needing to reconfigure the singleton instance
23
+ dup
23
24
  end
24
25
 
25
26
  def instance_id=(instance_id)
26
27
  raise PushError, 'Invalid instance id' if instance_id.nil? || instance_id.delete(' ').empty?
28
+
27
29
  @instance_id = instance_id
28
30
  end
29
31
 
30
32
  def secret_key=(secret_key)
31
33
  raise PushError, 'Invalid secret key' if secret_key.nil? || secret_key.delete(' ').empty?
34
+
32
35
  @secret_key = secret_key
33
36
  end
37
+
38
+ def endpoint=(endpoint)
39
+ raise PushError, 'Invalid endpoint override' if !endpoint.nil? && endpoint.delete(' ').empty?
40
+
41
+ @endpoint = endpoint
42
+ end
43
+
44
+ def endpoint
45
+ return @endpoint unless @endpoint.nil?
46
+
47
+ "https://#{@instance_id}.pushnotifications.pusher.com"
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
34
75
  end
35
76
  end
36
77
  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,7 +1,7 @@
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Medeiros
@@ -9,50 +9,76 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-07-31 00:00:00.000000000 Z
12
+ date: 2022-03-11 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
@@ -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,11 +255,17 @@ 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:
@@ -223,15 +279,14 @@ 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
289
+ rubygems_version: 3.1.2
235
290
  signing_key:
236
291
  specification_version: 4
237
292
  summary: Pusher Push Notifications Ruby server SDK
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