Skip to content

Commit 5d17496

Browse files
committed
Introduce a notification_scheme option to specify the scheme for push
notifications
1 parent 609491d commit 5d17496

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

lib/pusher.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ class HTTPError < Error; attr_accessor :original_error; end
2727
class << self
2828
extend Forwardable
2929

30-
def_delegators :default_client, :scheme, :host, :port, :app_id, :key, :secret, :http_proxy, :notification_host
31-
def_delegators :default_client, :scheme=, :host=, :port=, :app_id=, :key=, :secret=, :http_proxy=, :notification_host=
30+
def_delegators :default_client, :scheme, :host, :port, :app_id, :key, :secret, :http_proxy
31+
def_delegators :default_client, :notification_host, :notification_scheme
32+
def_delegators :default_client, :scheme=, :host=, :port=, :app_id=, :key=, :secret=, :http_proxy=
33+
def_delegators :default_client, :notification_host=, :notification_scheme=
3234

3335
def_delegators :default_client, :authentication_token, :url
3436
def_delegators :default_client, :encrypted=, :url=, :cluster=

lib/pusher/client.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Pusher
44
class Client
5-
attr_accessor :scheme, :host, :port, :app_id, :key, :secret, :notification_host
5+
attr_accessor :scheme, :host, :port, :app_id, :key, :secret, :notification_host, :notification_scheme
66
attr_reader :http_proxy, :proxy
77
attr_writer :connect_timeout, :send_timeout, :receive_timeout,
88
:keep_alive_timeout
@@ -36,9 +36,12 @@ def initialize(options = {})
3636
merged_options[:notification_host] =
3737
options.fetch(:notification_host, "hedwig-staging.herokuapp.com")
3838

39-
@scheme, @host, @port, @app_id, @key, @secret, @notification_host =
39+
merged_options[:notification_scheme] =
40+
options.fetch(:notification_scheme, "https")
41+
42+
@scheme, @host, @port, @app_id, @key, @secret, @notification_host, @notification_scheme =
4043
merged_options.values_at(
41-
:scheme, :host, :port, :app_id, :key, :secret, :notification_host
44+
:scheme, :host, :port, :app_id, :key, :secret, :notification_host, :notification_scheme
4245
)
4346

4447
@http_proxy = nil
@@ -304,7 +307,8 @@ def trigger_batch_async(*events)
304307
end
305308

306309
def notification_client
307-
@notification_client ||= NativeNotification::Client.new(@app_id, @notification_host, self)
310+
@notification_client ||=
311+
NativeNotification::Client.new(@app_id, @notification_host, @notification_scheme, self)
308312
end
309313

310314

lib/pusher/native_notification/client.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ class Client
99
RESTRICTED_GCM_PAYLOAD_KEYS = [:to, :registration_ids]
1010
WEBHOOK_LEVELS = ["DEBUG", "INFO"]
1111

12-
def initialize(app_id, host, pusher_client)
12+
def initialize(app_id, host, scheme, pusher_client)
1313
@app_id = app_id
1414
@host = host
15+
@scheme = scheme
1516
@pusher_client = pusher_client
1617
end
1718

@@ -56,7 +57,7 @@ def payload(interests, data)
5657
end
5758

5859
def url(path = nil)
59-
URI.parse("https://#{@host}/#{API_PREFIX}/#{API_VERSION}/apps/#{@app_id}#{path}")
60+
URI.parse("#{@scheme}://#{@host}/#{API_PREFIX}/#{API_VERSION}/apps/#{@app_id}#{path}")
6061
end
6162

6263
# Validate payload

0 commit comments

Comments
 (0)