Search in sources :

Example 1 with ApiResponse

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

the class UserClientService method userLogoutResponse.

// Cleanup: rename to something more suitable for a public api
/**
 * Simply sends a logout server call for the logged user.
 *
 * <p>Note: This is a network method. Run it asynchronously.</p>
 *
 * @return logout backend api response. use {@link ApiResponse#isSuccess()} to check for success
 */
public ApiResponse userLogoutResponse() {
    String response = "";
    ApiResponse apiResponse = null;
    try {
        response = httpRequestUtils.postData(getUserLogout(), "application/json", "application/json", null);
        if (!TextUtils.isEmpty(response)) {
            apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return apiResponse;
}
Also used : ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) JSONException(org.json.JSONException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with ApiResponse

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

the class UserClientService method getUserReadServerCall.

// Cleanup: default
/**
 * @deprecated This method is not longer used and will be removed soon.
 */
@Deprecated
public ApiResponse getUserReadServerCall() {
    String response = null;
    ApiResponse apiResponse = null;
    try {
        response = httpRequestUtils.getResponse(getUserReadUrl(), null, null);
        if (response != null) {
            apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
        }
        Utils.printLog(context, TAG, "User read response: " + response);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return apiResponse;
}
Also used : ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) JSONException(org.json.JSONException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with ApiResponse

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

the class UserClientService method userBlock.

/**
 * Sends a server request to block/unblock the given userId for the current(logged) user.
 *
 * <p>You do not need to pass the current user's user-id, it is taken from the local shared preferences({@link MobiComUserPreference}).</p>
 *
 * <p>Note: This is a network method. Run it asynchronously.</p>
 *
 * @param userId the userId of the user to block/unblock
 * @param block true for block/false for unblock
 * @return api response from the server, use {@link ApiResponse#isSuccess()} to check for success
 */
@Nullable
public ApiResponse userBlock(@Nullable String userId, boolean block) {
    String response = "";
    ApiResponse apiResponse = null;
    try {
        if (!TextUtils.isEmpty(userId)) {
            response = httpRequestUtils.getResponse((block ? getBlockUserUrl() : getUnBlockUserSyncUrl()) + "?userId=" + URLEncoder.encode(userId, "UTF-8"), "application/json", "application/json");
            apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return apiResponse;
}
Also used : ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) JSONException(org.json.JSONException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Nullable(androidx.annotation.Nullable)

Example 4 with ApiResponse

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

the class UserClientService method updateUserPassword.

// Cleanup: default
/**
 * @deprecated This method is not longer used and will be removed soon.
 */
@Deprecated
public String updateUserPassword(String oldPassword, String newPassword) {
    if (TextUtils.isEmpty(oldPassword) || TextUtils.isEmpty(newPassword)) {
        return null;
    }
    String response = "";
    ApiResponse apiResponse = null;
    try {
        response = httpRequestUtils.getResponse(getUpdateUserPasswordUrl() + "?oldPassword=" + oldPassword + "&newPassword=" + newPassword, "application/json", "application/json");
        if (TextUtils.isEmpty(response)) {
            return null;
        }
        apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
        if (apiResponse != null && apiResponse.isSuccess()) {
            return apiResponse.getStatus();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) SyncBlockUserApiResponse(com.applozic.mobicomkit.feed.SyncBlockUserApiResponse) JSONException(org.json.JSONException) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with ApiResponse

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

the class UserService method updateDisplayNameORImageLink.

// internal methods >>>
/**
 * Internal. Do not use.
 */
// Cleanup: private
public String updateDisplayNameORImageLink(String displayName, String profileImageLink, String localURL, String status, String contactNumber, String emailId, Map<String, String> metadata, String userId) {
    ApiResponse response = userClientService.updateDisplayNameORImageLink(displayName, profileImageLink, status, contactNumber, emailId, metadata, userId);
    if (response == null) {
        return null;
    }
    if (response.isSuccess()) {
        Contact contact = baseContactService.getContactById(!TextUtils.isEmpty(userId) ? userId : MobiComUserPreference.getInstance(context).getUserId());
        if (!TextUtils.isEmpty(displayName)) {
            contact.setFullName(displayName);
        }
        if (!TextUtils.isEmpty(profileImageLink)) {
            contact.setImageURL(profileImageLink);
        }
        contact.setLocalImageUrl(localURL);
        if (!TextUtils.isEmpty(status)) {
            contact.setStatus(status);
        }
        if (!TextUtils.isEmpty(contactNumber)) {
            contact.setContactNumber(contactNumber);
        }
        if (!TextUtils.isEmpty(emailId)) {
            contact.setEmailId(emailId);
        }
        if (metadata != null && !metadata.isEmpty()) {
            Map<String, String> existingMetadata = contact.getMetadata();
            if (existingMetadata == null) {
                existingMetadata = new HashMap<>();
            }
            existingMetadata.putAll(metadata);
            contact.setMetadata(existingMetadata);
        }
        baseContactService.upsert(contact);
        Contact contact1 = baseContactService.getContactById(!TextUtils.isEmpty(userId) ? userId : MobiComUserPreference.getInstance(context).getUserId());
        Utils.printLog(context, TAG, contact1.getImageURL() + ", " + contact1.getDisplayName() + "," + contact1.getStatus() + "," + contact1.getStatus() + "," + contact1.getMetadata() + "," + contact1.getEmailId() + "," + contact1.getContactNumber());
    }
    return response.getStatus();
}
Also used : 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)

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