@@ -13,7 +13,7 @@ def initialize(config)
1313      end 
1414
1515      def  push ( notification ) 
16-         response  =  httpx_session . post ( "v1/projects/#{ config . fetch ( :project_id ) }  ,  json : payload_from ( notification ) ,   headers :  {   authorization :  "Bearer  #{ access_token } "   } ) 
16+         response  =  httpx_session . post ( "v1/projects/#{ config . fetch ( :project_id ) }  ,  json : payload_from ( notification ) ) 
1717        handle_error ( response )  if  response . error 
1818      end 
1919
@@ -22,20 +22,7 @@ def push(notification)
2222
2323        def  httpx_session 
2424          self . class . httpx_sessions  ||= { } 
25-           self . class . httpx_sessions [ config ]  ||= build_httpx_session 
26-         end 
27- 
28-         # FCM suggests at least a 10s timeout for requests, we set 15 to add some buffer. 
29-         # https://firebase.google.com/docs/cloud-messaging/scale-fcm#timeouts 
30-         DEFAULT_REQUEST_TIMEOUT  =  15 . seconds 
31-         DEFAULT_POOL_SIZE        =  5 
32- 
33-         def  build_httpx_session 
34-           HTTPX . 
35-             plugin ( :persistent ,  close_on_fork : true ) . 
36-             with ( timeout : {  request_timeout : config [ :request_timeout ]  || DEFAULT_REQUEST_TIMEOUT  } ) . 
37-             with ( pool_options : {  max_connections : config [ :connection_pool_size ]  || DEFAULT_POOL_SIZE  } ) . 
38-             with ( origin : "https://fcm.googleapis.com" ) 
25+           self . class . httpx_sessions [ config ]  ||= HttpxSession . new ( config ) 
3926        end 
4027
4128        def  payload_from ( notification ) 
@@ -75,13 +62,6 @@ def stringify(hash)
7562          hash . compact . transform_values ( &:to_s ) 
7663        end 
7764
78-         def  access_token 
79-           authorizer  =  Google ::Auth ::ServiceAccountCredentials . make_creds  \
80-             json_key_io : StringIO . new ( config . fetch ( :encryption_key ) ) , 
81-             scope : "https://www.googleapis.com/auth/firebase.messaging" 
82-           authorizer . fetch_access_token! [ "access_token" ] 
83-         end 
84- 
8565        def  handle_error ( response ) 
8666          if  response . is_a? ( HTTPX ::ErrorResponse ) 
8767            handle_network_error ( response . error ) 
0 commit comments