コード例 #1
0
        public void ShouldReuseAccessToken()
        {
            const string email = "*****@*****.**";

            UserVoice.Client client    = getSignedClient();
            UserVoice.Client userToken = client.LoginAs(email);

            UserVoice.Client copiedToken = getSignedClient()
                                           .LoginWithAccessToken(userToken.Token, userToken.Secret);
            AssertEqual((string)copiedToken.Get("/api/v1/users/current")["user"]["email"], email);
        }
コード例 #2
0
        public void ShouldThrowExceptionOnOutOfRangeReference()
        {
            var k = false;

            try {
                UserVoice.Client     client = getSignedClient();
                UserVoice.Collection users  = client.LoginAsOwner().GetCollection("/api/v1/users", 3);
                Console.WriteLine("Getting user out of range FAILED: " + users[3]);
            } catch (IndexOutOfRangeException e) {
                e = e;
                k = true;
            }
            AssertTrue(k);
        }
コード例 #3
0
        public void ShouldForLoopMoreThan10Users()
        {
            UserVoice.Client     client = getSignedClient();
            UserVoice.Collection users  = client.LoginAsOwner().GetCollection("/api/v1/users");
            int times = 3;

            for (int i = 0; i < users.Count(); i++)
            {
                if (--times <= 0)
                {
                    break;
                }
                //Console.WriteLine("User: " + users[i]);
            }
            AssertTrue(users.Count() > 10);
        }
コード例 #4
0
        public void ShouldGetMoreThan10Users()
        {
            UserVoice.Client     client = getSignedClient();
            UserVoice.Collection users  = client.LoginAsOwner().GetCollection("/api/v1/users");
            int times = 3;

            foreach (var k in users)
            {
                if (--times <= 0)
                {
                    break;
                }
                //Console.WriteLine("User: " + k);
            }
            AssertTrue(users.Count() > 10);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: Code-Inside/BecauseWeCare
        static string API_KEY = ""; // Needed!

        #endregion Fields

        #region Methods

        public static void SyncUserVoiceSiteToRavenDb(Site site, string ravenDbServer, string database)
        {
            Console.WriteLine("SyncUserVoiceSite started for UserVoiceSite {0} to RavenDbServer {1}", site.Name, ravenDbServer + "@" + database);

            Stopwatch watch = new Stopwatch();
            watch.Start();

            var client = new UserVoice.Client(site.Subdomain, "", apiSecret: "");
            // for closed stuff we need the filter=closed (which is the only filter i can access ?? - otherwise just suggestions.json as endpoint
            var suggestions = client.GetCollection("/api/v1/forums/" + site.Id + "/suggestions.json?filter=closed");

            var totalNumber = suggestions.Count;

            Console.WriteLine("Total suggestions: " + totalNumber);

            using (var documentStore = new DocumentStore { Url = ravenDbServer, DefaultDatabase = database})
            {
                documentStore.Initialize();

                using (var bulkInsert = documentStore.BulkInsert(options: new BulkInsertOptions() { CheckForUpdates = true, BatchSize = 100 }))
                {
                    int i = 0;

                    foreach (var suggestionJson in suggestions)
                    {
                        int percentage = 0;

                        if(i > 0)
                        {
                            percentage =  i * 100/totalNumber;
                        }

                        Console.WriteLine("Completed {0}% (Counter: {1})", percentage, i);

                        var suggestionObject = suggestionJson.ToObject<Suggestion>();

                        suggestionObject.Site = site;
                        bulkInsert.Store(suggestionObject);
                        i++;
                    }
                }
            }

            watch.Stop();

            Console.WriteLine("Job for UserVoiceSite {0} finished. Elpased Time: {1}:{2}", site.Name, watch.Elapsed.Minutes, watch.Elapsed.Seconds);
        }
コード例 #6
0
        public void Send()
        {
            Task.Run(
                () =>
            {
                try
                {
                    var apikey    = "hVAAtCM7wCEaJe9DqlR52w";
                    var apiSecret = "haN4L38nqnyZTTfVyudb7WpR2vSAcOWB3PUEm6XQQ";
                    var subdomain = "hearthstonetracker";

                    var client = new UserVoice.Client(subdomain, apikey, apiSecret);

                    object attachments = new object[] { };
                    if (AttachLog)
                    {
                        var logPath        = Path.Combine((string)AppDomain.CurrentDomain.GetData("DataDirectory"), "logs");
                        var dirInfo        = new DirectoryInfo(logPath);
                        var latestLogfiles = dirInfo.GetFiles().Where(x => x.Extension == ".txt").OrderByDescending(x => x.LastWriteTime).Take(3).ToList();

                        if (latestLogfiles.Count > 0)
                        {
                            using (var ms = new MemoryStream())
                            {
                                using (var zipfile = new ZipArchive(ms, ZipArchiveMode.Create, true))
                                {
                                    foreach (var latestLogfile in latestLogfiles)
                                    {
                                        zipfile.CreateEntryFromFile(latestLogfile.FullName, latestLogfile.Name, CompressionLevel.Optimal);
                                    }
                                }
                                ms.Position = 0;
                                var bytes   = new Byte[ms.Length];
                                ms.Read(bytes, 0, bytes.Length);

                                attachments = new object[]
                                {
                                    new
                                    {
                                        name         = "logfiles.zip",
                                        content_type = "application/zip",
                                        data         = Convert.ToBase64String(bytes)
                                    }
                                };
                            }
                        }
                    }
                    var ticket = new
                    {
                        email  = Email,
                        ticket = new
                        {
                            state       = "open",
                            subject     = Subject,
                            message     = Message,
                            user_agent  = "HearthstoneTracker App",
                            attachments = attachments
                        }
                    };
                    client.Post("/api/v1/tickets.json", ticket);
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                }
            });

            TryClose();
            MessageBox.Show("Your support request has been sent.", "Support request sent.", MessageBoxButton.OK);
        }
コード例 #7
0
 public void ShouldGetOnly3Users()
 {
     UserVoice.Client     client = getSignedClient();
     UserVoice.Collection users  = client.LoginAsOwner().GetCollection("/api/v1/users", 3);
     AssertEqual(3, users.Count());
 }
コード例 #8
0
 public void ShouldGet10Users()
 {
     UserVoice.Client client = getSignedClient();
     AssertEqual(client.Get("/api/v1/users")["users"].Count(), 10);
 }
コード例 #9
0
 public void ShouldLoginAsOwner()
 {
     UserVoice.Client client = getSignedClient();
     client = client.LoginAsOwner();
     AssertTrue((bool)client.Get("/api/v1/users/current")["user"]["roles"]["owner"]);
 }
コード例 #10
0
 public void ShouldGetPublicForumData()
 {
     UserVoice.Client publicClient = getUnsignedClient();
     AssertEqual(false, (bool)publicClient.GetCollection("/api/v1/forums", 1)[0]["private"]);
 }
コード例 #11
0
 public void ShouldGetCurrentUserEmail()
 {
     UserVoice.Client client = getSignedClient();
     client = client.LoginAs("*****@*****.**");
     AssertEqual("*****@*****.**", (string)client.Get("/api/v1/users/current")["user"]["email"]);
 }
コード例 #12
0
        public void Send()
        {
            Task.Run(
                () =>
                {
                    try
                    {
                        var apikey = "hVAAtCM7wCEaJe9DqlR52w";
                        var apiSecret = "haN4L38nqnyZTTfVyudb7WpR2vSAcOWB3PUEm6XQQ";
                        var subdomain = "hearthstonetracker";

                        var client = new UserVoice.Client(subdomain, apikey, apiSecret);

                        object attachments = new object[] { };
                        if (AttachLog)
                        {
                            var logPath = Path.Combine((string)AppDomain.CurrentDomain.GetData("DataDirectory"), "logs");
                            var dirInfo = new DirectoryInfo(logPath);
                            var latestLogfiles = dirInfo.GetFiles().Where(x => x.Extension == ".txt").OrderByDescending(x => x.LastWriteTime).Take(3).ToList();

                            if (latestLogfiles.Count > 0)
                            {
                                using (var ms = new MemoryStream())
                                {
                                    using (var zipfile = new ZipArchive(ms, ZipArchiveMode.Create, true))
                                    {
                                        foreach (var latestLogfile in latestLogfiles)
                                        {
                                            zipfile.CreateEntryFromFile(latestLogfile.FullName, latestLogfile.Name, CompressionLevel.Optimal);
                                        }
                                    }
                                    ms.Position = 0;
                                    var bytes = new Byte[ms.Length];
                                    ms.Read(bytes, 0, bytes.Length);

                                    attachments = new object[]
                                                     {
                                                         new
                                                             {
                                                                 name = "logfiles.zip",
                                                                 content_type = "application/zip",
                                                                 data = Convert.ToBase64String(bytes)
                                                             }
                                                     };
                                }
                            }
                        }
                        var ticket = new
                        {
                            email = Email,
                            ticket = new
                            {
                                state = "open",
                                subject = Subject,
                                message = Message,
                                user_agent = "HearthstoneTracker App",
                                attachments = attachments
                            }
                        };
                        client.Post("/api/v1/tickets.json", ticket);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                    }
                });

            TryClose();
            MessageBox.Show("Your support request has been sent.", "Support request sent.", MessageBoxButton.OK);
        }
コード例 #13
0
 public void ShouldGetNoUsers()
 {
     UserVoice.Client     client = getSignedClient();
     UserVoice.Collection users  = client.LoginAsOwner().GetCollection("/api/v1/users/search?query=from:[email protected]");
     AssertEqual(0, users.Count());
 }