Search in sources :

Example 16 with ApiResponse

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

the class ChannelClientService method addMemberToMultipleChannels.

// Cleanup: private
public synchronized ApiResponse addMemberToMultipleChannels(Set<String> clientGroupIds, Set<Integer> channelKeys, String userId) {
    ApiResponse apiResponse = null;
    try {
        if (!TextUtils.isEmpty(userId)) {
            String parameters = "";
            if (clientGroupIds != null && clientGroupIds.size() > 0) {
                for (String clientGroupId : clientGroupIds) {
                    parameters += CLIENT_GROUPIDs + "=" + URLEncoder.encode(clientGroupId, "UTF-8") + "&";
                }
            } else {
                for (Integer channelKey : channelKeys) {
                    parameters += GROUPIDS + "=" + channelKey + "&";
                }
            }
            String url = getAddMemberToMultipleChannelsUrl() + "?" + parameters + USER_ID + "=" + URLEncoder.encode(userId, "UTF-8");
            String response = httpRequestUtils.getResponse(url, "application/json", "application/json");
            apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
            if (apiResponse != null) {
                Utils.printLog(context, TAG, "Channel add 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 17 with ApiResponse

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

the class ChannelClientService method removeMemberFromContactGroupOfType.

/**
 * Sends a request to remove a user from a contact group with the given group type and group id.
 *
 * <p>Contacts for a user can be grouped together. Such a group is called a contact group.
 * Groups can have group types.</p>
 *
 * @param groupName the id of the contact group. apologies for the bad naming
 * @param groupType the group type
 * @param userId id of contact to remove
 * @return the {@link ApiResponse} for the request
 */
@Nullable
public ApiResponse removeMemberFromContactGroupOfType(@Nullable String groupName, @Nullable String groupType, @Nullable String userId) {
    String response;
    String parameters;
    String url;
    if (!TextUtils.isEmpty(groupName) && !TextUtils.isEmpty(userId)) {
        if (!TextUtils.isEmpty(groupType)) {
            parameters = "?" + USER_ID + "=" + userId + "&" + GROUPTYPE + "=" + groupType;
        } else {
            parameters = "?" + USER_ID + "=" + userId;
        }
        url = String.format(getRemoveMemberFromGroupTypeUrl() + parameters, groupName);
        try {
            response = httpRequestUtils.getResponse(url, "application/json", "application/json");
            ApiResponse apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
            if (apiResponse != null) {
                Utils.printLog(context, TAG, "Remove memeber from Group of Type 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) Nullable(androidx.annotation.Nullable)

Example 18 with ApiResponse

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

the class ChannelClientService method removeMemberFromChannel.

// Cleanup: private
public synchronized ApiResponse removeMemberFromChannel(String clientGroupId, Integer channelKey, String userId) {
    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(parameters) && !TextUtils.isEmpty(userId)) {
            String url = getRemoveMemberUrl() + "?" + parameters + "&" + USER_ID + "=" + URLEncoder.encode(userId, "UTF-8");
            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 member 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 19 with ApiResponse

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

the class ChannelClientService method addMemberToContactGroupOfType.

/**
 * Sends a request to add a user/s to a contact group with the given group type and given id.
 *
 * <p>Contacts for a user can be grouped together. Such a group is called a contact group.
 * Groups can have group types.</p>
 *
 * @param contactGroupId the id of the contact
 * @param groupType the group type
 * @param contactGroupMemberList list of userIds of contacts to add in group
 * @return the {@link ApiResponse} for the request
 */
@Nullable
public ApiResponse addMemberToContactGroupOfType(@Nullable String contactGroupId, @Nullable String groupType, @Nullable List<String> contactGroupMemberList) {
    String response;
    if (!TextUtils.isEmpty(contactGroupId) && !TextUtils.isEmpty(groupType) && contactGroupMemberList != null) {
        String url = String.format(addMembersToContactGroupOfTypeUrl(), contactGroupId);
        ApplozicAddMemberOfGroupType applozicAddMemberOfGroupType = new ApplozicAddMemberOfGroupType();
        applozicAddMemberOfGroupType.setGroupMemberList(contactGroupMemberList);
        applozicAddMemberOfGroupType.setType(groupType);
        String jsonFromObject = GsonUtils.getJsonFromObject(applozicAddMemberOfGroupType, ApplozicAddMemberOfGroupType.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) Nullable(androidx.annotation.Nullable)

Example 20 with ApiResponse

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

the class MessageClientService method updateMessageMetadata.

// Cleanup: default
public ApiResponse updateMessageMetadata(String key, Map<String, String> metadata) {
    MessageMetadataUpdate metadataUpdate = new MessageMetadataUpdate();
    metadataUpdate.setKey(key);
    metadataUpdate.setMetadata(metadata);
    final String jsonFromObject = GsonUtils.getJsonFromObject(metadataUpdate, MessageMetadataUpdate.class);
    Utils.printLog(context, TAG, "Sending message to server: " + jsonFromObject);
    try {
        String response = httpRequestUtils.postData(getMessageMetadataUpdateUrl(), "application/json", "application/json", jsonFromObject);
        ApiResponse apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
        if (apiResponse != null) {
            Utils.printLog(context, TAG, "Message metadata update response : " + apiResponse.toString());
            return apiResponse;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ApiResponse(com.applozic.mobicomkit.feed.ApiResponse) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

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