Class: Gcloud::Search::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/search/project.rb

Overview

Project

Projects are top-level containers in Google Cloud Platform. They store information about billing and authorized users, and they control access to Google Cloud Search resources. Each project has a friendly name and a unique ID. Projects can be created only in the Google Developers Console. See Gcloud#search.

Examples:

require "gcloud"

gcloud = Gcloud.new
search = gcloud.search
index = search.index "books"

Instance Method Summary collapse

Instance Method Details

#index(index_id, skip_lookup: false) ⇒ Gcloud::Search::Index?

Retrieves an existing index by ID.

Examples:

require "gcloud"

gcloud = Gcloud.new
search = gcloud.search

index = search.index "books"
index.index_id #=> "books"

A new index can be created with index_id and skip_lookup:

require "gcloud"

gcloud = Gcloud.new
search = gcloud.search

index = search.index "more-books"
index #=> nil
index = search.index "more-books", skip_lookup: true
index.index_id #=> "more-books"

Parameters:

  • index_id (String)

    The ID of an index.

  • skip_lookup (Boolean)

    Optionally create an Index object without verifying the index resource exists on the Search service. Documents saved on this object will create the index resource if the resource does not yet exist. Default is false.

Returns:


112
113
114
115
116
117
118
119
120
# File 'lib/gcloud/search/project.rb', line 112

def index index_id, skip_lookup: false
  if skip_lookup
    index_hash = { "indexId" => index_id, "projectId" => project }
    return Gcloud::Search::Index.from_raw index_hash, connection
  end
  indexes(prefix: index_id).all.detect do |ix|
    ix.index_id == index_id
  end
end

#indexes(prefix: nil, token: nil, max: nil) ⇒ Array<Gcloud::Search::Index>

Retrieves the list of indexes belonging to the project.

Examples:

require "gcloud"

gcloud = Gcloud.new
search = gcloud.search

indexes = search.indexes
indexes.each do |index|
  puts index.index_id
end

Using pagination: (See Index::List)

require "gcloud"

gcloud = Gcloud.new
search = gcloud.search

indexes = search.indexes
loop do
  indexes.each do |index|
    puts index.index_id
  end
  break unless indexes.next?
  indexes = indexes.next
end

Parameters:

  • prefix (String)

    The prefix of the index name. It is used to list all indexes with names that have this prefix.

  • token (String)

    A previously-returned page token representing part of the larger set of results to view.

  • max (Integer)

    Maximum number of indexes to return. The default is 100.

Returns:


161
162
163
164
165
166
167
168
169
170
# File 'lib/gcloud/search/project.rb', line 161

def indexes prefix: nil, token: nil, max: nil
  ensure_connection!
  options = { prefix: prefix, token: token, max: max }
  resp = connection.list_indexes options
  if resp.success?
    Index::List.from_response resp, connection
  else
    fail ApiError.from_response(resp)
  end
end

#projectString

The ID of the current project.

Examples:

require "gcloud"

gcloud = Gcloud.new "my-project", "/path/to/keyfile.json"
search = gcloud.search

search.project #=> "my-project"

Returns:

  • (String)

68
69
70
# File 'lib/gcloud/search/project.rb', line 68

def project
  connection.project
end