create method

Future<Subscription> create(
  1. Subscription request,
  2. String parent, {
  3. bool? skipBacklog,
  4. String? subscriptionId,
  5. String? $fields,
})

Creates a new subscription.

request - The metadata request object.

Request parameters:

parent - Required. The parent location in which to create the subscription. Structured like projects/{project_number}/locations/{location}. Value must have pattern ^projects/\[^/\]+/locations/\[^/\]+$.

skipBacklog - If true, the newly created subscription will only receive messages published after the subscription was created. Otherwise, the entire message backlog will be received on the subscription. Defaults to false.

subscriptionId - Required. The ID to use for the subscription, which will become the final component of the subscription's name. This value is structured like: my-sub-name.

$fields - Selector specifying which fields to include in a partial response.

Completes with a Subscription.

Completes with a commons.ApiRequestError if the API endpoint returned an error.

If the used http.Client completes with an error when making a REST call, this method will complete with the same error.

Implementation

async.Future<Subscription> create(
  Subscription request,
  core.String parent, {
  core.bool? skipBacklog,
  core.String? subscriptionId,
  core.String? $fields,
}) async {
  final body_ = convert.json.encode(request);
  final queryParams_ = <core.String, core.List<core.String>>{
    if (skipBacklog != null) 'skipBacklog': ['${skipBacklog}'],
    if (subscriptionId != null) 'subscriptionId': [subscriptionId],
    if ($fields != null) 'fields': [$fields],
  };

  final url_ =
      'v1/admin/' + core.Uri.encodeFull('$parent') + '/subscriptions';

  final response_ = await _requester.request(
    url_,
    'POST',
    body: body_,
    queryParams: queryParams_,
  );
  return Subscription.fromJson(
      response_ as core.Map<core.String, core.dynamic>);
}