internal static PNSetChannelMetadataResult GetObject(List <object> listObject) { Dictionary <string, object> setChannelMetadataDicObj = (listObject != null && listObject.Count >= 2) ? JsonDataParseInternalUtil.ConvertToDictionaryObject(listObject[1]) : null; PNSetChannelMetadataResult result = null; if (setChannelMetadataDicObj != null && setChannelMetadataDicObj.ContainsKey("data")) { result = new PNSetChannelMetadataResult(); Dictionary <string, object> getSetChMetadataDataDic = JsonDataParseInternalUtil.ConvertToDictionaryObject(setChannelMetadataDicObj["data"]); if (getSetChMetadataDataDic != null && getSetChMetadataDataDic.Count > 0) { result.Channel = getSetChMetadataDataDic.ContainsKey("id") && getSetChMetadataDataDic["id"] != null ? getSetChMetadataDataDic["id"].ToString() : null; result.Name = getSetChMetadataDataDic.ContainsKey("name") && getSetChMetadataDataDic["name"] != null ? getSetChMetadataDataDic["name"].ToString() : null; result.Description = getSetChMetadataDataDic.ContainsKey("description") && getSetChMetadataDataDic["description"] != null ? getSetChMetadataDataDic["description"].ToString() : null; result.Updated = getSetChMetadataDataDic.ContainsKey("updated") && getSetChMetadataDataDic["updated"] != null ? getSetChMetadataDataDic["updated"].ToString() : null; if (getSetChMetadataDataDic.ContainsKey("custom")) { result.Custom = JsonDataParseInternalUtil.ConvertToDictionaryObject(getSetChMetadataDataDic["custom"]); } } } return(result); }
private async Task <PNResult <PNSetChannelMetadataResult> > SetChannelMetadata(string channelMetaId, bool includeCustom, Dictionary <string, object> externalQueryParam) { PNResult <PNSetChannelMetadataResult> ret = new PNResult <PNSetChannelMetadataResult>(); if (string.IsNullOrEmpty(channelMetaId) || string.IsNullOrEmpty(channelMetaId.Trim())) { PNStatus errStatus = new PNStatus { Error = true, ErrorData = new PNErrorData("Missing Channel", new ArgumentException("Missing Channel")) }; ret.Status = errStatus; return(ret); } if (string.IsNullOrEmpty(config.SubscribeKey) || string.IsNullOrEmpty(config.SubscribeKey.Trim()) || config.SubscribeKey.Length <= 0) { PNStatus errStatus = new PNStatus { Error = true, ErrorData = new PNErrorData("Invalid Subscribe key", new ArgumentException("Invalid Subscribe key")) }; ret.Status = errStatus; return(ret); } RequestState <PNSetChannelMetadataResult> requestState = new RequestState <PNSetChannelMetadataResult>(); requestState.ResponseType = PNOperationType.PNSetChannelMetadataOperation; requestState.Reconnect = false; requestState.EndPointOperation = this; requestState.UsePatchMethod = true; Dictionary <string, object> messageEnvelope = new Dictionary <string, object>(); if (this.chMetaName != null) { messageEnvelope.Add("name", chMetaName); } if (this.chMetaDesc != null) { messageEnvelope.Add("description", chMetaDesc); } if (this.chMetaCustom != null) { messageEnvelope.Add("custom", chMetaCustom); } string patchMessage = jsonLibrary.SerializeToJsonString(messageEnvelope); byte[] patchData = Encoding.UTF8.GetBytes(patchMessage); IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : ""); Uri request = urlBuilder.BuildSetChannelMetadataRequest("PATCH", patchMessage, channelMetaId, includeCustom, externalQueryParam); Tuple <string, PNStatus> JsonAndStatusTuple = await UrlProcessRequest(request, requestState, false, patchData).ConfigureAwait(false); ret.Status = JsonAndStatusTuple.Item2; string json = JsonAndStatusTuple.Item1; if (!string.IsNullOrEmpty(json)) { List <object> resultList = ProcessJsonResponse(requestState, json); ResponseBuilder responseBuilder = new ResponseBuilder(config, jsonLibrary, pubnubLog); PNSetChannelMetadataResult responseResult = responseBuilder.JsonToObject <PNSetChannelMetadataResult>(resultList, true); if (responseResult != null) { ret.Result = responseResult; } } return(ret); }