Skip to content

Commit 94e5da6

Browse files
author
Sasa Rosic
committed
Allow faraday client configuration
1 parent ec489fa commit 94e5da6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/fcm.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ class FCM
1212
INSTANCE_ID_API = "https://iid.googleapis.com"
1313
TOPIC_REGEX = /[a-zA-Z0-9\-_.~%]+/
1414

15-
def initialize(json_key_path = "", project_name = "", http_options = {})
15+
def initialize(json_key_path = "", project_name = "", http_options = {}, faraday_configurer = nil)
1616
@json_key_path = json_key_path
1717
@project_name = project_name
1818
@http_options = http_options
19+
@faraday_configurer = faraday_configurer
1920
end
2021

2122
# See https://firebase.google.com/docs/cloud-messaging/send-message
@@ -202,6 +203,7 @@ def for_uri(uri, extra_headers = {})
202203
extra_headers.each do |key, value|
203204
faraday.headers[key] = value
204205
end
206+
@faraday_configurer.call(faraday) if @faraday_configurer
205207
end
206208
yield connection
207209
end

spec/fcm_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@
3737
end
3838
end
3939

40+
describe 'faraday configurer' do
41+
let(:configurer) { ->(faraday) { } }
42+
let(:client) { FCM.new(json_key_path, '', {}, configurer) }
43+
44+
it 'should be called when initializing faraday client' do
45+
expect(configurer).to receive(:call).with(Faraday::Connection)
46+
47+
client.__send__(:for_uri, '') {}
48+
end
49+
end
50+
4051
describe "#send_v1 or #send_notification_v1" do
4152
let(:client) { FCM.new(json_key_path, project_name) }
4253

0 commit comments

Comments
 (0)