lib/google/cloud/storage.rb in google-cloud-storage-1.7.1 vs lib/google/cloud/storage.rb in google-cloud-storage-1.8.0

- old
+ new

@@ -35,12 +35,12 @@ # # ```ruby # require "google/cloud/storage" # # storage = Google::Cloud::Storage.new( - # project: "my-todo-project", - # keyfile: "/path/to/keyfile.json" + # project_id: "my-project", + # credentials: "/path/to/keyfile.json" # ) # # bucket = storage.bucket "my-bucket" # file = bucket.file "path/to/my-file.ext" # ``` @@ -549,14 +549,16 @@ # # For more information on connecting to Google Cloud see the # [Authentication # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication). # - # @param [String] project Project identifier for the Storage service you - # are connecting to. - # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If - # file path the file must be readable. + # @param [String] project_id Project identifier for the Storage service + # you are connecting to. If not present, the default project for the + # credentials is used. + # @param [String, Hash, Google::Auth::Credentials] credentials The path to + # the keyfile as a String, the contents of the keyfile as a Hash, or a + # Google::Auth::Credentials object. (See {Storage::Credentials}) # @param [String, Array<String>] scope 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](https://developers.google.com/identity/protocols/OAuth2). # @@ -564,39 +566,40 @@ # # * `https://www.googleapis.com/auth/devstorage.full_control` # @param [Integer] retries Number of times to retry requests on server # error. The default value is `3`. Optional. # @param [Integer] timeout Default timeout to use in requests. Optional. + # @param [String] project Alias for the `project_id` argument. Deprecated. + # @param [String] keyfile Alias for the `credentials` argument. + # Deprecated. # # @return [Google::Cloud::Storage::Project] # # @example # require "google/cloud/storage" # # storage = Google::Cloud::Storage.new( - # project: "my-todo-project", - # keyfile: "/path/to/keyfile.json" + # project_id: "my-project", + # credentials: "/path/to/keyfile.json" # ) # # bucket = storage.bucket "my-bucket" # file = bucket.file "path/to/my-file.ext" # - def self.new project: nil, keyfile: nil, scope: nil, retries: nil, - timeout: nil - project ||= Google::Cloud::Storage::Project.default_project - project = project.to_s # Always cast to a string - fail ArgumentError, "project is missing" if project.empty? + def self.new project_id: nil, credentials: nil, scope: nil, retries: nil, + timeout: nil, project: nil, keyfile: nil + project_id ||= (project || Storage::Project.default_project_id) + project_id = project_id.to_s # Always cast to a string + fail ArgumentError, "project_id is missing" if project_id.empty? - if keyfile.nil? - credentials = Google::Cloud::Storage::Credentials.default scope: scope - else - credentials = Google::Cloud::Storage::Credentials.new( - keyfile, scope: scope) + credentials ||= (keyfile || Storage::Credentials.default(scope: scope)) + unless credentials.is_a? Google::Auth::Credentials + credentials = Storage::Credentials.new credentials, scope: scope end - Google::Cloud::Storage::Project.new( - Google::Cloud::Storage::Service.new( - project, credentials, retries: retries, timeout: timeout)) + Storage::Project.new( + Storage::Service.new( + project_id, credentials, retries: retries, timeout: timeout)) end end end end