我试图使用firebase的新开源java firebase-admin sdk和jruby。 firebase文档在java中具有以下初始化说明:
FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
.setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
第一次尝试使用jruby。我使用jbuilder加载了firebase软件包。访问这些初始化方法有些麻烦。需要一些指导,将其从java翻译成jruby。
答案 0 :(得分:1)
想出来
class FirebaseInstance
attr_accessor :options, :app
include_package 'com.google.firebase'
include_package 'com.google.firebase.auth'
def initialize
@options = set_options
@app = FirebaseApp.initializeApp(@options)
end
def set_options
builder = FirebaseOptions::Builder.new
builder.setDatabaseUrl(<URL>)
builder.setCredential(credentials)
builder.build
end
def credentials
service_account = Java.JavaIo.FileInputStream.new(<FILE LOCATION>)
credentials = FirebaseCredentials.fromCertificate(service_account)
end
end