Skip to content
Merged
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
10 changes: 9 additions & 1 deletion lib/fcm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,18 @@ def validate_condition_topics?(condition)
def jwt_token
scope = "https://www.googleapis.com/auth/firebase.messaging"
authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open(@json_key_path),
json_key_io: json_key,
scope: scope,
)
token = authorizer.fetch_access_token!
token["access_token"]
end

def json_key
@json_key ||= if @json_key_path.respond_to?(:read)
@json_key_path
else
File.open(@json_key_path)
end
end
end
12 changes: 12 additions & 0 deletions spec/fcm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,16 @@
describe "subscribing to a topic" do
# TODO
end

describe "credentials path" do
it "can be a path to a file" do
fcm = FCM.new("test", "README.md")
expect(fcm.__send__(:json_key).class).to eq(File)
end

it "can be an IO object" do
fcm = FCM.new("test", StringIO.new("hey"))
expect(fcm.__send__(:json_key).class).to eq(StringIO)
end
end
end