Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/fcm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ class FCM
INSTANCE_ID_API = "https://iid.googleapis.com"
TOPIC_REGEX = /[a-zA-Z0-9\-_.~%]+/

def initialize(json_key_path = "", project_name = "", http_options = {})
def initialize(json_key_path = "", project_name = "", http_options = {}, faraday_configurer = nil)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
Metrics/LineLength: Line is too long. [100/80]

@json_key_path = json_key_path
@project_name = project_name
@http_options = http_options
@faraday_configurer = faraday_configurer
end

# See https://firebase.google.com/docs/cloud-messaging/send-message
Expand Down Expand Up @@ -202,6 +203,7 @@ def for_uri(uri, extra_headers = {})
extra_headers.each do |key, value|
faraday.headers[key] = value
end
@faraday_configurer.call(faraday) if @faraday_configurer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/SafeNavigation: Use safe navigation (&.) instead of checking if an object exists before calling the method.

end
yield connection
end
Expand Down
11 changes: 11 additions & 0 deletions spec/fcm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@
end
end

describe 'faraday configurer' do
let(:configurer) { ->(faraday) { } }
let(:client) { FCM.new(json_key_path, '', {}, configurer) }

it 'should be called when initializing faraday client' do
expect(configurer).to receive(:call).with(Faraday::Connection)

client.__send__(:for_uri, '') {}
end
end

describe "#send_v1 or #send_notification_v1" do
let(:client) { FCM.new(json_key_path, project_name) }

Expand Down