lib/google/cloud/vision.rb in google-cloud-vision-0.25.0 vs lib/google/cloud/vision.rb in google-cloud-vision-0.26.0

- old
+ new

@@ -568,14 +568,16 @@ ## # Creates a new object for connecting to the Vision service. # Each call creates a new connection. # - # @param [String] project Project identifier for the Vision 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 Vision 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 {Vision::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). # @@ -583,10 +585,13 @@ # # * `https://www.googleapis.com/auth/cloud-platform` # @param [Integer] timeout Default timeout to use in requests. Optional. # @param [Hash] client_config A hash of values to override the default # behavior of the API client. Optional. + # @param [String] project Alias for the `project_id` argument. Deprecated. + # @param [String] keyfile Alias for the `credentials` argument. + # Deprecated. # # @return [Google::Cloud::Vision::Project] # # @example # require "google/cloud/vision" @@ -596,26 +601,24 @@ # image = vision.image "path/to/landmark.jpg" # # landmark = image.landmark # landmark.description #=> "Mount Rushmore" # - def self.new project: nil, keyfile: nil, scope: nil, timeout: nil, - client_config: nil - project ||= Google::Cloud::Vision::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, timeout: nil, + client_config: nil, project: nil, keyfile: nil + project_id ||= (project || Vision::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::Vision::Credentials.default scope: scope - else - credentials = Google::Cloud::Vision::Credentials.new \ - keyfile, scope: scope + credentials ||= (keyfile || Vision::Credentials.default(scope: scope)) + unless credentials.is_a? Google::Auth::Credentials + credentials = Vision::Credentials.new credentials, scope: scope end - Google::Cloud::Vision::Project.new( - Google::Cloud::Vision::Service.new( - project, credentials, timeout: timeout, - client_config: client_config)) + Vision::Project.new( + Vision::Service.new( + project_id, credentials, timeout: timeout, + client_config: client_config)) end end end end