build method

  1. @override
WordpressRequest build(
  1. Uri baseUrl
)
override

Builds the request content.

This method is invoked when the request is ready to be send.

Request body, headers and other request properties are set on the returning instance.

Consider using addIfNotNull extension method to add a value to a map if it is not null.

Implementation

@override
WordpressRequest build(Uri baseUrl) {
  final queryParameters = <String, dynamic>{}
    ..addIfNotNull('context', context?.name)
    ..addIfNotNull('page', page)
    ..addIfNotNull('per_page', perPage)
    ..addIfNotNull('search', search)
    ..addIfNotNull('after', after?.toIso8601String())
    ..addIfNotNull('before', before?.toIso8601String())
    ..addIfNotNull('modified_before', modifiedBefore?.toIso8601String())
    ..addIfNotNull('modified_after', modifiedAfter?.toIso8601String())
    ..addIfNotNull('exclude', exclude?.join(','))
    ..addIfNotNull('include', include?.join(','))
    ..addIfNotNull('orderby', orderBy?.name)
    ..addIfNotNull('order', order?.name)
    ..addIfNotNull('author', author?.join(','))
    ..addIfNotNull('author_exclude', authorExclude?.join(','))
    ..addIfNotNull('offset', offset)
    ..addIfNotNull('parent', parent?.join(','))
    ..addIfNotNull('parent_exclude', parentExclude?.join(','))
    ..addIfNotNull('slug', slug?.join(','))
    ..addIfNotNull('status', status?.map((e) => e.name).join(','))
    ..addAllIfNotNull(extra)
    ..addAllIfNotNull(this.queryParameters);

  return WordpressRequest(
    queryParameters: queryParameters,
    headers: headers,
    method: HttpMethod.get,
    url: RequestUrl.relative('pages'),
    requireAuth: requireAuth || context == RequestContext.edit,
    cancelToken: cancelToken,
    authorization: authorization,
    events: events,
    receiveTimeout: receiveTimeout,
    sendTimeout: sendTimeout,
    validator: validator,
  );
}