Class: Gapic::Presenters::ServiceRestPresenter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Helpers::FilepathHelper, Helpers::NamespaceHelper
Defined in:
lib/gapic/presenters/service_rest_presenter.rb

Overview

A presenter for proto service (REST submethods)

Instance Method Summary collapse

Methods included from Helpers::NamespaceHelper

#ensure_absolute_namespace, #fix_namespace, #ruby_namespace, #ruby_namespace_for_address

Methods included from Helpers::FilepathHelper

#fix_file_path, #ruby_file_path, #ruby_file_path_for_namespace

Constructor Details

#initialize(main_service, api) ⇒ ServiceRestPresenter

Returns a new instance of ServiceRestPresenter.

Parameters:



47
48
49
50
51
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 47

def initialize main_service, api
  @main_service = main_service
  @api = api
  @type = "service"
end

Instance Method Details

#api_versionString

Returns The api_version for this service, or empty if not defined.

Returns:

  • (String)

    The api_version for this service, or empty if not defined.



385
386
387
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 385

def api_version
  @main_service.api_version.to_s
end

#client_file_pathString

Returns:

  • (String)


126
127
128
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 126

def client_file_path
  "#{client_require}.rb"
end

#client_name_fullString

Returns:

  • (String)


112
113
114
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 112

def client_name_full
  fix_namespace api, "#{service_name_full}::#{client_name}"
end

#client_requireString

Returns:

  • (String)


119
120
121
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 119

def client_require
  ruby_file_path api, client_name_full
end

#configure_client_callString

Returns:

  • (String)


161
162
163
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 161

def configure_client_call
  "#{client_name_full}.configure"
end

#create_client_callString

Returns:

  • (String)


133
134
135
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 133

def create_client_call
  "#{client_name_full}.new"
end

#helpers_requireString

Require string for the helpers file

Returns:

  • (String)


365
366
367
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 365

def helpers_require
  ruby_file_path @api, "#{service_name_full}::Helpers"
end

#is_deprecated?Boolean

Returns Whether the service is marked as deprecated.

Returns:

  • (Boolean)

    Whether the service is marked as deprecated.



380
381
382
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 380

def is_deprecated?
  @main_service.is_deprecated?
end

#lro?Boolean

Whether an AIP-151 LRO subclient needs to be generated for this service

Returns:

  • (Boolean)


228
229
230
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 228

def lro?
  methods.find(&:lro?)
end

#lro_client_presenterGapic::Presenters::Service::LroClientPresenter?

A presenter for the LRO subclient if needed

Returns:

  • (Gapic::Presenters::Service::LroClientPresenter, nil)


214
215
216
217
218
219
220
221
222
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 214

def lro_client_presenter
  return nil unless lro?
  Gapic::Presenters::Service::LroClientPresenter.new service: "google.longrunning.operations",
                                                     client_class_name: "Operations",
                                                     client_class_docname: operations_name_full,
                                                     client_var_name: lro_client_var,
                                                     require_str: operations_file_path,
                                                     service_description: "long-running operations"
end

#lro_subclientsObject



334
335
336
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 334

def lro_subclients
  [lro_client_presenter, nonstandard_lros].flatten.compact
end

#methodsEnumerable<Gapic::Presenters::MethodPresenter>

Presenters for methods that can be generated in REST clients.

Returns:



356
357
358
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 356

def methods
  main_service.methods.select(&:can_generate_rest?)
end

#mixin_presentersEnumerable<Gapic::Presenters::Service::MixinClientPresenter>

The client presenters of the mixin services that are used by the methods of this service

Returns:

  • (Enumerable<Gapic::Presenters::Service::MixinClientPresenter>)


295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 295

def mixin_presenters
  return [] unless main_service.mixins?
  main_service.mixin_presenters.map do |grpc_presenter|
    model = main_service.mixin_models.find { |mdl| mdl.service == grpc_presenter.service }
    raise "Mismatch between model and presenters in service #{service_name_full}" unless model

    Gapic::Presenters::Service::MixinClientPresenter.new service: model.service,
                                                         client_class_name: model.client_class_name_rest,
                                                         client_class_docname: model.client_class_docname_rest,
                                                         client_var_name: model.client_var_name,
                                                         require_str: model.require_str_rest,
                                                         service_description: model.service_description,
                                                         bindings_override: grpc_presenter.bindings_override
  end
end

#mixin_should_generate_override_config?Boolean

Whether config for this service should include the bindings_override field. This field is needed:

  • if a service is a mixin in it's own package, e.g. google.Cloud.Location
  • if a service hosts a mixin and has bindings overrides for it but the generated Operations clients should not have it since override for their bindings are generated instead of set during runtime.

Returns:

  • (Boolean)


286
287
288
289
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 286

def mixin_should_generate_override_config?
  (is_main_mixin_service? || main_service.mixin_binding_overrides?) &&
    main_service.grpc_full_name != "google.longrunning.Operations"
end

#nonstandard_lro_file_nameString

File name of the nonstandard LRO module

Returns:

  • (String)


197
198
199
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 197

def nonstandard_lro_file_name
  nonstandard_lro_file_path.split("/").last
end

#nonstandard_lro_file_pathString

Full file path to the nonstandard LRO module

Returns:

  • (String)


188
189
190
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 188

def nonstandard_lro_file_path
  "#{nonstandard_lro_require}.rb"
end

#nonstandard_lro_nameString

Name of the nonstandard LRO module

Returns:

  • (String)


170
171
172
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 170

def nonstandard_lro_name
  "NonstandardLro"
end

#nonstandard_lro_name_fullString

Full name of the nonstandard LRO module

Returns:

  • (String)


179
180
181
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 179

def nonstandard_lro_name_full
  fix_namespace @api, "#{service_name_full}::#{nonstandard_lro_name}"
end

#nonstandard_lro_requireString

The require string for the nonstandard LRO module

Returns:

  • (String)


206
207
208
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 206

def nonstandard_lro_require
  ruby_file_path @api, "#{service_name_full}::#{nonstandard_lro_name}"
end

#nonstandard_lrosEnumerable<Gapic::Presenters::Service::LroClientPresenter>

The client presenters of the nonstandard LROs that are used by the methods of this service

Returns:

  • (Enumerable<Gapic::Presenters::Service::LroClientPresenter>)


260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 260

def nonstandard_lros
  return [] unless main_service.nonstandard_lro_consumer?
  main_service.nonstandard_lros_models.map do |lro|
    lro_wrapper = @api.lookup lro.service_full_name
    lro_service = ServicePresenter.new(main_service.gem, @api, lro_wrapper).rest

    service_description = "long-running operations via #{lro_service.name}"
    client_var_name = ruby_file_path_for_namespace lro_service.name
    Gapic::Presenters::Service::LroClientPresenter.new service: lro.service_full_name,
                                                       client_class_name: lro_service.client_name_full,
                                                       client_class_docname: lro_service.client_name_full,
                                                       client_var_name: client_var_name,
                                                       require_str: lro_service.service_require,
                                                       service_description: service_description,
                                                       helper_type: lro_service.nonstandard_lro_name_full
  end
end

#numeric_enums?Boolean

Whether this rest service should send the numeric enums signal

Returns:

  • (Boolean)


373
374
375
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 373

def numeric_enums?
  main_service.gem.rest_numeric_enums?
end

#operations_file_nameObject



244
245
246
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 244

def operations_file_name
  operations_file_path.split("/").last
end

#operations_file_pathObject



240
241
242
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 240

def operations_file_path
  "#{operations_require}.rb"
end

#operations_nameObject



232
233
234
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 232

def operations_name
  "Operations"
end

#operations_name_fullObject



236
237
238
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 236

def operations_name_full
  fix_namespace @api, "#{service_name_full}::#{operations_name}"
end

#operations_requireObject



248
249
250
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 248

def operations_require
  ruby_file_path @api, "#{service_name_full}::#{operations_name}"
end

#operations_stub_nameObject



252
253
254
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 252

def operations_stub_name
  "OperationsServiceStub"
end

#quick_start_methodGapic::Presenters::MethodRestPresenter?

The method to use for quick start samples. Normally this is simply the first non-client-streaming method defined, but it can be overridden via a gem config.

Returns:



347
348
349
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 347

def quick_start_method
  main_service.quick_start_method&.rest
end

#service_directory_nameString

Folder name for this service This is just "rest" for rest services

Returns:

  • (String)


77
78
79
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 77

def service_directory_name
  "rest"
end

#service_name_fullString

Full Ruby name of this service

Returns:

  • (String)


58
59
60
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 58

def service_name_full
  fix_namespace api, "#{main_service.service_name_full}::Rest"
end

#service_requireString

Require path for this service

Returns:

  • (String)


67
68
69
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 67

def service_require
  ruby_file_path @api, service_name_full
end

#service_rest_file_pathString

Returns:

  • (String)


147
148
149
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 147

def service_rest_file_path
  "#{service_rest_require}.rb"
end

#service_rest_requireString

Returns:

  • (String)


140
141
142
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 140

def service_rest_require
  ruby_file_path api, service_name_full
end

#service_stub_file_pathString

Returns:

  • (String)


105
106
107
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 105

def service_stub_file_path
  "#{service_stub_require}.rb"
end

#service_stub_nameString

Returns:

  • (String)


84
85
86
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 84

def service_stub_name
  "ServiceStub"
end

#service_stub_name_fullString

Returns:

  • (String)


91
92
93
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 91

def service_stub_name_full
  fix_namespace api, "#{service_name_full}::#{service_stub_name}"
end

#service_stub_requireString

Returns:

  • (String)


98
99
100
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 98

def service_stub_require
  ruby_file_path api, service_stub_name_full
end

#subclientsEnumerable<Gapic::Presenters::Service::LroClientPresenter, Gapic::Model::Mixins::Mixin>

Subclients for this service Subclients are the clients to other services (e.g. an LRO provider service).

The following is typically generated for a subclient:

  • a require statement for the subclient's class
  • a class-level variable in the host service's client
  • a code to initialize this variable with a subclient's class instance in the host service's constructor

Returns:



330
331
332
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 330

def subclients
  [lro_client_presenter, mixin_presenters, nonstandard_lros].flatten.compact
end

#subclients?Boolean

Whether there are any subclients to generate with this service. Subclients are the clients to other services (e.g. an LRO provider service).

Returns:

  • (Boolean)


316
317
318
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 316

def subclients?
  subclients.any?
end

#test_client_file_pathString

Returns:

  • (String)


154
155
156
# File 'lib/gapic/presenters/service_rest_presenter.rb', line 154

def test_client_file_path
  main_service.service_file_path.sub ".rb", "_rest_test.rb"
end