Skip to content

Commit

Permalink
* fixes issue reported by acceptance tests in AppContextApi.
Browse files Browse the repository at this point in the history
* Added support for Patch requests in client library
  • Loading branch information
mohitpubnub committed Oct 9, 2024
1 parent 4c2ad9e commit bbd62a4
Show file tree
Hide file tree
Showing 21 changed files with 286 additions and 322 deletions.
3 changes: 2 additions & 1 deletion src/Api/PubnubApi/EndPoint/Access/GrantTokenOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ internal async Task<PNResult<PNAccessManagerTokenResult>> GrantAccess()
if (transportResponse.Error == null) {
var responseString = Encoding.UTF8.GetString(transportResponse.Content);
PNStatus errorStatus = GetStatusIfError(requestState, responseString);
if (errorStatus == null) {
if (errorStatus == null && transportResponse.StatusCode == Constants.HttpRequestSuccessStatusCode) {
requestState.GotJsonResponse = true;
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(requestState.ResponseType, PNStatusCategory.PNAcknowledgmentCategory, requestState, transportResponse.StatusCode, null);
JsonAndStatusTuple = new Tuple<string, PNStatus>(responseString, status);
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/Api/PubnubApi/EndPoint/Access/RevokeTokenOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ internal void RevokeAccess(PNCallback<PNAccessManagerRevokeTokenResult> callback
var transportRequest = PubnubInstance.transportMiddleware.PreapareTransportRequest(requestParameter: requestParameter, operationType: PNOperationType.PNAccessManagerRevokeToken);
PubnubInstance.transportMiddleware.Send(transportRequest: transportRequest).ContinueWith(t => {
var transportResponse = t.Result;
if (transportResponse.Error == null) {
if (transportResponse.Error == null && transportResponse.StatusCode == Constants.HttpRequestSuccessStatusCode) {
var responseString = Encoding.UTF8.GetString(t.Result.Content);
requestState.GotJsonResponse = true;
if (!string.IsNullOrEmpty(responseString)) {
List<object> result = ProcessJsonResponse(requestState, responseString);
ProcessResponseCallbacks(result, requestState);
Expand Down Expand Up @@ -103,8 +104,9 @@ internal async Task<PNResult<PNAccessManagerRevokeTokenResult>> RevokeAccess()
var transportResponse = await PubnubInstance.transportMiddleware.Send(transportRequest: transportRequest);
if (transportResponse.Error == null) {
var responseString = Encoding.UTF8.GetString(transportResponse.Content);
requestState.GotJsonResponse = true;
PNStatus errorStatus = GetStatusIfError(requestState, responseString);
if (errorStatus == null) {
if (errorStatus == null && transportResponse.StatusCode == Constants.HttpRequestSuccessStatusCode) {
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(requestState.ResponseType, PNStatusCategory.PNAcknowledgmentCategory, requestState, transportResponse.StatusCode, null);
JsonAndStatusTuple = new Tuple<string, PNStatus>(responseString, status);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GetAllChannelMetadataOperation : PubnubCoreBase
private bool includeCount;
private bool includeCustom;
private string channelsFilter;
private PNPageObject page;
private PNPageObject page = new PNPageObject();
private List<string> sortField;

private PNCallback<PNGetAllChannelMetadataResult> savedCallback;
Expand Down Expand Up @@ -109,8 +109,6 @@ private void GetAllChannelMetadataList(PNPageObject page, int limit, bool includ
if (callback == null) {
throw new ArgumentException("Missing callback");
}
PNPageObject internalPage;
if (page == null) { internalPage = new PNPageObject(); } else { internalPage = page; }

RequestState<PNGetAllChannelMetadataResult> requestState = new RequestState<PNGetAllChannelMetadataResult>();
requestState.ResponseType = PNOperationType.PNGetAllChannelMetadataOperation;
Expand All @@ -133,17 +131,14 @@ private void GetAllChannelMetadataList(PNPageObject page, int limit, bool includ
int statusCode = PNStatusCodeHelper.GetHttpStatusCode(transportResponse.Error.Message);
PNStatusCategory category = PNStatusCategoryHelper.GetPNStatusCategory(statusCode, transportResponse.Error.Message);
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(PNOperationType.PNGetAllChannelMetadataOperation, category, requestState, statusCode, new PNException(transportResponse.Error.Message, transportResponse.Error));
requestState.PubnubCallback.OnResponse(default(PNGetAllChannelMetadataResult), status);
requestState.PubnubCallback.OnResponse(default, status);
}
});
}

private async Task<PNResult<PNGetAllChannelMetadataResult>> GetAllChannelMetadataList(PNPageObject page, int limit, bool includeCount, bool includeCustom, string filter, List<string> sort, Dictionary<string, object> externalQueryParam)
{
PNResult<PNGetAllChannelMetadataResult> returnValue = new PNResult<PNGetAllChannelMetadataResult>();

PNPageObject internalPage;
if (page == null) { internalPage = new PNPageObject(); } else { internalPage = page; }
RequestState<PNGetAllChannelMetadataResult> requestState = new RequestState<PNGetAllChannelMetadataResult>();
requestState.ResponseType = PNOperationType.PNGetAllChannelMetadataOperation;
requestState.Reconnect = false;
Expand All @@ -156,7 +151,8 @@ private async Task<PNResult<PNGetAllChannelMetadataResult>> GetAllChannelMetadat
if (transportResponse.Error == null) {
var responseString = Encoding.UTF8.GetString(transportResponse.Content);
PNStatus errorStatus = GetStatusIfError(requestState, responseString);
if (errorStatus == null) {
if (errorStatus == null && transportResponse.StatusCode == Constants.HttpRequestSuccessStatusCode) {
requestState.GotJsonResponse = true;
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(requestState.ResponseType, PNStatusCategory.PNAcknowledgmentCategory, requestState, (int)HttpStatusCode.OK, null);
JsonAndStatusTuple = new Tuple<string, PNStatus>(responseString, status);
} else {
Expand Down Expand Up @@ -193,10 +189,10 @@ private RequestParameter CreateRequestParameter()
};

Dictionary<string, string> requestQueryStringParams = new Dictionary<string, string>();
if (!string.IsNullOrEmpty(page.Next)) {
if (!string.IsNullOrEmpty(page?.Next)) {
requestQueryStringParams.Add("start", UriUtil.EncodeUriComponent(page.Next, PNOperationType.PNGetAllChannelMetadataOperation, false, false, false));
}
if (!string.IsNullOrEmpty(page.Prev)) {
if (!string.IsNullOrEmpty(page?.Prev)) {
requestQueryStringParams.Add("end", UriUtil.EncodeUriComponent(page.Prev, PNOperationType.PNGetAllChannelMetadataOperation, false, false, false));
}
if (limit >= 0) {
Expand Down
13 changes: 3 additions & 10 deletions src/Api/PubnubApi/EndPoint/Objects/GetAllUuidMetadataOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GetAllUuidMetadataOperation : PubnubCoreBase
private bool includeCount;
private bool includeCustom;
private string usersFilter;
private PNPageObject page;
private PNPageObject page = new PNPageObject();
private List<string> sortField;

private PNCallback<PNGetAllUuidMetadataResult> savedCallback;
Expand Down Expand Up @@ -113,9 +113,6 @@ private void GetUuidMetadataList(PNPageObject page, int limit, bool includeCount
{
throw new ArgumentException("Missing callback");
}
PNPageObject internalPage;
if (page == null) { internalPage = new PNPageObject(); }
else { internalPage = page; }
RequestState<PNGetAllUuidMetadataResult> requestState = new RequestState<PNGetAllUuidMetadataResult>();
requestState.ResponseType = PNOperationType.PNGetAllUuidMetadataOperation;
requestState.PubnubCallback = callback;
Expand Down Expand Up @@ -144,11 +141,6 @@ private void GetUuidMetadataList(PNPageObject page, int limit, bool includeCount
private async Task<PNResult<PNGetAllUuidMetadataResult>> GetUuidMetadataList(PNPageObject page, int limit, bool includeCount, bool includeCustom, string filter, List<string> sort, Dictionary<string, object> externalQueryParam)
{
PNResult<PNGetAllUuidMetadataResult> returnValue = new PNResult<PNGetAllUuidMetadataResult>();

PNPageObject internalPage;
if (page == null) { internalPage = new PNPageObject(); }
else { internalPage = page; }

RequestState<PNGetAllUuidMetadataResult> requestState = new RequestState<PNGetAllUuidMetadataResult>();
requestState.ResponseType = PNOperationType.PNGetAllUuidMetadataOperation;
requestState.Reconnect = false;
Expand All @@ -162,7 +154,8 @@ private async Task<PNResult<PNGetAllUuidMetadataResult>> GetUuidMetadataList(PNP
if (transportResponse.Error == null) {
var responseString = Encoding.UTF8.GetString(transportResponse.Content);
PNStatus errorStatus = GetStatusIfError(requestState, responseString);
if (errorStatus == null) {
if (errorStatus == null && transportResponse.StatusCode == Constants.HttpRequestSuccessStatusCode) {
requestState.GotJsonResponse = true;
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(requestState.ResponseType, PNStatusCategory.PNAcknowledgmentCategory, requestState, (int)HttpStatusCode.OK, null);
JsonAndStatusTuple = new Tuple<string, PNStatus>(responseString, status);
} else {
Expand Down
12 changes: 4 additions & 8 deletions src/Api/PubnubApi/EndPoint/Objects/GetChannelMembersOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class GetChannelMembersOperation : PubnubCoreBase
private bool includeCount;
private string commandDelimitedIncludeOptions = "";
private string membersFilter;
private PNPageObject page;
private PNPageObject page = new PNPageObject();
private List<string> sortField;

private PNCallback<PNChannelMembersResult> savedCallback;
Expand Down Expand Up @@ -121,8 +121,6 @@ internal void Retry()

private void GetMembersList(string spaceId, PNPageObject page, int limit, bool includeCount, string includeOptions, string filter, List<string> sort, Dictionary<string, object> externalQueryParam, PNCallback<PNChannelMembersResult> callback)
{
PNPageObject internalPage;
if (page == null) { internalPage = new PNPageObject(); } else { internalPage = page; }
RequestState<PNChannelMembersResult> requestState = new RequestState<PNChannelMembersResult>();
requestState.ResponseType = PNOperationType.PNGetChannelMembersOperation;
requestState.PubnubCallback = callback;
Expand All @@ -148,17 +146,14 @@ private void GetMembersList(string spaceId, PNPageObject page, int limit, bool i
int statusCode = PNStatusCodeHelper.GetHttpStatusCode(transportResponse.Error.Message);
PNStatusCategory category = PNStatusCategoryHelper.GetPNStatusCategory(statusCode, transportResponse.Error.Message);
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(PNOperationType.PNGetChannelMembersOperation, category, requestState, statusCode, new PNException(transportResponse.Error.Message, transportResponse.Error));
requestState.PubnubCallback.OnResponse(default(PNChannelMembersResult), status);
requestState.PubnubCallback.OnResponse(default, status);
}
});
}

private async Task<PNResult<PNChannelMembersResult>> GetMembersList(string spaceId, PNPageObject page, int limit, bool includeCount, string includeOptions, string filter, List<string> sort, Dictionary<string, object> externalQueryParam)
{
PNResult<PNChannelMembersResult> returnValue = new PNResult<PNChannelMembersResult>();

PNPageObject internalPage;
if (page == null) { internalPage = new PNPageObject(); } else { internalPage = page; }
RequestState<PNChannelMembersResult> requestState = new RequestState<PNChannelMembersResult>();
requestState.ResponseType = PNOperationType.PNGetChannelMembersOperation;
requestState.Reconnect = false;
Expand All @@ -172,7 +167,8 @@ private async Task<PNResult<PNChannelMembersResult>> GetMembersList(string space
if (transportResponse.Error == null) {
var responseString = Encoding.UTF8.GetString(transportResponse.Content);
PNStatus errorStatus = GetStatusIfError(requestState, responseString);
if (errorStatus == null) {
if (errorStatus == null&& transportResponse.StatusCode == Constants.HttpRequestSuccessStatusCode) {
requestState.GotJsonResponse = true;
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(requestState.ResponseType, PNStatusCategory.PNAcknowledgmentCategory, requestState, (int)HttpStatusCode.OK, null);
JsonAndStatusTuple = new Tuple<string, PNStatus>(responseString, status);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ private async Task<PNResult<PNGetChannelMetadataResult>> GetSingleChannelMetadat
if (transportResponse.Error == null) {
var responseString = Encoding.UTF8.GetString(transportResponse.Content);
PNStatus errorStatus = GetStatusIfError(requestState, responseString);
if (errorStatus == null) {
if (errorStatus == null && transportResponse.StatusCode == Constants.HttpRequestSuccessStatusCode) {
requestState.GotJsonResponse = true;
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(requestState.ResponseType, PNStatusCategory.PNAcknowledgmentCategory, requestState, (int)HttpStatusCode.OK, null);
JsonAndStatusTuple = new Tuple<string, PNStatus>(responseString, status);
} else {
Expand Down
11 changes: 3 additions & 8 deletions src/Api/PubnubApi/EndPoint/Objects/GetMembershipsOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GetMembershipsOperation : PubnubCoreBase
private bool includeCount;
private string commandDelimitedIncludeOptions = "";
private string membershipsFilter;
private PNPageObject page;
private PNPageObject page = new PNPageObject();
private List<string> sortField;

private PNCallback<PNMembershipsResult> savedCallback;
Expand Down Expand Up @@ -110,9 +110,6 @@ private void GetMembershipsList(string uuid, PNPageObject page, int limit, bool
uuid = config.UserId;
}

PNPageObject internalPage;
if (page == null) { internalPage = new PNPageObject(); } else { internalPage = page; }

RequestState<PNMembershipsResult> requestState = new RequestState<PNMembershipsResult>();
requestState.ResponseType = PNOperationType.PNGetMembershipsOperation;
requestState.PubnubCallback = callback;
Expand Down Expand Up @@ -150,9 +147,6 @@ private async Task<PNResult<PNMembershipsResult>> GetMembershipsList(string uuid
if (string.IsNullOrEmpty(uuid)) {
uuid = config.UserId;
}

PNPageObject internalPage;
if (page == null) { internalPage = new PNPageObject(); } else { internalPage = page; }
RequestState<PNMembershipsResult> requestState = new RequestState<PNMembershipsResult>();
requestState.ResponseType = PNOperationType.PNGetMembershipsOperation;
requestState.UsePostMethod = false;
Expand All @@ -167,7 +161,8 @@ private async Task<PNResult<PNMembershipsResult>> GetMembershipsList(string uuid
if (transportResponse.Error == null) {
var responseString = Encoding.UTF8.GetString(transportResponse.Content);
PNStatus errorStatus = GetStatusIfError(requestState, responseString);
if (errorStatus == null) {
if (errorStatus == null && transportResponse.StatusCode == Constants.HttpRequestSuccessStatusCode) {
requestState.GotJsonResponse = true;
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(requestState.ResponseType, PNStatusCategory.PNAcknowledgmentCategory, requestState, (int)HttpStatusCode.OK, null);
JsonAndStatusTuple = new Tuple<string, PNStatus>(responseString, status);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void GetSingleUuidMetadata(string uuid, bool includeCustom, Dictionary<s
throw new ArgumentException("Missing callback");
}
if (string.IsNullOrEmpty(uuid)) {
uuid = config.UserId;
this.uuid = config.UserId;
}
RequestState<PNGetUuidMetadataResult> requestState = new RequestState<PNGetUuidMetadataResult>();
requestState.ResponseType = PNOperationType.PNGetUuidMetadataOperation;
Expand Down Expand Up @@ -116,7 +116,7 @@ private void GetSingleUuidMetadata(string uuid, bool includeCustom, Dictionary<s
private async Task<PNResult<PNGetUuidMetadataResult>> GetSingleUuidMetadata(string uuid, bool includeCustom, Dictionary<string, object> externalQueryParam)
{
if (string.IsNullOrEmpty(uuid)) {
uuid = config.UserId;
this.uuid = config.UserId;
}
PNResult<PNGetUuidMetadataResult> returnValue = new PNResult<PNGetUuidMetadataResult>();
RequestState<PNGetUuidMetadataResult> requestState = new RequestState<PNGetUuidMetadataResult>();
Expand All @@ -132,7 +132,8 @@ private async Task<PNResult<PNGetUuidMetadataResult>> GetSingleUuidMetadata(stri
if (transportResponse.Error == null) {
var responseString = Encoding.UTF8.GetString(transportResponse.Content);
PNStatus errorStatus = GetStatusIfError(requestState, responseString);
if (errorStatus == null) {
if (errorStatus == null && transportResponse.StatusCode == Constants.HttpRequestSuccessStatusCode) {
requestState.GotJsonResponse = true;
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(requestState.ResponseType, PNStatusCategory.PNAcknowledgmentCategory, requestState, (int)HttpStatusCode.OK, null);
JsonAndStatusTuple = new Tuple<string, PNStatus>(responseString, status);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ManageChannelMembersOperation : PubnubCoreBase
private List<PNChannelMember> setMember;
private List<string> delMember;
private string commandDelimitedIncludeOptions = string.Empty;
private PNPageObject page;
private PNPageObject page = new PNPageObject();
private int limit = -1;
private bool includeCount;
private List<string> sortField;
Expand Down Expand Up @@ -144,10 +144,6 @@ internal void Retry()

private void ProcessMembersOperationRequest(string spaceId, List<PNChannelMember> setMemberList, List<string> removeMemberList, PNPageObject page, int limit, bool includeCount, string includeOptions, List<string> sort, Dictionary<string, object> externalQueryParam, PNCallback<PNChannelMembersResult> callback)
{
PNPageObject internalPage;
if (page == null) { internalPage = new PNPageObject(); }
else { internalPage = page; }

RequestState<PNChannelMembersResult> requestState = new RequestState<PNChannelMembersResult>();
requestState.ResponseType = PNOperationType.PNManageChannelMembersOperation;
requestState.PubnubCallback = callback;
Expand Down Expand Up @@ -195,11 +191,6 @@ private async Task<PNResult<PNChannelMembersResult>> ProcessMembersOperationRequ
returnValue.Status = errStatus;
return returnValue;
}

PNPageObject internalPage;
if (page == null) { internalPage = new PNPageObject(); }
else { internalPage = page; }

RequestState<PNChannelMembersResult> requestState = new RequestState<PNChannelMembersResult>();
requestState.ResponseType = PNOperationType.PNManageChannelMembersOperation;
requestState.Reconnect = false;
Expand All @@ -212,7 +203,8 @@ private async Task<PNResult<PNChannelMembersResult>> ProcessMembersOperationRequ
if (transportResponse.Error == null) {
var responseString = Encoding.UTF8.GetString(transportResponse.Content);
PNStatus errorStatus = GetStatusIfError(requestState, responseString);
if (errorStatus == null) {
if (errorStatus == null && transportResponse.StatusCode == Constants.HttpRequestSuccessStatusCode) {
requestState.GotJsonResponse = true;
PNStatus status = new StatusBuilder(config, jsonLibrary).CreateStatusResponse(requestState.ResponseType, PNStatusCategory.PNAcknowledgmentCategory, requestState, (int)HttpStatusCode.OK, null);
JsonAndStatusTuple = new Tuple<string, PNStatus>(responseString, status);
} else {
Expand Down
Loading

0 comments on commit bbd62a4

Please sign in to comment.