Module: Google::Cloud

Defined in:
lib/google-cloud-storage.rb,
lib/google/cloud/storage.rb,
lib/google/cloud/storage/file.rb,
lib/google/cloud/storage/bucket.rb,
lib/google/cloud/storage/errors.rb,
lib/google/cloud/storage/project.rb,
lib/google/cloud/storage/service.rb,
lib/google/cloud/storage/version.rb,
lib/google/cloud/storage/file/acl.rb,
lib/google/cloud/storage/file/list.rb,
lib/google/cloud/storage/bucket/acl.rb,
lib/google/cloud/storage/bucket/cors.rb,
lib/google/cloud/storage/bucket/list.rb,
lib/google/cloud/storage/credentials.rb,
lib/google/cloud/storage/file/verifier.rb

Defined Under Namespace

Modules: Storage

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.storage(project = nil, keyfile = nil, scope: nil, retries: nil, timeout: nil) ⇒ Google::Cloud::Storage::Project

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).

Examples:

require "google/cloud/storage"

storage = Google::Cloud.storage "my-todo-project",
                         "/path/to/keyfile.json"

bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"

Parameters:

  • project (String) (defaults to: nil)

    Project identifier for the Storage service you are connecting to.

  • keyfile (String, Hash) (defaults to: nil)

    Keyfile downloaded from Google Cloud. If file path the file must be readable.

  • scope (String, Array<String>) (defaults to: nil)

    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](developers.google.com/identity/protocols/OAuth2).

    The default scope is:

  • retries (Integer) (defaults to: nil)

    Number of times to retry requests on server error. The default value is ‘3`. Optional.

  • timeout (Integer) (defaults to: nil)

    Default timeout to use in requests. Optional.

Returns:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/google-cloud-storage.rb', line 105

def self.storage project = nil, keyfile = nil, scope: nil, retries: nil,
                 timeout: nil
  require "google/cloud/storage"
  project ||= Google::Cloud::Storage::Project.default_project
  project = project.to_s # Always cast to a string
  fail ArgumentError, "project is missing" if project.empty?

  if keyfile.nil?
    credentials = Google::Cloud::Storage::Credentials.default scope: scope
  else
    credentials = Google::Cloud::Storage::Credentials.new(
      keyfile, scope: scope)
  end

  Google::Cloud::Storage::Project.new(
    Google::Cloud::Storage::Service.new(
      project, credentials, retries: retries, timeout: timeout))
end

Instance Method Details

#storage(scope: nil, retries: nil, timeout: nil) ⇒ Google::Cloud::Storage::Project

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

For more information on connecting to Google Cloud see the [Authentication Guide](googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).

Examples:

require "google/cloud"

gcloud  = Google::Cloud.new
storage = gcloud.storage
bucket = storage.bucket "my-bucket"
file = bucket.file "path/to/my-file.ext"

The default scope can be overridden with the ‘scope` option:

require "google/cloud"

gcloud  = Google::Cloud.new
readonly_scope = "https://www.googleapis.com/auth/devstorage.read_only"
readonly_storage = gcloud.storage scope: readonly_scope

Parameters:

  • scope (String, Array<String>) (defaults to: nil)

    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](developers.google.com/identity/protocols/OAuth2).

    The default scope is:

  • retries (Integer) (defaults to: nil)

    Number of times to retry requests on server error. The default value is ‘3`. Optional.

  • timeout (Integer) (defaults to: nil)

    Default timeout to use in requests. Optional.

Returns:

See Also:



65
66
67
68
69
# File 'lib/google-cloud-storage.rb', line 65

def storage scope: nil, retries: nil, timeout: nil
  Google::Cloud.storage @project, @keyfile, scope: scope,
                                            retries: (retries || @retries),
                                            timeout: (timeout || @timeout)
end