pusher 1.4.3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module Pusher
2
- VERSION = '1.4.3'
2
+ VERSION = '2.0.1'
3
3
  end
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: 1.4.3
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pusher
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-28 00:00:00.000000000 Z
11
+ date: 2021-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -171,37 +171,21 @@ executables: []
171
171
  extensions: []
172
172
  extra_rdoc_files: []
173
173
  files:
174
- - ".document"
175
- - ".gemtest"
176
- - ".github/stale.yml"
177
- - ".gitignore"
178
- - ".travis.yml"
179
174
  - CHANGELOG.md
180
- - Gemfile
181
175
  - LICENSE
182
176
  - README.md
183
- - Rakefile
184
- - examples/async_message.rb
185
- - examples/presence_channels/presence_channels.rb
186
- - examples/presence_channels/public/presence_channels.html
187
177
  - lib/pusher.rb
188
178
  - lib/pusher/channel.rb
189
179
  - lib/pusher/client.rb
190
- - lib/pusher/native_notification/client.rb
191
180
  - lib/pusher/request.rb
192
181
  - lib/pusher/resource.rb
193
182
  - lib/pusher/version.rb
194
183
  - lib/pusher/webhook.rb
195
- - pusher.gemspec
196
- - spec/channel_spec.rb
197
- - spec/client_spec.rb
198
- - spec/spec_helper.rb
199
- - spec/web_hook_spec.rb
200
184
  homepage: http://github.com/pusher/pusher-http-ruby
201
185
  licenses:
202
186
  - MIT
203
187
  metadata: {}
204
- post_install_message:
188
+ post_install_message:
205
189
  rdoc_options: []
206
190
  require_paths:
207
191
  - lib
@@ -209,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
193
  requirements:
210
194
  - - ">="
211
195
  - !ruby/object:Gem::Version
212
- version: '0'
196
+ version: '2.6'
213
197
  required_rubygems_version: !ruby/object:Gem::Requirement
214
198
  requirements:
215
199
  - - ">="
@@ -217,11 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
201
  version: '0'
218
202
  requirements: []
219
203
  rubygems_version: 3.1.2
220
- signing_key:
204
+ signing_key:
221
205
  specification_version: 4
222
206
  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
207
+ test_files: []
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gemtest DELETED
File without changes
data/.github/stale.yml DELETED
@@ -1,26 +0,0 @@
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: 365
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. Thankyou.
data/.gitignore DELETED
@@ -1,24 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
- .yardoc
21
- Gemfile.lock
22
-
23
- ## PROJECT::SPECIFIC
24
- .bundle
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- before_install:
2
- - sudo apt-get -y install libsodium18
3
-
4
- language: ruby
5
- sudo: false
6
- rvm:
7
- - 2.4
8
- - 2.5
9
- - 2.6
10
- - jruby
11
- - rbx-2
12
-
13
- matrix:
14
- allow_failures:
15
- - rvm: jruby
16
- - rvm: rbx-2
data/Gemfile DELETED
@@ -1,2 +0,0 @@
1
- source "https://rubygems.org"
2
- gemspec
data/Rakefile DELETED
@@ -1,11 +0,0 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec) do |s|
7
- s.pattern = 'spec/**/*.rb'
8
- end
9
-
10
- task :default => :spec
11
- task :test => :spec
@@ -1,28 +0,0 @@
1
- require 'rubygems'
2
- require 'pusher'
3
- require 'eventmachine'
4
- require 'em-http-request'
5
-
6
- # To get these values:
7
- # - Go to https://app.pusherapp.com/
8
- # - Click on Choose App.
9
- # - Click on one of your apps
10
- # - Click API Access
11
- Pusher.app_id = 'your_app_id'
12
- Pusher.key = 'your_key'
13
- Pusher.secret = 'your_secret'
14
-
15
-
16
- EM.run {
17
- deferrable = Pusher['test_channel'].trigger_async('my_event', 'hi')
18
-
19
- deferrable.callback { # called on success
20
- puts "Message sent successfully."
21
- EM.stop
22
- }
23
- deferrable.errback { |error| # called on error
24
- puts "Message could not be sent."
25
- puts error
26
- EM.stop
27
- }
28
- }
@@ -1,56 +0,0 @@
1
- require 'sinatra'
2
- require 'sinatra/cookies'
3
- require 'sinatra/json'
4
- require 'pusher'
5
-
6
- # You can get these variables from http://dashboard.pusher.com
7
- pusher = Pusher::Client.new(
8
- app_id: 'your-app-id',
9
- key: 'your-app-key',
10
- secret: 'your-app-secret',
11
- cluster: 'your-app-cluster'
12
- )
13
-
14
- set :public_folder, 'public'
15
-
16
- get "/" do
17
- redirect '/presence_channels.html'
18
- end
19
-
20
- # Emulate rails behaviour where this information would be stored in session
21
- get '/signin' do
22
- cookies[:user_id] = 'example_cookie'
23
- 'Ok'
24
- end
25
-
26
- # Auth endpoint: https://pusher.com/docs/channels/server_api/authenticating-users
27
- post '/pusher/auth' do
28
- channel_data = {
29
- user_id: 'example_user',
30
- user_info: {
31
- name: 'example_name',
32
- email: 'example_email'
33
- }
34
- }
35
-
36
- if cookies[:user_id] == 'example_cookie'
37
- response = pusher.authenticate(params[:channel_name], params[:socket_id], channel_data)
38
- json response
39
- else
40
- status 403
41
- end
42
- end
43
-
44
- get '/pusher_trigger' do
45
- channels = ['presence-channel-test'];
46
-
47
- begin
48
- pusher.trigger(channels, 'test-event', {
49
- message: 'hello world'
50
- })
51
- rescue Pusher::Error => e
52
- # (Pusher::AuthenticationError, Pusher::HTTPError, or Pusher::Error)
53
- end
54
-
55
- 'Triggered!'
56
- end
@@ -1,28 +0,0 @@
1
- <!DOCTYPE html>
2
- <head>
3
- <title>Pusher Test</title>
4
- <script src="https://js.pusher.com/5.0/pusher.min.js"></script>
5
- <script>
6
-
7
- // Enable pusher logging - don't include this in production
8
- Pusher.logToConsole = true;
9
-
10
- var pusher = new Pusher('your-app-key', {
11
- cluster: 'your-app-cluster',
12
- forceTLS: true,
13
- authEndpoint: '/pusher/auth'
14
- });
15
-
16
- var channel = pusher.subscribe('presence-channel-test');
17
- channel.bind('test-event', function(data) {
18
- alert(JSON.stringify(data));
19
- });
20
- </script>
21
- </head>
22
- <body>
23
- <h1>Pusher Test</h1>
24
- <p>
25
- Try publishing an event to channel <code>presence-channel-test</code>
26
- with event name <code>test-event</code>.
27
- </p>
28
- </body>
@@ -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
data/pusher.gemspec DELETED
@@ -1,34 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require File.expand_path('../lib/pusher/version', __FILE__)
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "pusher"
7
- s.version = Pusher::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Pusher"]
10
- s.email = ["support@pusher.com"]
11
- s.homepage = "http://github.com/pusher/pusher-http-ruby"
12
- s.summary = %q{Pusher Channels API client}
13
- s.description = %q{Wrapper for Pusher Channels REST api: : https://pusher.com/channels}
14
- s.license = "MIT"
15
-
16
- s.add_dependency "multi_json", "~> 1.15"
17
- s.add_dependency 'pusher-signature', "~> 0.1.8"
18
- s.add_dependency "httpclient", "~> 2.8"
19
- s.add_dependency "jruby-openssl" if defined?(JRUBY_VERSION)
20
-
21
- s.add_development_dependency "rspec", "~> 3.9"
22
- s.add_development_dependency "webmock", "~> 3.9"
23
- s.add_development_dependency "em-http-request", "~> 1.1"
24
- s.add_development_dependency "addressable", "~> 2.7"
25
- s.add_development_dependency "rake", "~> 13.0"
26
- s.add_development_dependency "rack", "~> 2.2"
27
- s.add_development_dependency "json", "~> 2.3"
28
- s.add_development_dependency "rbnacl", "~> 7.1"
29
-
30
- s.files = `git ls-files`.split("\n")
31
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
32
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
33
- s.require_paths = ["lib"]
34
- end
data/spec/channel_spec.rb DELETED
@@ -1,189 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe Pusher::Channel do
5
- before do
6
- @client = Pusher::Client.new({
7
- :app_id => '20',
8
- :key => '12345678900000001',
9
- :secret => '12345678900000001',
10
- :host => 'api.pusherapp.com',
11
- :port => 80,
12
- })
13
- @channel = @client['test_channel']
14
- end
15
-
16
- let(:pusher_url_regexp) { %r{/apps/20/events} }
17
-
18
- def stub_post(status, body = nil)
19
- options = {:status => status}
20
- options.merge!({:body => body}) if body
21
-
22
- stub_request(:post, pusher_url_regexp).to_return(options)
23
- end
24
-
25
- def stub_post_to_raise(e)
26
- stub_request(:post, pusher_url_regexp).to_raise(e)
27
- end
28
-
29
- describe '#trigger!' do
30
- it "should use @client.trigger internally" do
31
- expect(@client).to receive(:trigger)
32
- @channel.trigger('new_event', 'Some data')
33
- end
34
- end
35
-
36
- describe '#trigger' do
37
- it "should log failure if error raised in http call" do
38
- stub_post_to_raise(HTTPClient::BadResponseError)
39
-
40
- expect(Pusher.logger).to receive(:error).with("Exception from WebMock (HTTPClient::BadResponseError) (Pusher::HTTPError)")
41
- expect(Pusher.logger).to receive(:debug) #backtrace
42
- channel = Pusher::Channel.new(@client.url, 'test_channel', @client)
43
- channel.trigger('new_event', 'Some data')
44
- end
45
-
46
- it "should log failure if Pusher returns an error response" do
47
- stub_post 401, "some signature info"
48
- expect(Pusher.logger).to receive(:error).with("some signature info (Pusher::AuthenticationError)")
49
- expect(Pusher.logger).to receive(:debug) #backtrace
50
- channel = Pusher::Channel.new(@client.url, 'test_channel', @client)
51
- channel.trigger('new_event', 'Some data')
52
- end
53
- end
54
-
55
- describe "#initialization" do
56
- it "should not be too long" do
57
- expect { @client['b'*201] }.to raise_error(Pusher::Error)
58
- end
59
-
60
- it "should not use bad characters" do
61
- expect { @client['*^!±`/""'] }.to raise_error(Pusher::Error)
62
- end
63
- end
64
-
65
- describe "#trigger_async" do
66
- it "should use @client.trigger_async internally" do
67
- expect(@client).to receive(:trigger_async)
68
- @channel.trigger_async('new_event', 'Some data')
69
- end
70
- end
71
-
72
- describe '#info' do
73
- it "should call the Client#channel_info" do
74
- expect(@client).to receive(:get)
75
- .with("/channels/mychannel", anything)
76
- .and_return({:occupied => true, :subscription_count => 12})
77
- @channel = @client['mychannel']
78
- @channel.info
79
- end
80
-
81
- it "should assemble the requested attributes into the info option" do
82
- expect(@client).to receive(:get)
83
- .with(anything, {:info => "user_count,connection_count"})
84
- .and_return({:occupied => true, :subscription_count => 12, :user_count => 12})
85
- @channel = @client['presence-foo']
86
- @channel.info(%w{user_count connection_count})
87
- end
88
- end
89
-
90
- describe '#users' do
91
- it "should call the Client#channel_users" do
92
- expect(@client).to receive(:get).with("/channels/presence-mychannel/users", {}).and_return({:users => {'id' => '4'}})
93
- @channel = @client['presence-mychannel']
94
- @channel.users
95
- end
96
- end
97
-
98
- describe "#authentication_string" do
99
- def authentication_string(*data)
100
- lambda { @channel.authentication_string(*data) }
101
- end
102
-
103
- it "should return an authentication string given a socket id" do
104
- auth = @channel.authentication_string('1.1')
105
-
106
- expect(auth).to eq('12345678900000001:02259dff9a2a3f71ea8ab29ac0c0c0ef7996c8f3fd3702be5533f30da7d7fed4')
107
- end
108
-
109
- it "should raise error if authentication is invalid" do
110
- [nil, ''].each do |invalid|
111
- expect(authentication_string(invalid)).to raise_error Pusher::Error
112
- end
113
- end
114
-
115
- describe 'with extra string argument' do
116
- it 'should be a string or nil' do
117
- expect(authentication_string('1.1', 123)).to raise_error Pusher::Error
118
- expect(authentication_string('1.1', {})).to raise_error Pusher::Error
119
-
120
- expect(authentication_string('1.1', 'boom')).not_to raise_error
121
- expect(authentication_string('1.1', nil)).not_to raise_error
122
- end
123
-
124
- it "should return an authentication string given a socket id and custom args" do
125
- auth = @channel.authentication_string('1.1', 'foobar')
126
-
127
- expect(auth).to eq("12345678900000001:#{hmac(@client.secret, "1.1:test_channel:foobar")}")
128
- end
129
- end
130
- end
131
-
132
- describe '#authenticate' do
133
- before :each do
134
- @custom_data = {:uid => 123, :info => {:name => 'Foo'}}
135
- end
136
-
137
- it 'should return a hash with signature including custom data and data as json string' do
138
- allow(MultiJson).to receive(:encode).with(@custom_data).and_return 'a json string'
139
-
140
- response = @channel.authenticate('1.1', @custom_data)
141
-
142
- expect(response).to eq({
143
- :auth => "12345678900000001:#{hmac(@client.secret, "1.1:test_channel:a json string")}",
144
- :channel_data => 'a json string'
145
- })
146
- end
147
-
148
- it 'should fail on invalid socket_ids' do
149
- expect {
150
- @channel.authenticate('1.1:')
151
- }.to raise_error Pusher::Error
152
-
153
- expect {
154
- @channel.authenticate('1.1foo', 'channel')
155
- }.to raise_error Pusher::Error
156
-
157
- expect {
158
- @channel.authenticate(':1.1')
159
- }.to raise_error Pusher::Error
160
-
161
- expect {
162
- @channel.authenticate('foo1.1', 'channel')
163
- }.to raise_error Pusher::Error
164
-
165
- expect {
166
- @channel.authenticate('foo', 'channel')
167
- }.to raise_error Pusher::Error
168
- end
169
- end
170
-
171
- describe `#shared_secret` do
172
- before(:each) do
173
- @channel.instance_variable_set(:@name, 'private-encrypted-1')
174
- end
175
-
176
- it 'should return a shared_secret based on the channel name and encryption master key' do
177
- key = '3W1pfB/Etr+ZIlfMWwZP3gz8jEeCt4s2pe6Vpr+2c3M='
178
- shared_secret = @channel.shared_secret(key)
179
- expect(Base64.strict_encode64(shared_secret)).to eq(
180
- "6zeEp/chneRPS1cbK/hGeG860UhHomxSN6hTgzwT20I="
181
- )
182
- end
183
-
184
- it 'should return nil if missing encryption master key' do
185
- shared_secret = @channel.shared_secret(nil)
186
- expect(shared_secret).to be_nil
187
- end
188
- end
189
- end