createSubscriber method

Future<Response<CreateSubscriberSuccessResponse>> createSubscriber({
  1. required String firstName,
  2. String? lastName,
  3. String? email,
  4. CancelToken? cancelToken,
  5. Map<String, dynamic>? headers,
  6. Map<String, dynamic>? extra,
  7. ValidateStatus? validateStatus,
  8. ProgressCallback? onSendProgress,
  9. ProgressCallback? onReceiveProgress,
})

Create Subscriber Create subscriber.

Parameters:

  • firstName - Subscriber's first name.
  • lastName - Subscriber's last name.
  • email - The email address of the subscriber.
  • cancelToken - A CancelToken that can be used to cancel the operation
  • headers - Can be used to add additional headers to the request
  • extras - Can be used to add flags to the request
  • validateStatus - A ValidateStatus callback that can be used to determine request success based on the HTTP status of the response
  • onSendProgress - A ProgressCallback that can be used to get the send progress
  • onReceiveProgress - A ProgressCallback that can be used to get the receive progress

Returns a Future containing a Response with a CreateSubscriberSuccessResponse as data Throws DioException if API call or serialization fails

Implementation

Future<Response<CreateSubscriberSuccessResponse>> createSubscriber({
  required String firstName,
  String? lastName,
  String? email,
  CancelToken? cancelToken,
  Map<String, dynamic>? headers,
  Map<String, dynamic>? extra,
  ValidateStatus? validateStatus,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
}) async {
  const path = r'/api/v1/subscribers';
  final options = Options(
    method: r'POST',
    headers: <String, dynamic>{...?headers},
    extra: <String, dynamic>{
      'secure': <Map<String, String>>[
        {'type': 'http', 'scheme': 'bearer', 'name': 'kindeBearerAuth'},
      ],
      ...?extra,
    },
    validateStatus: validateStatus,
  );

  final queryParameters = <String, dynamic>{
    r'first_name': encodeQueryParameter(
      _serializers,
      firstName,
      const FullType(String),
    ),
    r'last_name': encodeQueryParameter(
      _serializers,
      lastName,
      const FullType(String),
    ),
    r'email': encodeQueryParameter(
      _serializers,
      email,
      const FullType(String),
    ),
  };

  final response = await _dio.request<Object>(
    path,
    options: options,
    queryParameters: queryParameters,
    cancelToken: cancelToken,
    onSendProgress: onSendProgress,
    onReceiveProgress: onReceiveProgress,
  );

  CreateSubscriberSuccessResponse? responseData;

  try {
    final rawResponse = response.data;
    responseData =
        rawResponse == null
            ? null
            : _serializers.deserialize(
                  rawResponse,
                  specifiedType: const FullType(
                    CreateSubscriberSuccessResponse,
                  ),
                )
                as CreateSubscriberSuccessResponse;
  } catch (error, stackTrace) {
    throw DioException(
      requestOptions: response.requestOptions,
      response: response,
      type: DioExceptionType.unknown,
      error: error,
      stackTrace: stackTrace,
    );
  }

  return Response<CreateSubscriberSuccessResponse>(
    data: responseData,
    headers: response.headers,
    isRedirect: response.isRedirect,
    requestOptions: response.requestOptions,
    redirects: response.redirects,
    statusCode: response.statusCode,
    statusMessage: response.statusMessage,
    extra: response.extra,
  );
}