Search in sources :

Example 6 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.

the class UserService method getUserListBySearch.

/**
 * Will return and sync a list of contacts matching the search term, from the server.
 *
 * <p>Note: The local contacts are also updated locally.</p>
 *
 * <p>Note: This method has database and network operation. Run it asynchronously.</p>
 *
 * @param searchString the search term
 * @return a list of users (as Contact objects)
 * @throws ApplozicException when the backend returns an error response
 */
@Nullable
public List<Contact> getUserListBySearch(@Nullable String searchString) throws ApplozicException {
    try {
        ApiResponse response = userClientService.getUsersBySearchString(searchString);
        if (response == null) {
            return null;
        }
        if (response.isSuccess()) {
            UserDetail[] userDetails = (UserDetail[]) GsonUtils.getObjectFromJson(GsonUtils.getJsonFromObject(response.getResponse(), List.class), UserDetail[].class);
            List<Contact> contactList = new ArrayList<>();
            for (UserDetail userDetail : userDetails) {
                contactList.add(getContactFromUserDetail(userDetail));
            }
            return contactList;
        } else {
            if (response.getErrorResponse() != null && !response.getErrorResponse().isEmpty()) {
                throw new ApplozicException(GsonUtils.getJsonFromObject(response.getErrorResponse(), List.class));
            }
        }
    } catch (Exception e) {
        throw new ApplozicException(e.getMessage());
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RegisteredUsersApiResponse(com.applozic.mobicomkit.feed.RegisteredUsersApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) Contact(com.applozic.mobicommons.people.contact.Contact) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) Nullable(androidx.annotation.Nullable)

Example 7 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.

the class UserServiceTest method processUserBlockSuccess.

@Test
public void processUserBlockSuccess() {
    ApiResponse expectedFailureApiResponse = new ApiResponse();
    expectedFailureApiResponse.setStatus("success");
    Mockito.when(userClientService.userBlock(testUserId, true)).thenReturn(expectedFailureApiResponse);
    ApiResponse actualSuccessApiResponse = userService.processUserBlock(testUserId, true);
    Truth.assertThat(actualSuccessApiResponse).isNotNull();
    // in applozic as of the date this test is written, only the status of the ApiResponse is used
    Truth.assertThat(actualSuccessApiResponse.getStatus()).isEqualTo("success");
    Mockito.verify(appContactService, Mockito.times(1)).updateUserBlocked(ArgumentMatchers.anyString(), ArgumentMatchers.anyBoolean());
}
Also used : MockedConstants.userDetailsApiResponse(com.applozic.mobicomkit.MockedConstants.userDetailsApiResponse) RegisteredUsersApiResponse(com.applozic.mobicomkit.feed.RegisteredUsersApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) Test(org.junit.Test)

Example 8 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.

the class UserServiceTest method updateUserDisplayNameFailureNull.

@Test
public void updateUserDisplayNameFailureNull() {
    // Note: return value from userService.updateUserDisplayName() is not used
    ApiResponse apiResponse = new ApiResponse();
    apiResponse.setStatus("anything but success");
    Mockito.when(userClientService.updateUserDisplayName(ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(apiResponse);
    ApiResponse actualApiResponse = userService.updateUserDisplayName(testUserId, "Display Name");
    Mockito.verify(appContactService, Mockito.never()).updateMetadataKeyValueForUserId(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString());
    Truth.assertThat(actualApiResponse).isEqualTo(apiResponse);
}
Also used : MockedConstants.userDetailsApiResponse(com.applozic.mobicomkit.MockedConstants.userDetailsApiResponse) RegisteredUsersApiResponse(com.applozic.mobicomkit.feed.RegisteredUsersApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) Test(org.junit.Test)

Example 9 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.

the class UserServiceTest method muteUserNotifications.

@Test
public void muteUserNotifications() {
    ApiResponse expectedApiResponse = new ApiResponse();
    expectedApiResponse.setStatus("success");
    Mockito.when(userClientService.muteUserNotifications(ArgumentMatchers.anyString(), ArgumentMatchers.anyLong())).thenReturn(expectedApiResponse);
    ApiResponse apiResponse = userService.muteUserNotifications(ArgumentMatchers.anyString(), ArgumentMatchers.anyLong());
    Truth.assertThat(apiResponse).isEqualTo(expectedApiResponse);
    Truth.assertThat(apiResponse.isSuccess()).isTrue();
}
Also used : MockedConstants.userDetailsApiResponse(com.applozic.mobicomkit.MockedConstants.userDetailsApiResponse) RegisteredUsersApiResponse(com.applozic.mobicomkit.feed.RegisteredUsersApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) Test(org.junit.Test)

Example 10 with ApiResponse

use of com.applozic.mobicomkit.feed.ApiResponse in project Applozic-Android-SDK by AppLozic.

the class UserServiceTest method updateUserWithResponse.

@Test
public void updateUserWithResponse() {
    ApiResponse expectedApiResponse = new ApiResponse();
    expectedApiResponse.setStatus("success");
    Mockito.when(userClientService.updateDisplayNameORImageLink("displayName", "profileImageLink", "status", "contactNumber", "emailId", null, "userId")).thenReturn(expectedApiResponse);
    Mockito.when(appContactService.getContactById(ArgumentMatchers.anyString())).thenReturn(new Contact());
    ApiResponse apiResponse = userService.updateUserWithResponse("displayName", "profileImageLink", "localURL", "status", "contactNumber", "emailId", null, "userId");
    Truth.assertThat(apiResponse).isEqualTo(expectedApiResponse);
    Mockito.verify(appContactService, Mockito.times(1)).upsert(ArgumentMatchers.any(Contact.class));
}
Also used : MockedConstants.userDetailsApiResponse(com.applozic.mobicomkit.MockedConstants.userDetailsApiResponse) RegisteredUsersApiResponse(com.applozic.mobicomkit.feed.RegisteredUsersApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) Contact(com.applozic.mobicommons.people.contact.Contact) Test(org.junit.Test)

Aggregations

ApiResponse (com.applozic.mobicomkit.feed.ApiResponse)54 SyncBlockUserApiResponse (com.applozic.mobicomkit.feed.SyncBlockUserApiResponse)23 ChannelFeedApiResponse (com.applozic.mobicomkit.feed.ChannelFeedApiResponse)22 JSONException (org.json.JSONException)19 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)16 RegisteredUsersApiResponse (com.applozic.mobicomkit.feed.RegisteredUsersApiResponse)16 Test (org.junit.Test)14 MultipleChannelFeedApiResponse (com.applozic.mobicomkit.MultipleChannelFeedApiResponse)12 MockedConstants.userDetailsApiResponse (com.applozic.mobicomkit.MockedConstants.userDetailsApiResponse)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 Nullable (androidx.annotation.Nullable)8 Contact (com.applozic.mobicommons.people.contact.Contact)8 ChannelUserMapper (com.applozic.mobicommons.people.channel.ChannelUserMapper)3 ArrayList (java.util.ArrayList)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 ProgressDialog (android.app.ProgressDialog)2 Toast (android.widget.Toast)2 UserBlockTask (com.applozic.mobicomkit.api.account.user.UserBlockTask)2 MuteNotificationAsync (com.applozic.mobicomkit.api.notification.MuteNotificationAsync)2 MuteNotificationRequest (com.applozic.mobicomkit.api.notification.MuteNotificationRequest)2