createNewContact method

  1. @override
Future<RuutContact> createNewContact(
  1. String inboxIdentifier,
  2. RuutUser? user
)
override

Creates new contact for inbox with inboxIdentifier and passes user body to be linked to created contact

Implementation

@override
Future<RuutContact> createNewContact(
    String inboxIdentifier, RuutUser? user) async {
  try {
    final createResponse = await dio.post(
        "/public/api/v1/inboxes/$inboxIdentifier/contacts",
        data: user?.toJson());
    print('createNewContact: ${user?.toJson()}');
    if ((createResponse.statusCode ?? 0).isBetween(199, 300)) {
      //creating contact successful continue with request
      printFullText('createNewContact response: ${createResponse.data}');
      final contact = RuutContact.fromJson(createResponse.data);
      print('createNewContact contact: ${contact.toJson()}');
      return contact;
    } else {
      throw RuutClientException(
          createResponse.statusMessage ?? "unknown error",
          RuutClientExceptionType.CREATE_CONTACT_FAILED);
    }
  } on DioException catch (e) {
    throw RuutClientException(
        e.message ?? '', RuutClientExceptionType.CREATE_CONTACT_FAILED);
  }
}