Class: Firebase::Admin::Credentials
- Inherits:
-
Object
- Object
- Firebase::Admin::Credentials
- Defined in:
- lib/firebase/admin/credentials.rb
Overview
Firebase credentials.
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Gets the google credentials.
Class Method Summary collapse
-
.from_default ⇒ Firebase::Admin::Credentials
Loads application default credentials.
-
.from_file(file) ⇒ Firebase::Admin::Credentials
Loads google credentials from a specified file path.
-
.from_json(json) ⇒ Firebase::Admin::Credentials
Loads google credentials from a JSON string.
Instance Method Summary collapse
-
#apply!(hash, opts = {}) ⇒ Object
Apply the credentials.
-
#initialize(credentials) ⇒ Credentials
constructor
Constructs a Credential from the specified Google Credentials.
-
#project_id ⇒ Object
Gets the google project id.
Constructor Details
#initialize(credentials) ⇒ Credentials
Constructs a Credential from the specified Google Credentials.
56 57 58 59 |
# File 'lib/firebase/admin/credentials.rb', line 56 def initialize(credentials) raise ArgumentError, "credentials cannot be nil" if credentials.nil? @credentials = credentials end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Gets the google credentials
50 51 52 |
# File 'lib/firebase/admin/credentials.rb', line 50 def credentials @credentials end |
Class Method Details
.from_default ⇒ Firebase::Admin::Credentials
Loads application default credentials.
44 45 46 |
# File 'lib/firebase/admin/credentials.rb', line 44 def from_default new(Google::Auth.get_application_default(SCOPE)) end |
.from_file(file) ⇒ Firebase::Admin::Credentials
Loads google credentials from a specified file path.
25 26 27 28 |
# File 'lib/firebase/admin/credentials.rb', line 25 def from_file(file) json = file.is_a?(File) ? file.read : File.read(file) from_json(json) end |
.from_json(json) ⇒ Firebase::Admin::Credentials
Loads google credentials from a JSON string.
36 37 38 39 |
# File 'lib/firebase/admin/credentials.rb', line 36 def from_json(json) io = StringIO.new(json) new(Google::Auth::DefaultCredentials.make_creds(scope: SCOPE, json_key_io: io)) end |
Instance Method Details
#apply!(hash, opts = {}) ⇒ Object
Apply the credentials
67 68 69 |
# File 'lib/firebase/admin/credentials.rb', line 67 def apply!(hash, opts = {}) @credentials.apply!(hash, opts) end |
#project_id ⇒ Object
Gets the google project id
62 63 64 |
# File 'lib/firebase/admin/credentials.rb', line 62 def project_id @credentials.project_id end |