def apply()

in notificationworkerlambda/src/main/scala/com/gu/notifications/worker/delivery/fcm/FcmClient.scala [110:127]


  def apply(config: FcmConfig, firebaseAppName: Option[String]): Try[FcmFirebase] =
    Try {
      val credential = GoogleCredentials.fromStream(new ByteArrayInputStream(config.serviceAccountKey.getBytes))
      val firebaseOptions: FirebaseOptions = FirebaseOptions.builder()
          .setCredentials(credential)
          .setHttpTransport(new OkGoogleHttpTransport)
          .setConnectTimeout(10000) // 10 seconds
          .build
      val firebaseApp = firebaseAppName match {
        case None => FirebaseApp.initializeApp(firebaseOptions)
        case Some(name) => FirebaseApp.initializeApp(firebaseOptions, name)
      }
      val projectId = credential match {
        case s: ServiceAccountCredentials => s.getProjectId()
        case _ => ""
      }
      new FcmFirebase(FirebaseMessaging.getInstance(firebaseApp), firebaseApp, config, projectId, credential, firebaseOptions.getJsonFactory())
    }