Пример #1
0
        public static Models.Points.UserPoints ParsePointsObjectFromStream(Stream stream)
        {
            string value;

            using (var reader = new StreamReader(stream, Encoding.UTF8))
            {
                value = reader.ReadToEnd();
            }
            Models.Points.UserPoints RedepmtionList = JsonConvert.DeserializeObject <Models.Points.UserPoints>(value);
            return(RedepmtionList);
        }
Пример #2
0
        public Models.Points.UserPoints StreamElementsPointsRequest(CommandArgs args)
        {
            string user = string.Join(" ", args.Parameters);

            if (string.IsNullOrWhiteSpace(user))
            {
                user = args.Player.User.Name;
                if (string.IsNullOrWhiteSpace(user))
                {
                    return(null);
                }
            }
            string         jwtToken   = Models.StreamElements.jwtToken;
            string         channel    = Models.StreamElements.channel;
            Uri            urlAddress = new Uri("https://api.streamelements.com/kappa/v2/" + "points" + "/" + channel + "/" + user);
            HttpWebRequest request    = (HttpWebRequest)WebRequest.CreateDefault(urlAddress);

            request.Headers["Authorization"] = ("Bearer " + jwtToken);
            ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                Stream       receiveStream = response.GetResponseStream();
                StreamReader readStream    = null;
                if (response.CharacterSet == null)
                {
                    readStream = new StreamReader(receiveStream);
                }
                else
                {
                    readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
                }
                // Send Message to player
                Models.Points.UserPoints userPoints = ParsePointsObjectFromStream(response.GetResponseStream());
                response.Close();
                readStream.Close();
                return(userPoints);
            }
            return(null);
        }