blob: 0b6bac91e263897ba59ae780c08972155763355b [file] [edit]
// Copyright 2018 Google LLC
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
// This is a generated file (see the discoveryapis_generator project).
// ignore_for_file: camel_case_types
// ignore_for_file: comment_references
// ignore_for_file: deprecated_member_use_from_same_package
// ignore_for_file: doc_directive_unknown
// ignore_for_file: lines_longer_than_80_chars
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: prefer_interpolation_to_compose_strings
// ignore_for_file: unintended_html_in_doc_comment
// ignore_for_file: unnecessary_brace_in_string_interps
// ignore_for_file: unnecessary_lambdas
// ignore_for_file: unnecessary_string_interpolations
/// Web Search Indexing API - v3
///
/// Notifies Google Web Search when your web pages change.
///
/// For more information, see
/// <https://developers.google.com/search/apis/indexing-api/>
///
/// Create an instance of [IndexingApi] to access these resources:
///
/// - [UrlNotificationsResource]
library;
import 'dart:async' as async;
import 'dart:convert' as convert;
import 'dart:core' as core;
import 'package:_discoveryapis_commons/_discoveryapis_commons.dart' as commons;
import 'package:http/http.dart' as http;
import '../src/user_agent.dart';
export 'package:_discoveryapis_commons/_discoveryapis_commons.dart'
show ApiRequestError, DetailedApiRequestError;
/// Notifies Google Web Search when your web pages change.
class IndexingApi {
/// Submit data to Google for indexing
static const indexingScope = 'https://www.googleapis.com/auth/indexing';
final commons.ApiRequester _requester;
UrlNotificationsResource get urlNotifications =>
UrlNotificationsResource(_requester);
IndexingApi(
http.Client client, {
core.String rootUrl = 'https://indexing.googleapis.com/',
core.String servicePath = '',
}) : _requester = commons.ApiRequester(
client,
rootUrl,
servicePath,
requestHeaders,
);
}
class UrlNotificationsResource {
final commons.ApiRequester _requester;
UrlNotificationsResource(commons.ApiRequester client) : _requester = client;
/// Gets metadata about a Web Document.
///
/// This method can _only_ be used to query URLs that were previously seen in
/// successful Indexing API notifications. Includes the latest
/// `UrlNotification` received via this API.
///
/// Request parameters:
///
/// [url] - URL that is being queried.
///
/// [$fields] - Selector specifying which fields to include in a partial
/// response.
///
/// Completes with a [UrlNotificationMetadata].
///
/// 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.
async.Future<UrlNotificationMetadata> getMetadata({
core.String? url,
core.String? $fields,
}) async {
final queryParams_ = <core.String, core.List<core.String>>{
'url': ?url == null ? null : [url],
'fields': ?$fields == null ? null : [$fields],
};
const url_ = 'v3/urlNotifications/metadata';
final response_ = await _requester.request(
url_,
'GET',
queryParams: queryParams_,
);
return UrlNotificationMetadata.fromJson(
response_ as core.Map<core.String, core.dynamic>,
);
}
/// Notifies that a URL has been updated or deleted.
///
/// [request] - The metadata request object.
///
/// Request parameters:
///
/// [$fields] - Selector specifying which fields to include in a partial
/// response.
///
/// Completes with a [PublishUrlNotificationResponse].
///
/// 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.
async.Future<PublishUrlNotificationResponse> publish(
UrlNotification request, {
core.String? $fields,
}) async {
final body_ = convert.json.encode(request);
final queryParams_ = <core.String, core.List<core.String>>{
'fields': ?$fields == null ? null : [$fields],
};
const url_ = 'v3/urlNotifications:publish';
final response_ = await _requester.request(
url_,
'POST',
body: body_,
queryParams: queryParams_,
);
return PublishUrlNotificationResponse.fromJson(
response_ as core.Map<core.String, core.dynamic>,
);
}
}
/// Output for PublishUrlNotification
class PublishUrlNotificationResponse {
/// Description of the notification events received for this URL.
UrlNotificationMetadata? urlNotificationMetadata;
PublishUrlNotificationResponse({this.urlNotificationMetadata});
PublishUrlNotificationResponse.fromJson(core.Map json_)
: this(
urlNotificationMetadata: json_.containsKey('urlNotificationMetadata')
? UrlNotificationMetadata.fromJson(
json_['urlNotificationMetadata']
as core.Map<core.String, core.dynamic>,
)
: null,
);
core.Map<core.String, core.dynamic> toJson() {
final urlNotificationMetadata = this.urlNotificationMetadata;
return {'urlNotificationMetadata': ?urlNotificationMetadata};
}
}
/// `UrlNotification` is the resource used in all Indexing API calls.
///
/// It describes one event in the life cycle of a Web Document.
class UrlNotification {
/// Creation timestamp for this notification.
///
/// Users should _not_ specify it, the field is ignored at the request time.
core.String? notifyTime;
/// The URL life cycle event that Google is being notified about.
/// Possible string values are:
/// - "URL_NOTIFICATION_TYPE_UNSPECIFIED" : Unspecified.
/// - "URL_UPDATED" : The given URL (Web document) has been updated.
/// - "URL_DELETED" : The given URL (Web document) has been deleted.
core.String? type;
/// The object of this notification.
///
/// The URL must be owned by the publisher of this notification and, in case
/// of `URL_UPDATED` notifications, it _must_ be crawlable by Google.
core.String? url;
UrlNotification({this.notifyTime, this.type, this.url});
UrlNotification.fromJson(core.Map json_)
: this(
notifyTime: json_['notifyTime'] as core.String?,
type: json_['type'] as core.String?,
url: json_['url'] as core.String?,
);
core.Map<core.String, core.dynamic> toJson() {
final notifyTime = this.notifyTime;
final type = this.type;
final url = this.url;
return {'notifyTime': ?notifyTime, 'type': ?type, 'url': ?url};
}
}
/// Summary of the most recent Indexing API notifications successfully received,
/// for a given URL.
class UrlNotificationMetadata {
/// Latest notification received with type `URL_REMOVED`.
UrlNotification? latestRemove;
/// Latest notification received with type `URL_UPDATED`.
UrlNotification? latestUpdate;
/// URL to which this metadata refers.
core.String? url;
UrlNotificationMetadata({this.latestRemove, this.latestUpdate, this.url});
UrlNotificationMetadata.fromJson(core.Map json_)
: this(
latestRemove: json_.containsKey('latestRemove')
? UrlNotification.fromJson(
json_['latestRemove'] as core.Map<core.String, core.dynamic>,
)
: null,
latestUpdate: json_.containsKey('latestUpdate')
? UrlNotification.fromJson(
json_['latestUpdate'] as core.Map<core.String, core.dynamic>,
)
: null,
url: json_['url'] as core.String?,
);
core.Map<core.String, core.dynamic> toJson() {
final latestRemove = this.latestRemove;
final latestUpdate = this.latestUpdate;
final url = this.url;
return {
'latestRemove': ?latestRemove,
'latestUpdate': ?latestUpdate,
'url': ?url,
};
}
}