Class: Google::Cloud::Gemserver::CLI::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/gemserver/cli/request.rb

Overview

Request

Responsible for sending requests to the gemserver for operations that involve the database. Gem operations are done with the 'gem' command and are not in the scope of Request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = nil, proj_name = nil) ⇒ Request

Initialize the Backend object by constructing an HTTP object for the gemserver.

gemserver was deployed to. Optional.

Parameters:

  • url (String) (defaults to: nil)

    The URL of the gemserver. Optional.

  • proj_name (String) (defaults to: nil)

    The name of the Google Cloud Platform the



46
47
48
49
# File 'lib/google/cloud/gemserver/cli/request.rb', line 46

def initialize url = nil, proj_name = nil
  gemserver_url = url.nil? == true ? remote(proj_name) : url
  @http = Net::HTTP.new gemserver_url
end

Instance Attribute Details

#httpNet::HTTP

The HTTP object used to connect to and send requests to the gemserver.

Returns:

  • (Net::HTTP)


36
37
38
# File 'lib/google/cloud/gemserver/cli/request.rb', line 36

def http
  @http
end

Instance Method Details

#create_key(permissions = nil) ⇒ Net::HTTPResponse

Send a request to the gemserver to create a key with certain permissions.

have (read, write, or both). Optional.

Parameters:

  • permissions (String) (defaults to: nil)

    The permissions the generated key will

Returns:

  • (Net::HTTPResponse)


59
60
61
# File 'lib/google/cloud/gemserver/cli/request.rb', line 59

def create_key permissions = nil
  send_req Net::HTTP::Post, "/api/v1/key", {permissions: permissions}
end

#delete_key(key) ⇒ Net::HTTPResponse

Send a request to the gemserver to delete a key.

Parameters:

  • key (String)

    The key to delete.

Returns:

  • (Net::HTTPResponse)


69
70
71
# File 'lib/google/cloud/gemserver/cli/request.rb', line 69

def delete_key key
  send_req Net::HTTP::Put, "/api/v1/key", {key: key}
end

#healthNet::HTTPResponse

Sends a request to the gemserver to ensure it is accessible.

Returns:

  • (Net::HTTPResponse)


86
87
88
# File 'lib/google/cloud/gemserver/cli/request.rb', line 86

def health
  send_req Net::HTTP::Get, "/health"
end

#statsNet::HTTPResponse

Send a request to the gemserver to fetch information about stored private gems and cached gem dependencies.

Returns:

  • (Net::HTTPResponse)


78
79
80
# File 'lib/google/cloud/gemserver/cli/request.rb', line 78

def stats
  send_req Net::HTTP::Post, "/api/v1/stats"
end