Module: Google::Cloud::Firestore

Defined in:
lib/google/cloud/firestore.rb,
lib/google/cloud/firestore/batch.rb,
lib/google/cloud/firestore/query.rb,
lib/google/cloud/firestore/client.rb,
lib/google/cloud/firestore/convert.rb,
lib/google/cloud/firestore/service.rb,
lib/google/cloud/firestore/v1beta1.rb,
lib/google/cloud/firestore/version.rb,
lib/google/cloud/firestore/generate.rb,
lib/google/cloud/firestore/field_path.rb,
lib/google/cloud/firestore/credentials.rb,
lib/google/cloud/firestore/field_value.rb,
lib/google/cloud/firestore/transaction.rb,
lib/google/cloud/firestore/commit_response.rb,
lib/google/cloud/firestore/document_snapshot.rb,
lib/google/cloud/firestore/document_reference.rb,
lib/google/cloud/firestore/collection_reference.rb,
lib/google/cloud/firestore/v1beta1/doc/overview.rb,
lib/google/cloud/firestore/v1beta1/firestore_client.rb

Overview

Ruby Client for Google Cloud Firestore API (Beta)

Google Cloud Firestore API:

Quick Start

In order to use this library, you first need to go through the following steps:

  1. Select or create a Cloud Platform project.
  2. Enable the Google Cloud Firestore API.
  3. Setup Authentication.

Installation

$ gem install google-cloud-firestore

Next Steps

Defined Under Namespace

Modules: V1beta1 Classes: Batch, Client, CollectionReference, CommitResponse, Credentials, DocumentReference, DocumentSnapshot, FieldPath, FieldValue, Query, Transaction

Constant Summary collapse

VERSION =
"0.21.0".freeze

Class Method Summary collapse

Class Method Details

.configure {|Google::Cloud.configure.firestore| ... } ⇒ Google::Cloud::Config

Configure the Google Cloud Firestore library.

The following Firestore configuration parameters are supported:

  • project_id - (String) Identifier for a Firestore project. (The parameter project is considered deprecated, but may also be used.)
  • credentials - (String, Hash, Google::Auth::Credentials) The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object. (See Credentials) (The parameter keyfile is considered deprecated, but may also be used.)
  • scope - (String, Array) The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access.
  • timeout - (Integer) Default timeout to use in requests.
  • client_config - (Hash) A hash of values to override the default behavior of the API client.

Yields:

Returns:

  • (Google::Cloud::Config)

    The configuration object the Google::Cloud::Firestore library uses.



540
541
542
543
544
# File 'lib/google/cloud/firestore.rb', line 540

def self.configure
  yield Google::Cloud.configure.firestore if block_given?

  Google::Cloud.configure.firestore
end

.new(project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, project: nil, keyfile: nil) ⇒ Google::Cloud::Firestore::Client

Creates a new object for connecting to the Firestore service. Each call creates a new connection.

For more information on connecting to Google Cloud see the Authentication Guide.

Examples:

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

Parameters:

  • project_id (String)

    Identifier for a Firestore project. If not present, the default project for the credentials is used.

  • credentials (String, Hash, Google::Auth::Credentials)

    The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object. (See Credentials)

  • scope (String, Array<String>)

    The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs.

    The default scope is:

    • https://www.googleapis.com/auth/datastore
  • timeout (Integer)

    Default timeout to use in requests. Optional.

  • client_config (Hash)

    A hash of values to override the default behavior of the API client. Optional.

  • project (String)

    Alias for the project_id argument. Deprecated.

  • keyfile (String)

    Alias for the credentials argument. Deprecated.

Returns:

Raises:

  • (ArgumentError)


497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'lib/google/cloud/firestore.rb', line 497

def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
             client_config: nil, project: nil, keyfile: nil
  project_id ||= (project || default_project_id)
  project_id = project_id.to_s # Always cast to a string
  raise ArgumentError, "project_id is missing" if project_id.empty?

  scope ||= configure.scope
  timeout ||= configure.timeout
  client_config ||= configure.client_config

  credentials ||= (keyfile || default_credentials(scope: scope))
  unless credentials.is_a? Google::Auth::Credentials
    credentials = Firestore::Credentials.new credentials, scope: scope
  end

  Firestore::Client.new(
    Firestore::Service.new(
      project_id, credentials, timeout: timeout,
                               client_config: client_config
    )
  )
end