Module: Google::Cloud

Defined in:
lib/google-cloud-language.rb,
lib/google/cloud/language.rb,
lib/google/cloud/language/project.rb,
lib/google/cloud/language/service.rb,
lib/google/cloud/language/version.rb,
lib/google/cloud/language/document.rb,
lib/google/cloud/language/annotation.rb,
lib/google/cloud/language/credentials.rb

Defined Under Namespace

Modules: Language

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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

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

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

Examples:

require "google/cloud/language"

language = Google::Cloud.language

content = "Darth Vader is the best villain in Star Wars."
document = language.document content
annotation = document.annotate

Parameters:

  • project (String) (defaults to: nil)

    Project identifier for the Language 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>)

    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/cloud-platform"
  • retries (Integer)

    This option is not currently supported.

  • timeout (Integer)

    Default timeout to use in requests. Optional.

Returns:



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/google-cloud-language.rb', line 102

def self.language project = nil, keyfile = nil, scope: nil, retries: nil,
                  timeout: nil
  require "google/cloud/language"
  project ||= Google::Cloud::Language::Project.default_project
  if keyfile.nil?
    credentials = Google::Cloud::Language::Credentials.default scope: scope
  else
    credentials = Google::Cloud::Language::Credentials.new(
      keyfile, scope: scope)
  end
  Google::Cloud::Language::Project.new(
    Google::Cloud::Language::Service.new(
      project, credentials, retries: retries, timeout: timeout))
end

Instance Method Details

#language(scope: nil, retries: nil, timeout: nil) ⇒ Google::Cloud::Language::Project

Creates a new object for connecting to the Language 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
language = gcloud.language

content = "Darth Vader is the best villain in Star Wars."
document = language.document content
annotation = document.annotate

The default scope can be overridden with the scope option:

require "google/cloud"

gcloud  = Google::Cloud.new
platform_scope = "https://www.googleapis.com/auth/cloud-platform"
language = gcloud.language scope: platform_scope

Parameters:

  • 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/cloud-platform"
  • retries (Integer)

    This option is not currently supported.

  • timeout (Integer)

    Default timeout to use in requests. Optional.

Returns:



63
64
65
66
67
# File 'lib/google-cloud-language.rb', line 63

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