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/policy.rb,
lib/google/cloud/storage/convert.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/hmac_key.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/post_object.rb,
lib/google/cloud/storage/notification.rb,
lib/google/cloud/storage/file/verifier.rb,
lib/google/cloud/storage/hmac_key/list.rb,
lib/google/cloud/storage/file/signer_v2.rb,
lib/google/cloud/storage/file/signer_v4.rb,
lib/google/cloud/storage/policy/binding.rb,
lib/google/cloud/storage/policy/bindings.rb,
lib/google/cloud/storage/bucket/lifecycle.rb,
lib/google/cloud/storage/policy/condition.rb

Defined Under Namespace

Modules: Storage

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.storage(project_id = nil, credentials = nil, scope: nil, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, max_elapsed_time: nil, base_interval: nil, max_interval: nil, multiplier: nil, upload_chunk_size: 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.

Examples:

require "google/cloud/storage"

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

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

Parameters:

  • project_id (String) (defaults to: nil)

    Project identifier for the Storage service you are connecting to. If not present, the default project for the credentials is used.

  • credentials (String, Hash, Google::Auth::Credentials) (defaults to: nil)

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

  • 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.

    The default scope is:

    • https://www.googleapis.com/auth/devstorage.full_control
  • retries (Integer) (defaults to: nil)

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

  • max_elapsed_time (Integer) (defaults to: nil)

    Total time in seconds that requests are allowed to keep being retried.

  • base_interval (Float) (defaults to: nil)

    The initial interval in seconds between tries.

  • max_interval (Integer) (defaults to: nil)

    The maximum interval in seconds that any individual retry can reach.

  • multiplier (Integer) (defaults to: nil)

    Each successive interval grows by this factor. A multipler of 1.5 means the next interval will be 1.5x the current interval.

  • timeout (Integer) (defaults to: nil)

    (default timeout) The max duration, in seconds, to wait before timing out. Optional. If left blank, the wait will be at most the time permitted by the underlying HTTP/RPC protocol.

  • open_timeout (Integer) (defaults to: nil)

    How long, in seconds, before failed connections time out. Optional.

  • read_timeout (Integer) (defaults to: nil)

    How long, in seconds, before requests time out. Optional.

  • send_timeout (Integer) (defaults to: nil)

    How long, in seconds, before receiving response from server times out. Optional.

  • upload_chunk_size (Integer) (defaults to: nil)

    The chunk size of storage upload, in bytes. The default value is 100 MB, i.e. 104_857_600 bytes. To disable chunking and upload the complete file regardless of size, pass 0 as the chunk size.

Returns:



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/google-cloud-storage.rb', line 142

def self.storage project_id = nil, credentials = nil, scope: nil,
                 retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil,
                 max_elapsed_time: nil, base_interval: nil, max_interval: nil, multiplier: nil,
                 upload_chunk_size: nil
  require "google/cloud/storage"
  Google::Cloud::Storage.new project_id: project_id,
                             credentials: credentials,
                             scope: scope,
                             retries: retries,
                             timeout: timeout,
                             open_timeout: open_timeout || timeout,
                             read_timeout: read_timeout || timeout,
                             send_timeout: send_timeout || timeout,
                             max_elapsed_time: max_elapsed_time,
                             base_interval: base_interval,
                             max_interval: max_interval,
                             multiplier: multiplier,
                             upload_chunk_size: upload_chunk_size
end

Instance Method Details

#storage(scope: nil, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil, max_elapsed_time: nil, base_interval: nil, max_interval: nil, multiplier: nil, upload_chunk_size: 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.

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.

    The default scope is:

    • https://www.googleapis.com/auth/devstorage.full_control
  • retries (Integer) (defaults to: nil)

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

  • max_elapsed_time (Integer) (defaults to: nil)

    Total time in seconds that requests are allowed to keep being retried.

  • base_interval (Float) (defaults to: nil)

    The initial interval in seconds between tries.

  • max_interval (Integer) (defaults to: nil)

    The maximum interval in seconds that any individual retry can reach.

  • multiplier (Integer) (defaults to: nil)

    Each successive interval grows by this factor. A multipler of 1.5 means the next interval will be 1.5x the current interval.

  • timeout (Integer) (defaults to: nil)

    (default timeout) The max duration, in seconds, to wait before timing out. Optional. If left blank, the wait will be at most the time permitted by the underlying HTTP/RPC protocol.

  • open_timeout (Integer) (defaults to: nil)

    How long, in seconds, before failed connections time out. Optional.

  • read_timeout (Integer) (defaults to: nil)

    How long, in seconds, before requests time out. Optional.

  • send_timeout (Integer) (defaults to: nil)

    How long, in seconds, before receiving response from server times out. Optional.

  • upload_chunk_size (Integer) (defaults to: nil)

    The chunk size of storage upload, in bytes. The default value is 100 MB, i.e. 104_857_600 bytes. To disable chunking and upload the complete file regardless of size, pass 0 as the chunk size.

Returns:

See Also:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/google-cloud-storage.rb', line 79

def storage scope: nil, retries: nil, timeout: nil, open_timeout: nil, read_timeout: nil, send_timeout: nil,
            max_elapsed_time: nil, base_interval: nil, max_interval: nil, multiplier: nil, upload_chunk_size: nil
  Google::Cloud.storage @project, @keyfile, scope: scope,
                                            retries: retries || @retries,
                                            timeout: timeout || @timeout,
                                            open_timeout: open_timeout || timeout,
                                            read_timeout: read_timeout || timeout,
                                            send_timeout: send_timeout || timeout,
                                            max_elapsed_time: max_elapsed_time,
                                            base_interval: base_interval,
                                            max_interval: max_interval,
                                            multiplier: multiplier,
                                            upload_chunk_size: upload_chunk_size
end