Exemplo n.º 1
0
        public Models.RootObject GetStoreRedemptions(string queryParams, string itemID)
        {
            string jwtToken = Models.StreamElements.jwtToken;
            string channel  = Models.StreamElements.channel;

            if (queryParams == null)
            {
                queryParams = "?completed=true";
            }
            else
            {
                queryParams += "&completed=true";
            }
            Uri            urlAddress = new Uri("https://api.streamelements.com/kappa/v2/" + "store" + "/" + channel + "/" + "redemptions" + "/" + itemID + queryParams);
            HttpWebRequest request    = (HttpWebRequest)WebRequest.CreateDefault(urlAddress);

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

            if (response.StatusCode == HttpStatusCode.OK)
            {
                Models.RootObject data = ParseRootObjectFromStream(response.GetResponseStream());
                response.Close();
                return(data);
            }
            else
            {
                Console.WriteLine("HttpStatusCode is not OK:" + response.StatusCode.ToString());
                return(null);
            }
        }
Exemplo n.º 2
0
        public static Models.RootObject ParseRootObjectFromStream(Stream stream)
        {
            string value;

            using (var reader = new StreamReader(stream, Encoding.UTF8))
            {
                value = reader.ReadToEnd();
            }
            Models.RootObject RedepmtionList = JsonConvert.DeserializeObject <Models.RootObject>(value);
            return(RedepmtionList);
        }
Exemplo n.º 3
0
        public void StreamElementsCheckJoinRedemptions(CommandArgs args)
        {
            int    limit       = 40;
            bool   pending     = true;
            string queryParams = "?limit=" + limit + "&pending=" + pending;

            //grab list
            Models.RootObject list = GetStoreRedemptions(queryParams, null);
            if (list.docs.Count != 0)
            {
                //make account
                //mark redemption complete
                CreateAccount(list);
            }
            else
            {
            }
        }
Exemplo n.º 4
0
 public void CreateAccount(Models.RootObject a)
 {
     for (int i = 0; i <= (a.docs.Count - 1); i++)
     {
         var Doc = a.docs[i];
         if (Doc.item.ToString().Contains("Join"))
         {
             var account = new TShockAPI.DB.User();
             account.Name  = Doc.redeemer.username;
             account.Group = TShock.Config.DefaultGuestGroupName;
             string password = String.Join(" ", Doc.input.ToArray());
             //Check for account already
             if (TShock.Users.GetUserByName(account.Name) == null)
             {
                 Console.WriteLine(account.Name + "User Does Not Exist");
                 //make the account
                 TShock.Users.AddUser(account);
             }
             //assign the password
             var regex = new Regex("^[a-zA-Z0-9]*$");
             if (password.Length > TShock.Config.MinimumPasswordLength)
             {
                 if (regex.IsMatch(password))
                 {
                     TShock.Users.SetUserPassword(account, password);
                     Console.WriteLine(account.Name + " has changed their password.");
                 }
                 else
                 {
                     Console.WriteLine("Password was shit.  Please try alphanumerical only.");
                 }
             }
             // Mark the redemption complete.
             MarkStreamElementsRedemptionComplete(Doc);
         }
         else
         {
             Console.WriteLine("Redemption list does not contain Join.");
         }
     }
 }