pusher 1.4.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/stale.yml +2 -2
- data/.github/workflows/gh-release.yml +35 -0
- data/.github/workflows/publish.yml +17 -0
- data/.github/workflows/release.yml +71 -0
- data/.github/workflows/test.yml +31 -0
- data/CHANGELOG.md +70 -88
- data/README.md +5 -4
- data/examples/presence_channels/presence_channels.rb +6 -6
- data/lib/pusher.rb +0 -3
- data/lib/pusher/client.rb +42 -71
- data/lib/pusher/version.rb +1 -1
- data/pull_request_template.md +7 -0
- data/pusher.gemspec +2 -0
- data/spec/channel_spec.rb +3 -5
- data/spec/client_spec.rb +50 -95
- metadata +12 -15
- data/.document +0 -5
- data/.gemtest +0 -0
- data/.travis.yml +0 -16
- data/lib/pusher/native_notification/client.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c186f5455002119a1783a5d4fe40df5f60db90a5a028fbcfc2d792efd3ef993
|
4
|
+
data.tar.gz: 8efdc4ef40dd9fbe41ce6d9695e2e4a5eddb79d2f462d3ce2a68f6475cb6afe8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9182e53ee76a64c33205fd7dfbcf5ad7b35bcf9934096baa380fa1f6ab89acaeb770ccba76eb8a9a6c4fd8abe8f848cae605a784ed67ed2a52b52bbc65a0495e
|
7
|
+
data.tar.gz: aa4faf02269292f19ea9724de6562a128dfaf37cc3ee34caf7941a9f3e50cb55cdea1a75b05323d3fe8ed93a92ce7e682fc59d1116e5377f3c1c73af6eea015e
|
data/.github/stale.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Configuration for probot-stale - https://github.com/probot/stale
|
2
2
|
|
3
3
|
# Number of days of inactivity before an Issue or Pull Request becomes stale
|
4
|
-
daysUntilStale:
|
4
|
+
daysUntilStale: 90
|
5
5
|
|
6
6
|
# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
|
7
7
|
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
|
@@ -23,4 +23,4 @@ markComment: >
|
|
23
23
|
This issue has been automatically marked as stale because it has not had
|
24
24
|
recent activity. It will be closed if no further activity occurs. If you'd
|
25
25
|
like this issue to stay open please leave a comment indicating how this issue
|
26
|
-
is affecting you.
|
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 --remote --exact | grep -o "pusher ([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/version.rb
|
66
|
+
- name: Commit changes
|
67
|
+
run: |
|
68
|
+
git add CHANGELOG.md lib/pusher/version.rb
|
69
|
+
git commit -m "Bump to version ${{ env.VERSION }}"
|
70
|
+
- name: Push
|
71
|
+
run: git push
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
push:
|
6
|
+
branches: [master, main]
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
runs-on: ubuntu-20.04
|
11
|
+
strategy:
|
12
|
+
fail-fast: false
|
13
|
+
matrix:
|
14
|
+
ruby: ['2.6', '2.7', '3.0']
|
15
|
+
|
16
|
+
name: Ruby ${{ matrix.ruby }} Test
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- name: Checkout
|
20
|
+
uses: actions/checkout@v2
|
21
|
+
|
22
|
+
- name: Setup Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby }}
|
26
|
+
|
27
|
+
- name: Install dependencies
|
28
|
+
run: bundle install
|
29
|
+
|
30
|
+
- name: Run test suite
|
31
|
+
run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,139 +1,121 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 2.0.0
|
4
|
+
|
5
|
+
* [CHANGED] Use TLS by default.
|
6
|
+
* [REMOVED] Support for Ruby 2.4 and 2.5.
|
7
|
+
* [FIXED] Handle empty or nil configuration.
|
8
|
+
* [REMOVED] Legacy Push Notification integration.
|
9
|
+
* [ADDED] Stalebot and Github actions.
|
10
|
+
|
11
|
+
## 1.4.3
|
3
12
|
|
4
|
-
* Remove newline from end of base64 encoded strings, some decoders don't like
|
13
|
+
* [FIXED] Remove newline from end of base64 encoded strings, some decoders don't like
|
5
14
|
them.
|
6
15
|
|
7
|
-
1.4.2
|
16
|
+
## 1.4.2
|
8
17
|
==================
|
9
18
|
|
10
|
-
* Return `shared_secret` to support authenticating encrypted channels. Thanks
|
19
|
+
* [FIXED] Return `shared_secret` to support authenticating encrypted channels. Thanks
|
11
20
|
@Benjaminpjacobs
|
12
21
|
|
13
|
-
1.4.1
|
14
|
-
==================
|
22
|
+
## 1.4.1
|
15
23
|
|
16
|
-
* Remove rbnacl from dependencies so we don't get errors when it isn't
|
24
|
+
* [CHANGED] Remove rbnacl from dependencies so we don't get errors when it isn't
|
17
25
|
required. Thanks @y-yagi!
|
18
26
|
|
19
|
-
1.4.0
|
20
|
-
==================
|
27
|
+
## 1.4.0
|
21
28
|
|
22
|
-
* Support for end-to-end encryption.
|
29
|
+
* [ADDED] Support for end-to-end encryption.
|
23
30
|
|
24
|
-
1.3.3
|
25
|
-
==================
|
31
|
+
## 1.3.3
|
26
32
|
|
27
|
-
* Rewording to clarify "Pusher Channels" or simply "Channels" product name.
|
33
|
+
* [CHANGED] Rewording to clarify "Pusher Channels" or simply "Channels" product name.
|
28
34
|
|
29
|
-
1.3.2
|
30
|
-
==================
|
35
|
+
## 1.3.2
|
31
36
|
|
32
|
-
* Return a specific error for "Request Entity Too Large" (body over 10KB).
|
33
|
-
* Add a `use_tls` option for SSL (defaults to false).
|
34
|
-
* Add a `from_url` client method (in addition to existing `from_env` option).
|
35
|
-
* Improved documentation and fixed typos.
|
36
|
-
* Add Ruby 2.4 to test matrix.
|
37
|
+
* [FIXED] Return a specific error for "Request Entity Too Large" (body over 10KB).
|
38
|
+
* [ADDED] Add a `use_tls` option for SSL (defaults to false).
|
39
|
+
* [ADDED] Add a `from_url` client method (in addition to existing `from_env` option).
|
40
|
+
* [CHANGED] Improved documentation and fixed typos.
|
41
|
+
* [ADDED] Add Ruby 2.4 to test matrix.
|
37
42
|
|
38
|
-
1.3.1
|
39
|
-
==================
|
43
|
+
## 1.3.1
|
40
44
|
|
41
|
-
* Added missing client batch methods to default client delegations
|
42
|
-
* Document raised exception in the `authenticate` method
|
43
|
-
* Fixes em-http-request from using v2.5.0 of `addressable` breaking builds.
|
45
|
+
* [FIXED] Added missing client batch methods to default client delegations
|
46
|
+
* [CHANGED] Document raised exception in the `authenticate` method
|
47
|
+
* [FIXED] Fixes em-http-request from using v2.5.0 of `addressable` breaking builds.
|
44
48
|
|
45
|
-
1.3.0
|
46
|
-
==================
|
49
|
+
## 1.3.0
|
47
50
|
|
48
|
-
* Add support for sending push notifications on up to 10 interests.
|
51
|
+
* [ADDED] Add support for sending push notifications on up to 10 interests.
|
49
52
|
|
50
|
-
1.2.1
|
51
|
-
==================
|
53
|
+
## 1.2.1
|
52
54
|
|
53
|
-
* Fixes Rails 5 compatibility. Use duck-typing to detect request object
|
55
|
+
* [FIXED] Fixes Rails 5 compatibility. Use duck-typing to detect request object
|
54
56
|
|
55
|
-
1.2.0
|
56
|
-
==================
|
57
|
+
## 1.2.0
|
57
58
|
|
58
|
-
* Minor release for Native notifications
|
59
|
+
* [CHANGED] Minor release for Native notifications
|
59
60
|
|
60
|
-
1.2.0.rc1
|
61
|
-
==================
|
61
|
+
## 1.2.0.rc1
|
62
62
|
|
63
|
-
* Add support for Native notifications
|
63
|
+
* [ADDED] Add support for Native notifications
|
64
64
|
|
65
|
-
1.1.0
|
66
|
-
==================
|
65
|
+
## 1.1.0
|
67
66
|
|
68
|
-
* Add support for batch events
|
67
|
+
* [ADDED] Add support for batch events
|
69
68
|
|
70
|
-
1.0.0
|
71
|
-
==================
|
69
|
+
## 1.0.0
|
72
70
|
|
73
|
-
No breaking changes, this release is just to follow semver and show that we
|
71
|
+
* [CHANGED] No breaking changes, this release is just to follow semver and show that we
|
74
72
|
are stable.
|
75
73
|
|
76
|
-
0.18.0
|
77
|
-
==================
|
74
|
+
## 0.18.0
|
78
75
|
|
79
|
-
* Introduce `Pusher::Client.from_env`
|
80
|
-
* Improve error handling on missing config
|
76
|
+
* [ADDED] Introduce `Pusher::Client.from_env`
|
77
|
+
* [FIXED] Improve error handling on missing config
|
81
78
|
|
82
|
-
0.17.0
|
83
|
-
==================
|
79
|
+
## 0.17.0
|
84
80
|
|
85
|
-
* Introduce the `cluster` option.
|
81
|
+
* [ADDED] Introduce the `cluster` option.
|
86
82
|
|
87
|
-
0.16.0
|
88
|
-
==================
|
83
|
+
## 0.16.0
|
89
84
|
|
90
|
-
* Bump httpclient version to 2.7
|
91
|
-
* Ruby 1.8.7 is not supported anymore.
|
85
|
+
* [CHANGED] Bump httpclient version to 2.7
|
86
|
+
* [REMOVED] Ruby 1.8.7 is not supported anymore.
|
92
87
|
|
93
|
-
0.15.2
|
94
|
-
==================
|
88
|
+
## 0.15.2
|
95
89
|
|
96
|
-
* Documented `Pusher.channel_info`, `Pusher.channels`
|
97
|
-
* Added `Pusher.channel_users`
|
90
|
+
* [CHANGED] Documented `Pusher.channel_info`, `Pusher.channels`
|
91
|
+
* [ADDED] Added `Pusher.channel_users`
|
98
92
|
|
99
|
-
0.15.1
|
100
|
-
==================
|
93
|
+
## 0.15.1
|
101
94
|
|
102
|
-
* Fixed a bug where the `authenticate` method added in 0.15.0 wasn't exposed on the Pusher class.
|
95
|
+
* [FIXED] Fixed a bug where the `authenticate` method added in 0.15.0 wasn't exposed on the Pusher class.
|
103
96
|
|
104
|
-
0.15.0
|
105
|
-
==================
|
97
|
+
## 0.15.0
|
106
98
|
|
107
|
-
* Added `Pusher.authenticate` method for authenticating private and presence channels.
|
99
|
+
* [ADDED] Added `Pusher.authenticate` method for authenticating private and presence channels.
|
108
100
|
This is prefered over the older `Pusher['a_channel'].authenticate(...)` style.
|
109
101
|
|
110
|
-
0.14.6
|
111
|
-
==================
|
112
|
-
* Updated to use the `pusher-signature` gem instead of `signature`.
|
113
|
-
This resolves namespace related issues.
|
102
|
+
## 0.14.6
|
114
103
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
* SECURITY: Prevent auth delegation trough crafted socket IDs
|
119
|
-
|
120
|
-
0.14.4 / 2015-01-20
|
121
|
-
==================
|
104
|
+
* [CHANGED] Updated to use the `pusher-signature` gem instead of `signature`.
|
105
|
+
This resolves namespace related issues.
|
122
106
|
|
123
|
-
|
124
|
-
* SECURITY: Prevent POODLE. Disable SSLv3, update httpclient to v2.5
|
125
|
-
* Fix channel name character limit.
|
126
|
-
* Adds support for listing users on a presence channel
|
107
|
+
## 0.14.5
|
127
108
|
|
128
|
-
|
129
|
-
==================
|
109
|
+
* [SECURITY] Prevent auth delegation trough crafted socket IDs
|
130
110
|
|
131
|
-
|
111
|
+
## 0.14.4
|
132
112
|
|
133
|
-
|
134
|
-
|
113
|
+
* [SECURITY] Prevent timing attack, update signature to v0.1.8
|
114
|
+
* [SECURITY] Prevent POODLE. Disable SSLv3, update httpclient to v2.5
|
115
|
+
* [FIXED] Fix channel name character limit.
|
116
|
+
* [ADDED] Adds support for listing users on a presence channel
|
135
117
|
|
136
|
-
|
118
|
+
## 0.14.2
|
137
119
|
|
138
|
-
* Bump httpclient to v2.4. See #62 (POODLE SSL)
|
139
|
-
* Fix limited channel count at README.md. Thanks @tricknotes
|
120
|
+
* [CHANGED] Bump httpclient to v2.4. See #62 (POODLE SSL)
|
121
|
+
* [CHANGED] Fix limited channel count at README.md. Thanks @tricknotes
|
data/README.md
CHANGED
@@ -2,7 +2,11 @@
|
|
2
2
|
|
3
3
|
This Gem provides a Ruby interface to [the Pusher HTTP API for Pusher Channels](https://pusher.com/docs/channels/library_auth_reference/rest-api).
|
4
4
|
|
5
|
-
[![Build Status](https://
|
5
|
+
[![Build Status](https://github.com/pusher/pusher-http-ruby/workflows/Tests/badge.svg)](https://github.com/pusher/pusher-http-ruby/actions?query=workflow%3ATests+branch%3Amaster) [![Gem Version](https://badge.fury.io/rb/pusher.svg)](https://badge.fury.io/rb/pusher)
|
6
|
+
|
7
|
+
## Supported Platforms
|
8
|
+
|
9
|
+
* Ruby - supports **Ruby 2.6 or greater**.
|
6
10
|
|
7
11
|
## Installation and Configuration
|
8
12
|
|
@@ -295,6 +299,3 @@ pusher.trigger(
|
|
295
299
|
```
|
296
300
|
|
297
301
|
Rationale: the methods in this library map directly to individual Channels HTTP API requests. If we allowed triggering a single event on multiple channels (some encrypted, some unencrypted), then it would require two API requests: one where the event is encrypted to the encrypted channels, and one where the event is unencrypted for unencrypted channels.
|
298
|
-
|
299
|
-
## Supported Ruby versions
|
300
|
-
2.4+
|
@@ -6,14 +6,14 @@ require 'pusher'
|
|
6
6
|
# You can get these variables from http://dashboard.pusher.com
|
7
7
|
pusher = Pusher::Client.new(
|
8
8
|
app_id: 'your-app-id',
|
9
|
-
|
9
|
+
key: 'your-app-key',
|
10
10
|
secret: 'your-app-secret',
|
11
|
-
|
11
|
+
cluster: 'your-app-cluster'
|
12
12
|
)
|
13
13
|
|
14
14
|
set :public_folder, 'public'
|
15
15
|
|
16
|
-
get
|
16
|
+
get '/' do
|
17
17
|
redirect '/presence_channels.html'
|
18
18
|
end
|
19
19
|
|
@@ -29,9 +29,9 @@ post '/pusher/auth' do
|
|
29
29
|
user_id: 'example_user',
|
30
30
|
user_info: {
|
31
31
|
name: 'example_name',
|
32
|
-
|
32
|
+
email: 'example_email'
|
33
33
|
}
|
34
|
-
|
34
|
+
}
|
35
35
|
|
36
36
|
if cookies[:user_id] == 'example_cookie'
|
37
37
|
response = pusher.authenticate(params[:channel_name], params[:socket_id], channel_data)
|
@@ -49,7 +49,7 @@ get '/pusher_trigger' do
|
|
49
49
|
message: 'hello world'
|
50
50
|
})
|
51
51
|
rescue Pusher::Error => e
|
52
|
-
#
|
52
|
+
# For example, Pusher::AuthenticationError, Pusher::HTTPError, or Pusher::Error
|
53
53
|
end
|
54
54
|
|
55
55
|
'Triggered!'
|
data/lib/pusher.rb
CHANGED
@@ -28,9 +28,7 @@ module Pusher
|
|
28
28
|
extend Forwardable
|
29
29
|
|
30
30
|
def_delegators :default_client, :scheme, :host, :port, :app_id, :key, :secret, :http_proxy
|
31
|
-
def_delegators :default_client, :notification_host, :notification_scheme
|
32
31
|
def_delegators :default_client, :scheme=, :host=, :port=, :app_id=, :key=, :secret=, :http_proxy=
|
33
|
-
def_delegators :default_client, :notification_host=, :notification_scheme=
|
34
32
|
|
35
33
|
def_delegators :default_client, :authentication_token, :url, :cluster
|
36
34
|
def_delegators :default_client, :encrypted=, :url=, :cluster=
|
@@ -66,4 +64,3 @@ require 'pusher/channel'
|
|
66
64
|
require 'pusher/request'
|
67
65
|
require 'pusher/resource'
|
68
66
|
require 'pusher/webhook'
|
69
|
-
require 'pusher/native_notification/client'
|
data/lib/pusher/client.rb
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
require 'base64'
|
2
|
-
|
3
2
|
require 'pusher-signature'
|
4
3
|
|
5
4
|
module Pusher
|
6
5
|
class Client
|
7
|
-
attr_accessor :scheme, :host, :port, :app_id, :key, :secret, :
|
6
|
+
attr_accessor :scheme, :host, :port, :app_id, :key, :secret, :encryption_master_key
|
8
7
|
attr_reader :http_proxy, :proxy
|
9
8
|
attr_writer :connect_timeout, :send_timeout, :receive_timeout,
|
10
9
|
:keep_alive_timeout
|
11
10
|
|
12
11
|
## CONFIGURATION ##
|
12
|
+
DEFAULT_CONNECT_TIMEOUT = 5
|
13
|
+
DEFAULT_SEND_TIMEOUT = 5
|
14
|
+
DEFAULT_RECEIVE_TIMEOUT = 5
|
15
|
+
DEFAULT_KEEP_ALIVE_TIMEOUT = 30
|
16
|
+
DEFAULT_CLUSTER = "mt1"
|
13
17
|
|
14
18
|
# Loads the configuration from an url in the environment
|
15
19
|
def self.from_env(key = 'PUSHER_URL')
|
@@ -25,51 +29,35 @@ module Pusher
|
|
25
29
|
end
|
26
30
|
|
27
31
|
def initialize(options = {})
|
28
|
-
|
29
|
-
|
30
|
-
:port => 80,
|
31
|
-
}
|
32
|
+
@scheme = "https"
|
33
|
+
@port = options[:port] || 443
|
32
34
|
|
33
|
-
if options
|
34
|
-
|
35
|
-
default_options[:port] = 443
|
35
|
+
if options.key?(:encrypted)
|
36
|
+
warn "[DEPRECATION] `encrypted` is deprecated and will be removed in the next major version. Use `use_tls` instead."
|
36
37
|
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
merged_options[:host] = options[:host]
|
42
|
-
elsif options.has_key?(:cluster)
|
43
|
-
merged_options[:host] = "api-#{options[:cluster]}.pusher.com"
|
44
|
-
else
|
45
|
-
merged_options[:host] = "api.pusherapp.com"
|
39
|
+
if options[:use_tls] == false || options[:encrypted] == false
|
40
|
+
@scheme = "http"
|
41
|
+
@port = options[:port] || 80
|
46
42
|
end
|
47
43
|
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
@app_id = options[:app_id]
|
45
|
+
@key = options[:key]
|
46
|
+
@secret = options[:secret]
|
51
47
|
|
52
|
-
|
53
|
-
|
48
|
+
@host = options[:host]
|
49
|
+
@host ||= "api-#{options[:cluster]}.pusher.com" unless options[:cluster].nil? || options[:cluster].empty?
|
50
|
+
@host ||= "api-#{DEFAULT_CLUSTER}.pusher.com"
|
54
51
|
|
55
|
-
@
|
56
|
-
merged_options.values_at(
|
57
|
-
:scheme, :host, :port, :app_id, :key, :secret, :notification_host, :notification_scheme
|
58
|
-
)
|
52
|
+
@encryption_master_key = Base64.strict_decode64(options[:encryption_master_key_base64]) if options[:encryption_master_key_base64]
|
59
53
|
|
60
|
-
|
61
|
-
@encryption_master_key =
|
62
|
-
Base64.strict_decode64(options[:encryption_master_key_base64])
|
63
|
-
end
|
64
|
-
|
65
|
-
@http_proxy = nil
|
66
|
-
self.http_proxy = options[:http_proxy] if options[:http_proxy]
|
54
|
+
@http_proxy = options[:http_proxy]
|
67
55
|
|
68
56
|
# Default timeouts
|
69
|
-
@connect_timeout =
|
70
|
-
@send_timeout =
|
71
|
-
@receive_timeout =
|
72
|
-
@keep_alive_timeout =
|
57
|
+
@connect_timeout = DEFAULT_CONNECT_TIMEOUT
|
58
|
+
@send_timeout = DEFAULT_SEND_TIMEOUT
|
59
|
+
@receive_timeout = DEFAULT_RECEIVE_TIMEOUT
|
60
|
+
@keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT
|
73
61
|
end
|
74
62
|
|
75
63
|
# @private Returns the authentication token for the client
|
@@ -83,10 +71,10 @@ module Pusher
|
|
83
71
|
def url(path = nil)
|
84
72
|
raise ConfigurationError, :app_id unless @app_id
|
85
73
|
URI::Generic.build({
|
86
|
-
:
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
74
|
+
scheme: @scheme,
|
75
|
+
host: @host,
|
76
|
+
port: @port,
|
77
|
+
path: "/apps/#{@app_id}#{path}"
|
90
78
|
})
|
91
79
|
end
|
92
80
|
|
@@ -110,13 +98,12 @@ module Pusher
|
|
110
98
|
@http_proxy = http_proxy
|
111
99
|
uri = URI.parse(http_proxy)
|
112
100
|
@proxy = {
|
113
|
-
:
|
114
|
-
:
|
115
|
-
:
|
116
|
-
:
|
117
|
-
:
|
101
|
+
scheme: uri.scheme,
|
102
|
+
host: uri.host,
|
103
|
+
port: uri.port,
|
104
|
+
user: uri.user,
|
105
|
+
password: uri.password
|
118
106
|
}
|
119
|
-
@http_proxy
|
120
107
|
end
|
121
108
|
|
122
109
|
# Configure whether Pusher API calls should be made over SSL
|
@@ -136,6 +123,8 @@ module Pusher
|
|
136
123
|
end
|
137
124
|
|
138
125
|
def cluster=(cluster)
|
126
|
+
cluster = DEFAULT_CLUSTER if cluster.nil? || cluster.empty?
|
127
|
+
|
139
128
|
@host = "api-#{cluster}.pusher.com"
|
140
129
|
end
|
141
130
|
|
@@ -330,24 +319,6 @@ module Pusher
|
|
330
319
|
post_async('/batch_events', trigger_batch_params(events.flatten))
|
331
320
|
end
|
332
321
|
|
333
|
-
def notification_client
|
334
|
-
@notification_client ||=
|
335
|
-
NativeNotification::Client.new(@app_id, @notification_host, @notification_scheme, self)
|
336
|
-
end
|
337
|
-
|
338
|
-
|
339
|
-
# Send a push notification
|
340
|
-
#
|
341
|
-
# POST /apps/[app_id]/notifications
|
342
|
-
#
|
343
|
-
# @param interests [Array] An array of interests
|
344
|
-
# @param message [String] Message to send
|
345
|
-
# @param options [Hash] Additional platform specific options
|
346
|
-
#
|
347
|
-
# @return [Hash]
|
348
|
-
def notify(interests, data = {})
|
349
|
-
notification_client.notify(interests, data)
|
350
|
-
end
|
351
322
|
|
352
323
|
# Generate the expected response for an authentication endpoint.
|
353
324
|
# See http://pusher.com/docs/authenticating_users for details.
|
@@ -386,9 +357,9 @@ module Pusher
|
|
386
357
|
|
387
358
|
# @private Construct a net/http http client
|
388
359
|
def sync_http_client
|
389
|
-
|
390
|
-
require 'httpclient'
|
360
|
+
require 'httpclient'
|
391
361
|
|
362
|
+
@client ||= begin
|
392
363
|
HTTPClient.new(@http_proxy).tap do |c|
|
393
364
|
c.connect_timeout = @connect_timeout
|
394
365
|
c.send_timeout = @send_timeout
|
@@ -407,14 +378,14 @@ module Pusher
|
|
407
378
|
require 'em-http' unless defined?(EventMachine::HttpRequest)
|
408
379
|
|
409
380
|
connection_opts = {
|
410
|
-
:
|
411
|
-
:
|
381
|
+
connect_timeout: @connect_timeout,
|
382
|
+
inactivity_timeout: @receive_timeout,
|
412
383
|
}
|
413
384
|
|
414
385
|
if defined?(@proxy)
|
415
386
|
proxy_opts = {
|
416
|
-
:
|
417
|
-
:
|
387
|
+
host: @proxy[:host],
|
388
|
+
port: @proxy[:port]
|
418
389
|
}
|
419
390
|
if @proxy[:user]
|
420
391
|
proxy_opts[:authorization] = [@proxy[:user], @proxy[:password]]
|
data/lib/pusher/version.rb
CHANGED
data/pusher.gemspec
CHANGED
@@ -13,6 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.description = %q{Wrapper for Pusher Channels REST api: : https://pusher.com/channels}
|
14
14
|
s.license = "MIT"
|
15
15
|
|
16
|
+
s.required_ruby_version = ">= 2.6"
|
17
|
+
|
16
18
|
s.add_dependency "multi_json", "~> 1.15"
|
17
19
|
s.add_dependency 'pusher-signature', "~> 0.1.8"
|
18
20
|
s.add_dependency "httpclient", "~> 2.8"
|
data/spec/channel_spec.rb
CHANGED
@@ -29,7 +29,7 @@ describe Pusher::Channel do
|
|
29
29
|
describe '#trigger!' do
|
30
30
|
it "should use @client.trigger internally" do
|
31
31
|
expect(@client).to receive(:trigger)
|
32
|
-
@channel.trigger('new_event', 'Some data')
|
32
|
+
@channel.trigger!('new_event', 'Some data')
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -39,16 +39,14 @@ describe Pusher::Channel do
|
|
39
39
|
|
40
40
|
expect(Pusher.logger).to receive(:error).with("Exception from WebMock (HTTPClient::BadResponseError) (Pusher::HTTPError)")
|
41
41
|
expect(Pusher.logger).to receive(:debug) #backtrace
|
42
|
-
channel
|
43
|
-
channel.trigger('new_event', 'Some data')
|
42
|
+
@channel.trigger('new_event', 'Some data')
|
44
43
|
end
|
45
44
|
|
46
45
|
it "should log failure if Pusher returns an error response" do
|
47
46
|
stub_post 401, "some signature info"
|
48
47
|
expect(Pusher.logger).to receive(:error).with("some signature info (Pusher::AuthenticationError)")
|
49
48
|
expect(Pusher.logger).to receive(:debug) #backtrace
|
50
|
-
channel
|
51
|
-
channel.trigger('new_event', 'Some data')
|
49
|
+
@channel.trigger('new_event', 'Some data')
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
data/spec/client_spec.rb
CHANGED
@@ -17,11 +17,11 @@ describe Pusher do
|
|
17
17
|
|
18
18
|
describe 'default configuration' do
|
19
19
|
it 'should be preconfigured for api host' do
|
20
|
-
expect(@client.host).to eq('api.
|
20
|
+
expect(@client.host).to eq('api-mt1.pusher.com')
|
21
21
|
end
|
22
22
|
|
23
|
-
it 'should be preconfigured for port
|
24
|
-
expect(@client.port).to eq(
|
23
|
+
it 'should be preconfigured for port 443' do
|
24
|
+
expect(@client.port).to eq(443)
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'should use standard logger if no other logger if defined' do
|
@@ -79,6 +79,16 @@ describe Pusher do
|
|
79
79
|
expect(@client.host).to eq('api-eu.pusher.com')
|
80
80
|
end
|
81
81
|
|
82
|
+
it 'should handle nil gracefully' do
|
83
|
+
@client.cluster = nil
|
84
|
+
expect(@client.host).to eq('api-mt1.pusher.com')
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should handle empty string' do
|
88
|
+
@client.cluster = ""
|
89
|
+
expect(@client.host).to eq('api-mt1.pusher.com')
|
90
|
+
end
|
91
|
+
|
82
92
|
it 'should be overridden by host if it comes after' do
|
83
93
|
@client.cluster = 'eu'
|
84
94
|
@client.host = 'api.staging.pusher.com'
|
@@ -106,26 +116,26 @@ describe Pusher do
|
|
106
116
|
end
|
107
117
|
|
108
118
|
describe 'configuring TLS' do
|
109
|
-
it 'should set port and scheme if "use_tls"
|
119
|
+
it 'should set port and scheme if "use_tls" disabled' do
|
110
120
|
client = Pusher::Client.new({
|
111
|
-
:use_tls =>
|
121
|
+
:use_tls => false,
|
112
122
|
})
|
113
|
-
expect(client.scheme).to eq('
|
114
|
-
expect(client.port).to eq(
|
123
|
+
expect(client.scheme).to eq('http')
|
124
|
+
expect(client.port).to eq(80)
|
115
125
|
end
|
116
126
|
|
117
|
-
it 'should set port and scheme if "encrypted"
|
127
|
+
it 'should set port and scheme if "encrypted" disabled' do
|
118
128
|
client = Pusher::Client.new({
|
119
|
-
:encrypted =>
|
129
|
+
:encrypted => false,
|
120
130
|
})
|
121
|
-
expect(client.scheme).to eq('
|
122
|
-
expect(client.port).to eq(
|
131
|
+
expect(client.scheme).to eq('http')
|
132
|
+
expect(client.port).to eq(80)
|
123
133
|
end
|
124
134
|
|
125
|
-
it 'should use
|
135
|
+
it 'should use TLS port and scheme if "encrypted" or "use_tls" are not set' do
|
126
136
|
client = Pusher::Client.new
|
127
|
-
expect(client.scheme).to eq('
|
128
|
-
expect(client.port).to eq(
|
137
|
+
expect(client.scheme).to eq('https')
|
138
|
+
expect(client.port).to eq(443)
|
129
139
|
end
|
130
140
|
|
131
141
|
it 'should override port if "use_tls" option set but a different port is specified' do
|
@@ -137,6 +147,15 @@ describe Pusher do
|
|
137
147
|
expect(client.port).to eq(8443)
|
138
148
|
end
|
139
149
|
|
150
|
+
it 'should override port if "use_tls" option set but a different port is specified' do
|
151
|
+
client = Pusher::Client.new({
|
152
|
+
:use_tls => false,
|
153
|
+
:port => 8000
|
154
|
+
})
|
155
|
+
expect(client.scheme).to eq('http')
|
156
|
+
expect(client.port).to eq(8000)
|
157
|
+
end
|
158
|
+
|
140
159
|
end
|
141
160
|
|
142
161
|
describe 'configuring a http proxy' do
|
@@ -518,22 +537,22 @@ describe Pusher do
|
|
518
537
|
[:get, :post].each do |verb|
|
519
538
|
describe "##{verb}" do
|
520
539
|
before :each do
|
521
|
-
@url_regexp = %r{api.
|
540
|
+
@url_regexp = %r{api-mt1.pusher.com}
|
522
541
|
stub_request(verb, @url_regexp).
|
523
542
|
to_return(:status => 200, :body => "{}")
|
524
543
|
end
|
525
544
|
|
526
545
|
let(:call_api) { @client.send(verb, '/path') }
|
527
546
|
|
528
|
-
it "should use
|
547
|
+
it "should use https by default" do
|
529
548
|
call_api
|
530
|
-
expect(WebMock).to have_requested(verb, %r{
|
549
|
+
expect(WebMock).to have_requested(verb, %r{https://api-mt1.pusher.com/apps/20/path})
|
531
550
|
end
|
532
551
|
|
533
552
|
it "should use https if configured" do
|
534
|
-
@client.encrypted =
|
553
|
+
@client.encrypted = false
|
535
554
|
call_api
|
536
|
-
expect(WebMock).to have_requested(verb, %r{
|
555
|
+
expect(WebMock).to have_requested(verb, %r{http://api-mt1.pusher.com})
|
537
556
|
end
|
538
557
|
|
539
558
|
it "should format the respose hash with symbols at first level" do
|
@@ -598,7 +617,7 @@ describe Pusher do
|
|
598
617
|
[[:get, :get_async], [:post, :post_async]].each do |verb, method|
|
599
618
|
describe "##{method}" do
|
600
619
|
before :each do
|
601
|
-
@url_regexp = %r{api.
|
620
|
+
@url_regexp = %r{api-mt1.pusher.com}
|
602
621
|
stub_request(verb, @url_regexp).
|
603
622
|
to_return(:status => 200, :body => "{}")
|
604
623
|
end
|
@@ -612,15 +631,15 @@ describe Pusher do
|
|
612
631
|
}
|
613
632
|
}
|
614
633
|
|
615
|
-
it "should use
|
634
|
+
it "should use https by default" do
|
616
635
|
call_api
|
617
|
-
expect(WebMock).to have_requested(verb, %r{
|
636
|
+
expect(WebMock).to have_requested(verb, %r{https://api-mt1.pusher.com/apps/20/path})
|
618
637
|
end
|
619
638
|
|
620
|
-
it "should use
|
621
|
-
@client.encrypted =
|
639
|
+
it "should use http if configured" do
|
640
|
+
@client.encrypted = false
|
622
641
|
call_api
|
623
|
-
expect(WebMock).to have_requested(verb, %r{
|
642
|
+
expect(WebMock).to have_requested(verb, %r{http://api-mt1.pusher.com})
|
624
643
|
end
|
625
644
|
|
626
645
|
# Note that the raw httpclient connection object is returned and
|
@@ -640,27 +659,27 @@ describe Pusher do
|
|
640
659
|
[[:get, :get_async], [:post, :post_async]].each do |verb, method|
|
641
660
|
describe "##{method}" do
|
642
661
|
before :each do
|
643
|
-
@url_regexp = %r{api.
|
662
|
+
@url_regexp = %r{api-mt1.pusher.com}
|
644
663
|
stub_request(verb, @url_regexp).
|
645
664
|
to_return(:status => 200, :body => "{}")
|
646
665
|
end
|
647
666
|
|
648
667
|
let(:call_api) { @client.send(method, '/path') }
|
649
668
|
|
650
|
-
it "should use
|
669
|
+
it "should use https by default" do
|
651
670
|
EM.run {
|
652
671
|
call_api.callback {
|
653
|
-
expect(WebMock).to have_requested(verb, %r{
|
672
|
+
expect(WebMock).to have_requested(verb, %r{https://api-mt1.pusher.com/apps/20/path})
|
654
673
|
EM.stop
|
655
674
|
}
|
656
675
|
}
|
657
676
|
end
|
658
677
|
|
659
|
-
it "should use
|
678
|
+
it "should use http if configured" do
|
660
679
|
EM.run {
|
661
|
-
@client.encrypted =
|
680
|
+
@client.encrypted = false
|
662
681
|
call_api.callback {
|
663
|
-
expect(WebMock).to have_requested(verb, %r{
|
682
|
+
expect(WebMock).to have_requested(verb, %r{http://api-mt1.pusher.com})
|
664
683
|
EM.stop
|
665
684
|
}
|
666
685
|
}
|
@@ -697,70 +716,6 @@ describe Pusher do
|
|
697
716
|
end
|
698
717
|
end
|
699
718
|
end
|
700
|
-
|
701
|
-
describe "native notifications" do
|
702
|
-
before :each do
|
703
|
-
@client.app_id = "20"
|
704
|
-
@client.key = "testytest"
|
705
|
-
@client.secret = "mysupersecretkey"
|
706
|
-
end
|
707
|
-
|
708
|
-
it "should configure a native notification client using the pusher client object" do
|
709
|
-
expect(@client.notification_client).to_not be(nil)
|
710
|
-
end
|
711
|
-
|
712
|
-
it "should use the default host if not provided" do
|
713
|
-
expect(@client.notification_host).to eq("nativepush-cluster1.pusher.com")
|
714
|
-
end
|
715
|
-
|
716
|
-
it "should use a newly provided host" do
|
717
|
-
@client.notification_host = "test.com"
|
718
|
-
expect(@client.notification_host).to eq("test.com")
|
719
|
-
end
|
720
|
-
|
721
|
-
it "should set the native notification client host to the same one" do
|
722
|
-
expect(@client.notification_host).to eq(@client.notification_client.host)
|
723
|
-
end
|
724
|
-
|
725
|
-
it "should raise an error if no interest is provided" do
|
726
|
-
payload = {
|
727
|
-
gcm: {
|
728
|
-
notification: {
|
729
|
-
title: "Hello",
|
730
|
-
icon: "icon",
|
731
|
-
}
|
732
|
-
}
|
733
|
-
}
|
734
|
-
|
735
|
-
expect { @client.notify([], payload) }.to raise_error(Pusher::Error)
|
736
|
-
end
|
737
|
-
|
738
|
-
it "should send a request to the notifications endpoint" do
|
739
|
-
notification_host_regexp = %r{nativepush-cluster1.pusher.com}
|
740
|
-
payload = {
|
741
|
-
interests: ["test"],
|
742
|
-
gcm: {
|
743
|
-
notification: {
|
744
|
-
title: "Hello",
|
745
|
-
icon: "icon",
|
746
|
-
}
|
747
|
-
}
|
748
|
-
}
|
749
|
-
|
750
|
-
stub_request(
|
751
|
-
:post,
|
752
|
-
notification_host_regexp,
|
753
|
-
).with(
|
754
|
-
body: MultiJson.encode(payload)
|
755
|
-
).to_return({
|
756
|
-
:status => 200,
|
757
|
-
:body => MultiJson.encode({ :foo => "bar" })
|
758
|
-
})
|
759
|
-
|
760
|
-
res = @client.notify(["test"], payload)
|
761
|
-
expect(res).to eq({foo: "bar"})
|
762
|
-
end
|
763
|
-
end
|
764
719
|
end
|
765
720
|
|
766
721
|
describe 'configuring cluster' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pusher
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -171,11 +171,12 @@ executables: []
|
|
171
171
|
extensions: []
|
172
172
|
extra_rdoc_files: []
|
173
173
|
files:
|
174
|
-
- ".document"
|
175
|
-
- ".gemtest"
|
176
174
|
- ".github/stale.yml"
|
175
|
+
- ".github/workflows/gh-release.yml"
|
176
|
+
- ".github/workflows/publish.yml"
|
177
|
+
- ".github/workflows/release.yml"
|
178
|
+
- ".github/workflows/test.yml"
|
177
179
|
- ".gitignore"
|
178
|
-
- ".travis.yml"
|
179
180
|
- CHANGELOG.md
|
180
181
|
- Gemfile
|
181
182
|
- LICENSE
|
@@ -187,11 +188,11 @@ files:
|
|
187
188
|
- lib/pusher.rb
|
188
189
|
- lib/pusher/channel.rb
|
189
190
|
- lib/pusher/client.rb
|
190
|
-
- lib/pusher/native_notification/client.rb
|
191
191
|
- lib/pusher/request.rb
|
192
192
|
- lib/pusher/resource.rb
|
193
193
|
- lib/pusher/version.rb
|
194
194
|
- lib/pusher/webhook.rb
|
195
|
+
- pull_request_template.md
|
195
196
|
- pusher.gemspec
|
196
197
|
- spec/channel_spec.rb
|
197
198
|
- spec/client_spec.rb
|
@@ -201,7 +202,7 @@ homepage: http://github.com/pusher/pusher-http-ruby
|
|
201
202
|
licenses:
|
202
203
|
- MIT
|
203
204
|
metadata: {}
|
204
|
-
post_install_message:
|
205
|
+
post_install_message:
|
205
206
|
rdoc_options: []
|
206
207
|
require_paths:
|
207
208
|
- lib
|
@@ -209,7 +210,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
210
|
requirements:
|
210
211
|
- - ">="
|
211
212
|
- !ruby/object:Gem::Version
|
212
|
-
version: '
|
213
|
+
version: '2.6'
|
213
214
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
215
|
requirements:
|
215
216
|
- - ">="
|
@@ -217,11 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
218
|
version: '0'
|
218
219
|
requirements: []
|
219
220
|
rubygems_version: 3.1.2
|
220
|
-
signing_key:
|
221
|
+
signing_key:
|
221
222
|
specification_version: 4
|
222
223
|
summary: Pusher Channels API client
|
223
|
-
test_files:
|
224
|
-
- spec/channel_spec.rb
|
225
|
-
- spec/client_spec.rb
|
226
|
-
- spec/spec_helper.rb
|
227
|
-
- spec/web_hook_spec.rb
|
224
|
+
test_files: []
|
data/.document
DELETED
data/.gemtest
DELETED
File without changes
|
data/.travis.yml
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
module Pusher
|
2
|
-
module NativeNotification
|
3
|
-
class Client
|
4
|
-
attr_reader :app_id, :host
|
5
|
-
|
6
|
-
API_PREFIX = "server_api"
|
7
|
-
API_VERSION = "v1"
|
8
|
-
|
9
|
-
def initialize(app_id, host, scheme, pusher_client)
|
10
|
-
@app_id = app_id
|
11
|
-
@host = host
|
12
|
-
@scheme = scheme
|
13
|
-
@pusher_client = pusher_client
|
14
|
-
end
|
15
|
-
|
16
|
-
# Send a notification via the native notifications API
|
17
|
-
def notify(interests, data = {})
|
18
|
-
Request.new(
|
19
|
-
@pusher_client,
|
20
|
-
:post,
|
21
|
-
url("/notifications"),
|
22
|
-
{},
|
23
|
-
payload(interests, data)
|
24
|
-
).send_sync
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
# {
|
30
|
-
# interests: [Array of interests],
|
31
|
-
# apns: {
|
32
|
-
# See https://pusher.com/docs/push_notifications/ios/server
|
33
|
-
# },
|
34
|
-
# gcm: {
|
35
|
-
# See https://pusher.com/docs/push_notifications/android/server
|
36
|
-
# }
|
37
|
-
# }
|
38
|
-
#
|
39
|
-
# @raise [Pusher::Error] if the interests array is empty
|
40
|
-
# @return [String]
|
41
|
-
def payload(interests, data)
|
42
|
-
interests = Array(interests).map(&:to_s)
|
43
|
-
|
44
|
-
raise Pusher::Error, "Interests array must not be empty" if interests.length == 0
|
45
|
-
|
46
|
-
data = deep_symbolize_keys!(data)
|
47
|
-
|
48
|
-
data.merge!(interests: interests)
|
49
|
-
|
50
|
-
MultiJson.encode(data)
|
51
|
-
end
|
52
|
-
|
53
|
-
def url(path = nil)
|
54
|
-
URI.parse("#{@scheme}://#{@host}/#{API_PREFIX}/#{API_VERSION}/apps/#{@app_id}#{path}")
|
55
|
-
end
|
56
|
-
|
57
|
-
# Symbolize all keys in the hash recursively
|
58
|
-
def deep_symbolize_keys!(hash)
|
59
|
-
hash.keys.each do |k|
|
60
|
-
ks = k.respond_to?(:to_sym) ? k.to_sym : k
|
61
|
-
hash[ks] = hash.delete(k)
|
62
|
-
deep_symbolize_keys!(hash[ks]) if hash[ks].kind_of?(Hash)
|
63
|
-
end
|
64
|
-
|
65
|
-
hash
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|