Class: Gapic::Schema::Service

Inherits:
Proto
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gapic/schema/wrappers.rb

Overview

Wrapper for a protobuf service.

Constant Summary collapse

OPTION_EXTENSION_NAMES =
{
  "google.api.default_host" => [1049, :string],
  "google.api.oauth_scopes" => [1050, :string],
  "google.api.api_version" => [525_000_001, :string]
}.freeze

Instance Attribute Summary collapse

Attributes inherited from Proto

#address, #descriptor, #docs, #parent

Instance Method Summary collapse

Methods inherited from Proto

#containing_api, #containing_file, #docs_leading_comments, #leading_comments, #leading_detached_comments, #option_named, #path, #span, #trailing_comments

Constructor Details

#initialize(descriptor, address, docs, methods) ⇒ Service

Initializes a Service object.

Parameters:

  • descriptor (Google::Protobuf::ServiceDescriptorProto)

    the protobuf representation of this service.

  • address (Enumerable<String>)

    The address of the proto. See

    address for more info.

  • docs (Google::Protobuf::SourceCodeInfo::Location)

    The docs of the proto. See #docs for more info.

  • methods (Enumerable<Method>)

    The methods of this service.



283
284
285
286
287
# File 'lib/gapic/schema/wrappers.rb', line 283

def initialize descriptor, address, docs, methods
  super descriptor, address, docs
  @methods = methods || []
  @methods.each { |m| m.parent = self }
end

Instance Attribute Details

#methodsObject (readonly)

@ return [Enumerable] The methods of this service.



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/gapic/schema/wrappers.rb', line 270

class Service < Proto
  extend Forwardable

  attr_reader :methods

  # Initializes a Service object.
  # @param descriptor [Google::Protobuf::ServiceDescriptorProto] the
  #   protobuf representation of this service.
  # @param address [Enumerable<String>] The address of the proto. See
  #   #address for more info.
  # @param docs [Google::Protobuf::SourceCodeInfo::Location] The docs
  #   of the proto. See #docs for more info.
  # @param methods [Enumerable<Method>] The methods of this service.
  def initialize descriptor, address, docs, methods
    super descriptor, address, docs
    @methods = methods || []
    @methods.each { |m| m.parent = self }
  end

  OPTION_EXTENSION_NAMES = {
    "google.api.default_host" => [1049, :string],
    "google.api.oauth_scopes" => [1050, :string],
    "google.api.api_version" => [525_000_001, :string]
  }.freeze

  ##
  # Return a configuration of supported option extensions.
  #
  def option_extension_names
    OPTION_EXTENSION_NAMES
  end

  # @return [String] The hostname for this service
  #   (e.g. "foo.googleapis.com"). This should be specified with no
  #   prefix.
  def host
    option_named "google.api.default_host"
  end

  # @return [Array<String>] The OAuth scopes information for the client.
  def scopes
    String(option_named("google.api.oauth_scopes")).split ","
  end

  # @return [String] The API version for this service.
  def api_version
    option_named "google.api.api_version"
  end

  # @return [String] Ruby Package
  def ruby_package
    return nil if parent.nil?

    parent.ruby_package
  end

  # @return [Boolean] True if this service is marked as deprecated, false
  #   otherwise.
  def is_deprecated?
    option_named "deprecated"
  end

  # @return [Array<Google::Api::ResourceDescriptor>] A representation of the resource.
  #   This is generally intended to be attached to the "name" field.
  #   See `google/api/resource.proto`.
  def resources
    require "gapic/resource_lookup"

    @resources ||= Gapic::ResourceLookup.for_service self
  end

  # @return [String] The full name for this service
  #   (e.g. `google.example.Service`).
  #   Useful when matching against other pieces of information
  #   which also reference full proto name, e.g. Service Config
  #   or Grpc Service Config
  def full_name
    @address.join "."
  end

  # @!method name
  #   @return [String] the unqualified name of the service.
  # @!method options
  #   @return [Google::Protobuf::ServiceOptions] the options of this
  #     service.
  def_delegators(
    :descriptor,
    :name,
    :options
  )
end

Instance Method Details

#api_versionString

Returns The API version for this service.

Returns:

  • (String)

    The API version for this service.



315
316
317
# File 'lib/gapic/schema/wrappers.rb', line 315

def api_version
  option_named "google.api.api_version"
end

#full_nameString

Returns The full name for this service (e.g. google.example.Service). Useful when matching against other pieces of information which also reference full proto name, e.g. Service Config or Grpc Service Config.

Returns:

  • (String)

    The full name for this service (e.g. google.example.Service). Useful when matching against other pieces of information which also reference full proto name, e.g. Service Config or Grpc Service Config



346
347
348
# File 'lib/gapic/schema/wrappers.rb', line 346

def full_name
  @address.join "."
end

#hostString

Returns The hostname for this service (e.g. "foo.googleapis.com"). This should be specified with no prefix.

Returns:

  • (String)

    The hostname for this service (e.g. "foo.googleapis.com"). This should be specified with no prefix.



305
306
307
# File 'lib/gapic/schema/wrappers.rb', line 305

def host
  option_named "google.api.default_host"
end

#is_deprecated?Boolean

Returns True if this service is marked as deprecated, false otherwise.

Returns:

  • (Boolean)

    True if this service is marked as deprecated, false otherwise.



328
329
330
# File 'lib/gapic/schema/wrappers.rb', line 328

def is_deprecated?
  option_named "deprecated"
end

#nameString

Returns the unqualified name of the service.

Returns:

  • (String)

    the unqualified name of the service.



355
356
357
358
359
# File 'lib/gapic/schema/wrappers.rb', line 355

def_delegators(
  :descriptor,
  :name,
  :options
)

#option_extension_namesObject

Return a configuration of supported option extensions.



298
299
300
# File 'lib/gapic/schema/wrappers.rb', line 298

def option_extension_names
  OPTION_EXTENSION_NAMES
end

#optionsGoogle::Protobuf::ServiceOptions

Returns the options of this service.

Returns:

  • (Google::Protobuf::ServiceOptions)

    the options of this service.



355
356
357
358
359
# File 'lib/gapic/schema/wrappers.rb', line 355

def_delegators(
  :descriptor,
  :name,
  :options
)

#resourcesArray<Google::Api::ResourceDescriptor>

Returns A representation of the resource. This is generally intended to be attached to the "name" field. See google/api/resource.proto.

Returns:

  • (Array<Google::Api::ResourceDescriptor>)

    A representation of the resource. This is generally intended to be attached to the "name" field. See google/api/resource.proto.



335
336
337
338
339
# File 'lib/gapic/schema/wrappers.rb', line 335

def resources
  require "gapic/resource_lookup"

  @resources ||= Gapic::ResourceLookup.for_service self
end

#ruby_packageString

Returns Ruby Package.

Returns:

  • (String)

    Ruby Package



320
321
322
323
324
# File 'lib/gapic/schema/wrappers.rb', line 320

def ruby_package
  return nil if parent.nil?

  parent.ruby_package
end

#scopesArray<String>

Returns The OAuth scopes information for the client.

Returns:

  • (Array<String>)

    The OAuth scopes information for the client.



310
311
312
# File 'lib/gapic/schema/wrappers.rb', line 310

def scopes
  String(option_named("google.api.oauth_scopes")).split ","
end