Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Type and SpaceId to all features #165

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions src/Api/PubnubApi/Builder/UrlRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Uri IUrlRequestBuilder.BuildMultiChannelLeaveRequest(string requestMethod, strin
return BuildRestApiRequest(requestMethod, requestBody, url, currentType, queryString, true);
}

Uri IUrlRequestBuilder.BuildPublishRequest(string requestMethod, string requestBody, string channel, object originalMessage, bool storeInHistory, int ttl, Dictionary<string, object> userMetaData, Dictionary<string, string> additionalUrlParams, Dictionary<string, object> externalQueryParam)
Uri IUrlRequestBuilder.BuildPublishRequest(string requestMethod, string requestBody, string channel, object originalMessage, bool storeInHistory, int ttl, Dictionary<string, object> userMetaData, string type, string spaceId, Dictionary<string, string> additionalUrlParams, Dictionary<string, object> externalQueryParam)
{
PNOperationType currentType = PNOperationType.PNPublishOperation;

Expand Down Expand Up @@ -202,6 +202,16 @@ Uri IUrlRequestBuilder.BuildPublishRequest(string requestMethod, string requestB
requestQueryStringParams.Add("meta", UriUtil.EncodeUriComponent(jsonMetaData, currentType, false, false, false));
}

if (!string.IsNullOrEmpty(type))
{
requestQueryStringParams.Add("type", UriUtil.EncodeUriComponent(type, currentType, false, false, false));
}

if (!string.IsNullOrEmpty(spaceId))
{
requestQueryStringParams.Add("space-id", UriUtil.EncodeUriComponent(spaceId, currentType, false, false, false));
}

if (storeInHistory && ttl >= 0)
{
requestQueryStringParams.Add("tt1", ttl.ToString(CultureInfo.InvariantCulture));
Expand Down Expand Up @@ -229,7 +239,7 @@ Uri IUrlRequestBuilder.BuildPublishRequest(string requestMethod, string requestB
return BuildRestApiRequest(requestMethod, requestBody, url, currentType, queryString, allowPAMv3Sign);
}

Uri IUrlRequestBuilder.BuildSignalRequest(string requestMethod, string requestBody, string channel, object originalMessage, Dictionary<string, object> userMetaData, Dictionary<string, object> externalQueryParam)
Uri IUrlRequestBuilder.BuildSignalRequest(string requestMethod, string requestBody, string channel, object originalMessage, Dictionary<string, object> userMetaData, string type, string spaceId, Dictionary<string, object> externalQueryParam)
{
PNOperationType currentType = PNOperationType.PNSignalOperation;

Expand All @@ -253,6 +263,16 @@ Uri IUrlRequestBuilder.BuildSignalRequest(string requestMethod, string requestBo
requestQueryStringParams.Add("meta", UriUtil.EncodeUriComponent(jsonMetaData, currentType, false, false, false));
}

if (!string.IsNullOrEmpty(type))
{
requestQueryStringParams.Add("type", UriUtil.EncodeUriComponent(type, currentType, false, false, false));
}

if (!string.IsNullOrEmpty(spaceId))
{
requestQueryStringParams.Add("space-id", UriUtil.EncodeUriComponent(spaceId, currentType, false, false, false));
}

if (externalQueryParam != null && externalQueryParam.Count > 0)
{
foreach (KeyValuePair<string, object> kvp in externalQueryParam)
Expand Down Expand Up @@ -370,7 +390,7 @@ Uri IUrlRequestBuilder.BuildHistoryRequest(string requestMethod, string requestB
return BuildRestApiRequest(requestMethod, requestBody, url, currentType, queryString, true);
}

Uri IUrlRequestBuilder.BuildFetchRequest(string requestMethod, string requestBody, string[] channels, long start, long end, int count, bool reverse, bool includeMeta, bool includeMessageActions, bool includeUuid, bool includeMessageType, Dictionary<string, object> externalQueryParam)
Uri IUrlRequestBuilder.BuildFetchRequest(string requestMethod, string requestBody, string[] channels, long start, long end, int count, bool reverse, bool includeMeta, bool includeMessageActions, bool includeUuid, bool includeMessageType, bool includeType, bool includeSpaceId, Dictionary<string, object> externalQueryParam)
{
string channel = (channels != null && channels.Length > 0) ? string.Join(",", channels.OrderBy(x => x).ToArray()) : "";

Expand Down Expand Up @@ -415,6 +435,24 @@ Uri IUrlRequestBuilder.BuildFetchRequest(string requestMethod, string requestBod
{
requestQueryStringParams.Add("include_message_type", "true");
}
else
{
requestQueryStringParams.Add("include_message_type", "false");
}

if (includeType)
{
requestQueryStringParams.Add("include_type", "true");
}
else
{
requestQueryStringParams.Add("include_type", "false");
}

if (includeSpaceId)
{
requestQueryStringParams.Add("include_space_id", "true");
}

if (externalQueryParam != null && externalQueryParam.Count > 0)
{
Expand Down Expand Up @@ -1895,7 +1933,7 @@ Uri IUrlRequestBuilder.BuildGenerateFileUploadUrlRequest(string requestMethod, s
return BuildRestApiRequest(requestMethod, requestBody, url, currentType, queryString, true);
}

Uri IUrlRequestBuilder.BuildPublishFileMessageRequest(string requestMethod, string requestBody, string channel, object originalMessage, bool storeInHistory, int ttl, Dictionary<string, object> userMetaData, Dictionary<string, string> additionalUrlParams, Dictionary<string, object> externalQueryParam)
Uri IUrlRequestBuilder.BuildPublishFileMessageRequest(string requestMethod, string requestBody, string channel, object originalMessage, bool storeInHistory, int ttl, Dictionary<string, object> userMetaData, string type, string spaceId, Dictionary<string, string> additionalUrlParams, Dictionary<string, object> externalQueryParam)
{
PNOperationType currentType = PNOperationType.PNPublishFileMessageOperation;

Expand Down Expand Up @@ -1938,6 +1976,16 @@ Uri IUrlRequestBuilder.BuildPublishFileMessageRequest(string requestMethod, stri
requestQueryStringParams.Add("store", "0");
}

if (!string.IsNullOrEmpty(type))
{
requestQueryStringParams.Add("type",UriUtil.EncodeUriComponent(type, currentType, false, false, false));
}

if (!string.IsNullOrEmpty(spaceId))
{
requestQueryStringParams.Add("space-id", UriUtil.EncodeUriComponent(spaceId, currentType, false, false, false));
}

if (externalQueryParam != null && externalQueryParam.Count > 0)
{
foreach (KeyValuePair<string, object> kvp in externalQueryParam)
Expand Down
17 changes: 15 additions & 2 deletions src/Api/PubnubApi/EndPoint/Files/PublishFileMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class PublishFileMessageOperation : PubnubCoreBase
private bool storeInHistory = true;
private Dictionary<string, object> userMetadata;
private int ttl = -1;
private string type = string.Empty;
private string spaceId = string.Empty;

public PublishFileMessageOperation(PNConfiguration pubnubConfig, IJsonPluggableLibrary jsonPluggableLibrary, IPubnubUnitTest pubnubUnit, IPubnubLog log, EndPoint.TelemetryManager telemetryManager, EndPoint.TokenManager tokenManager, Pubnub instance) : base(pubnubConfig, jsonPluggableLibrary, pubnubUnit, log, telemetryManager, tokenManager, instance)
{
Expand Down Expand Up @@ -95,6 +97,17 @@ public PublishFileMessageOperation FileName(string name)
return this;
}

public PublishFileMessageOperation Type(string type)
{
this.type = type;
return this;
}
public PublishFileMessageOperation SpaceId(string spaceId)
{
this.spaceId = spaceId;
return this;
}

public PublishFileMessageOperation QueryParam(Dictionary<string, object> customQueryParam)
{
this.queryParam = customQueryParam;
Expand Down Expand Up @@ -178,7 +191,7 @@ private void ProcessFileMessagePublish(Dictionary<string, object> externalQueryP


IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null && !string.IsNullOrEmpty(PubnubInstance.InstanceId) && PubnubTokenMgrCollection.ContainsKey(PubnubInstance.InstanceId)) ? PubnubTokenMgrCollection[PubnubInstance.InstanceId] : null, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");
Uri request = urlBuilder.BuildPublishFileMessageRequest("GET", "", this.channelName, publishPayload, this.storeInHistory, this.ttl, this.userMetadata, null, externalQueryParam);
Uri request = urlBuilder.BuildPublishFileMessageRequest("GET", "", this.channelName, publishPayload, this.storeInHistory, this.ttl, this.userMetadata, this.type, this.spaceId, null, externalQueryParam);

string json = "";
UrlProcessRequest(request, requestState, false).ContinueWith(r =>
Expand Down Expand Up @@ -246,7 +259,7 @@ private async Task<PNResult<PNPublishFileMessageResult>> ProcessFileMessagePubli
requestState.EndPointOperation = this;

IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null && !string.IsNullOrEmpty(PubnubInstance.InstanceId) && PubnubTokenMgrCollection.ContainsKey(PubnubInstance.InstanceId)) ? PubnubTokenMgrCollection[PubnubInstance.InstanceId] : null, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");
Uri request = urlBuilder.BuildPublishFileMessageRequest("GET", "", this.channelName, publishPayload, this.storeInHistory, this.ttl, this.userMetadata, null, externalQueryParam);
Uri request = urlBuilder.BuildPublishFileMessageRequest("GET", "", this.channelName, publishPayload, this.storeInHistory, this.ttl, this.userMetadata, this.type, this.spaceId, null, externalQueryParam);

Tuple<string, PNStatus> JsonAndStatusTuple = await UrlProcessRequest(request, requestState, false).ConfigureAwait(false);
ret.Status = JsonAndStatusTuple.Item2;
Expand Down
19 changes: 17 additions & 2 deletions src/Api/PubnubApi/EndPoint/Files/SendFileOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class SendFileOperation : PubnubCoreBase
private bool storeInHistory = true;
private Dictionary<string, object> userMetadata;
private int ttl = -1;
private string type = string.Empty;
private string spaceId = string.Empty;

public SendFileOperation(PNConfiguration pubnubConfig, IJsonPluggableLibrary jsonPluggableLibrary, IPubnubUnitTest pubnubUnit, IPubnubLog log, EndPoint.TelemetryManager telemetryManager, EndPoint.TokenManager tokenManager, Pubnub instance) : base(pubnubConfig, jsonPluggableLibrary, pubnubUnit, log, telemetryManager, tokenManager, instance)
{
Expand Down Expand Up @@ -87,6 +89,17 @@ public SendFileOperation Ttl(int ttl)
return this;
}

public SendFileOperation Type(string type)
{
this.type = type;
return this;
}
public SendFileOperation SpaceId(string spaceId)
{
this.spaceId = spaceId;
return this;
}

public SendFileOperation File(string fileNameWithFullPath)
{
this.sendFileFullPath = fileNameWithFullPath;
Expand Down Expand Up @@ -400,7 +413,7 @@ private async Task<PNResult<PNPublishFileMessageResult>> PublishFileMessage(obje

IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null && !string.IsNullOrEmpty(PubnubInstance.InstanceId) && PubnubTokenMgrCollection.ContainsKey(PubnubInstance.InstanceId)) ? PubnubTokenMgrCollection[PubnubInstance.InstanceId] : null, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");

Uri request = urlBuilder.BuildPublishFileMessageRequest("GET", "", this.channelName, message, this.storeInHistory, this.ttl, this.userMetadata, null, externalQueryParam);
Uri request = urlBuilder.BuildPublishFileMessageRequest("GET", "", this.channelName, message, this.storeInHistory, this.ttl, this.userMetadata, this.type, this.spaceId, null, externalQueryParam);

RequestState<PNPublishFileMessageResult> requestState = new RequestState<PNPublishFileMessageResult>();
requestState.Channels = new[] { this.channelName };
Expand All @@ -420,7 +433,9 @@ await UrlProcessRequest(request, requestState, false).ContinueWith(r =>
ResponseBuilder responseBuilder = new ResponseBuilder(config, jsonLibrary, pubnubLog);
PNPublishFileMessageResult publishResult = responseBuilder.JsonToObject<PNPublishFileMessageResult>(result, true);
StatusBuilder statusBuilder = new StatusBuilder(config, jsonLibrary);
if (publishResult != null)
if (result != null &&
string.Compare(result[0].ToString(), "1", StringComparison.OrdinalIgnoreCase) == 0 &&
publishResult != null)
{
ret.Result = publishResult;
PNStatus status = statusBuilder.CreateStatusResponse(requestState.ResponseType, PNStatusCategory.PNAcknowledgmentCategory, requestState, (int)HttpStatusCode.OK, null);
Expand Down
4 changes: 2 additions & 2 deletions src/Api/PubnubApi/EndPoint/PubSub/FireOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private void Fire(string channel, object message, bool storeInHistory, int ttl,
string requestMethodName = (this.httpPost) ? "POST" : "GET";
IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null && !string.IsNullOrEmpty(PubnubInstance.InstanceId) && PubnubTokenMgrCollection.ContainsKey(PubnubInstance.InstanceId)) ? PubnubTokenMgrCollection[PubnubInstance.InstanceId] : null, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");

Uri request = urlBuilder.BuildPublishRequest(requestMethodName, "", channel, message, storeInHistory, ttl, metaData, urlParam, externalQueryParam);
Uri request = urlBuilder.BuildPublishRequest(requestMethodName, "", channel, message, storeInHistory, ttl, metaData, null, null, urlParam, externalQueryParam);

RequestState<PNPublishResult> requestState = new RequestState<PNPublishResult>();
requestState.Channels = new [] { channel };
Expand Down Expand Up @@ -261,7 +261,7 @@ private async Task<PNResult<PNPublishResult>> Fire(string channel, object messag
string requestMethodName = (this.httpPost) ? "POST" : "GET";
IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null && !string.IsNullOrEmpty(PubnubInstance.InstanceId) && PubnubTokenMgrCollection.ContainsKey(PubnubInstance.InstanceId)) ? PubnubTokenMgrCollection[PubnubInstance.InstanceId] : null, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");

Uri request = urlBuilder.BuildPublishRequest(requestMethodName, "", channel, message, storeInHistory, ttl, metaData, urlParam, externalQueryParam);
Uri request = urlBuilder.BuildPublishRequest(requestMethodName, "", channel, message, storeInHistory, ttl, metaData, null, null, urlParam, externalQueryParam);

RequestState<PNPublishResult> requestState = new RequestState<PNPublishResult>();
requestState.Channels = new[] { channel };
Expand Down
Loading