Search in sources :

Example 46 with ApiResponse

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

the class ChannelClientService method addMemberToContactGroup.

/**
 * Sends a request to add a user/s to a contact group with the given id.
 *
 * <p>Contacts for a user can be grouped together. Such a group is called a contact group.</p>
 *
 * @param contactGroupId the id of the contact
 * @param contactGroupMemberList list of userIds of contacts to add in group
 * @return the {@link ApiResponse} for the request
 */
public ApiResponse addMemberToContactGroup(String contactGroupId, List<String> contactGroupMemberList) {
    String response;
    if (!TextUtils.isEmpty(contactGroupId) && contactGroupMemberList != null) {
        String url = String.format(addMembersToContactGroupUrl(), contactGroupId);
        Utils.printLog(context, TAG, url);
        String jsonFromObject = GsonUtils.getJsonFromObject(contactGroupMemberList, List.class);
        Utils.printLog(context, TAG, "Sending json:" + jsonFromObject);
        try {
            response = httpRequestUtils.postData(url, "application/json", "application/json", jsonFromObject);
            ApiResponse apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
            if (apiResponse != null) {
                Utils.printLog(context, TAG, "Add Member To Contact Group Response: " + apiResponse.getStatus());
                return apiResponse;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : MultipleChannelFeedApiResponse(com.applozic.mobicomkit.MultipleChannelFeedApiResponse) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) JSONException(org.json.JSONException)

Example 47 with ApiResponse

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

the class ChannelClientService method leaveMemberFromChannel.

// Cleanup: private
public synchronized ApiResponse leaveMemberFromChannel(String clientGroupId, Integer channelKey) {
    ApiResponse apiResponse = null;
    try {
        String parameters = "";
        if (!TextUtils.isEmpty(clientGroupId)) {
            parameters = CLIENT_GROUPID + "=" + URLEncoder.encode(clientGroupId, "UTF-8");
        } else {
            parameters = GROUP_ID + "=" + channelKey;
        }
        if (!TextUtils.isEmpty(clientGroupId) || (channelKey != null && channelKey != 0)) {
            String url = getChannelLeftUrl() + "?" + parameters;
            String response = httpRequestUtils.getResponse(url, "application/json", "application/json");
            apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
            if (apiResponse != null) {
                Utils.printLog(context, TAG, "Channel leave member call response: " + apiResponse.getStatus());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return apiResponse;
}
Also used : MultipleChannelFeedApiResponse(com.applozic.mobicomkit.MultipleChannelFeedApiResponse) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) JSONException(org.json.JSONException)

Example 48 with ApiResponse

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

the class ChannelClientService method updateChannel.

/**
 * Sends a request to the server to update channel details.
 *
 * <p>See {@link GroupInfoUpdate} for details on parameters.</p>
 *
 * @param groupInfoUpdate the object used to store data to update
 * @return the {@link ApiResponse} for the request
 */
@Nullable
public synchronized ApiResponse updateChannel(@Nullable GroupInfoUpdate groupInfoUpdate) {
    ApiResponse apiResponse = null;
    try {
        if (groupInfoUpdate != null) {
            String channelNameUpdateJson = GsonUtils.getJsonFromObject(groupInfoUpdate, GroupInfoUpdate.class);
            String response = httpRequestUtils.postData(getChannelUpdateUrl(), "application/json", "application/json", channelNameUpdateJson);
            apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
            if (apiResponse != null) {
                Utils.printLog(context, TAG, "Update Channel response: " + apiResponse.getStatus());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return apiResponse;
}
Also used : MultipleChannelFeedApiResponse(com.applozic.mobicomkit.MultipleChannelFeedApiResponse) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) JSONException(org.json.JSONException) Nullable(androidx.annotation.Nullable)

Example 49 with ApiResponse

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

the class ChannelClientService method removeMembersFromMultipleChannels.

private ApiResponse removeMembersFromMultipleChannels(Set<String> clientGroupIds, Set<Integer> channelKeys, Set<String> userIds) {
    ApiResponse apiResponse = null;
    try {
        if (userIds != null && userIds.size() > 0) {
            String parameters = "";
            if (clientGroupIds != null && clientGroupIds.size() > 0) {
                for (String clientGroupId : clientGroupIds) {
                    parameters += CLIENT_GROUPIDs + "=" + URLEncoder.encode(clientGroupId, "UTF-8") + "&";
                }
            } else if (channelKeys != null && channelKeys.size() > 0) {
                for (Integer channelKey : channelKeys) {
                    parameters += GROUPIDS + "=" + channelKey + "&";
                }
            }
            for (String userId : userIds) {
                parameters += USER_ID + "=" + URLEncoder.encode(userId, "UTF-8") + "&";
            }
            String url = getRemoveMembersFromMultipChannels() + "?" + parameters;
            String response = httpRequestUtils.getResponse(url, "application/json", "application/json");
            apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
            if (apiResponse != null) {
                Utils.printLog(context, TAG, "Channel remove members from channels response: " + "" + apiResponse.getStatus());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return apiResponse;
}
Also used : MultipleChannelFeedApiResponse(com.applozic.mobicomkit.MultipleChannelFeedApiResponse) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) JSONException(org.json.JSONException)

Example 50 with ApiResponse

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

the class ChannelClientService method addMemberToChannel.

// Cleanup: private
public synchronized ApiResponse addMemberToChannel(@Nullable String clientGroupId, @Nullable Integer channelKey, @Nullable String userId) {
    try {
        String parameters = "";
        if (!TextUtils.isEmpty(clientGroupId)) {
            parameters = CLIENT_GROUPID + "=" + URLEncoder.encode(clientGroupId, "UTF-8");
        } else {
            parameters = GROUP_ID + "=" + channelKey;
        }
        if (!TextUtils.isEmpty(parameters) && !TextUtils.isEmpty(userId)) {
            String url = getAddMemberToGroup() + "?" + parameters + "&" + USER_ID + "=" + URLEncoder.encode(userId, "UTF-8");
            String response = httpRequestUtils.getResponse(url, "application/json", "application/json");
            ApiResponse apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
            if (apiResponse != null) {
                Utils.printLog(context, TAG, "Channel add member call response: " + apiResponse.getStatus());
            }
            return apiResponse;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : MultipleChannelFeedApiResponse(com.applozic.mobicomkit.MultipleChannelFeedApiResponse) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) JSONException(org.json.JSONException)

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