예제 #1
0
        public async Task <ChannelState> Query(ChannelQueryParams queryParams)
        {
            var payload = JObject.FromObject(queryParams);

            payload.Add("data", this._data.ToJObject());

            string tpl      = "channels/{0}{1}/query";
            string idStr    = this.ID == null ? "" : "/" + this.ID;
            string endpoint = string.Format(tpl, this.Type, idStr);

            var request = this._client.BuildAppRequest(endpoint, HttpMethod.POST);

            request.SetJsonBody(JsonConvert.SerializeObject(payload));

            var response = await this._client.MakeRequest(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
            {
                var stateObj = JObject.Parse(response.Content);
                stateObj.Remove("duration");
                var chanState = ChannelState.FromJObject(stateObj);
                if (string.IsNullOrEmpty(this.ID))
                {
                    this.ID = chanState.Channel.ID;
                }
                return(chanState);
            }
            throw StreamChatException.FromResponse(response);
        }
예제 #2
0
        public async Task<List<ChannelState>> QueryChannels(QueryChannelsOptions opts)
        {
            var request = this.BuildAppRequest("channels", HttpMethod.GET);
            opts.Apply(request);

            var response = await this.MakeRequest(request);
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var root = JObject.Parse(response.Content);
                var chans = root.Property("channels").Value as JArray;
                var result = new List<ChannelState>();
                foreach (var chan in chans)
                {
                    var chanObj = chan as JObject;
                    result.Add(ChannelState.FromJObject(chanObj));
                }
                return result;
            }
            throw StreamChatException.FromResponse(response);
        }