Commits

lfoust committed e5b4917

Added GetModerators user method

Comments (0)

Files changed (7)

trunk/source/Stacky.Net35/StackyClient/UserMethods.cs

             });
             return new PagedList<Reputation>(response.Reputation, response);
         }
+
+        public virtual IPagedList<User> GetModerators()
+        {
+            return GetModerators(new UserOptions());
+        }
+
+        public virtual IPagedList<User> GetModerators(UserOptions options)
+        {
+            return GetUsers(options, new string[] { "moderators" });
+        }
     }
 }

trunk/source/Stacky/Enums/UserSort.cs

         /// </summary>
         Creation,
         /// <summary>
-        /// Oldest.
-        /// </summary>
-        Oldest,
-        /// <summary>
         /// Name.
         /// </summary>
         Name

trunk/source/Stacky/StackyClient/UserMethods.cs

                 key = apiKey
             }).Badges;
         }
+
+        public virtual IPagedList<User> GetModerators(int? page = null, int? pageSize = null, UserSort sortBy = UserSort.Reputation, SortDirection sortDirection = SortDirection.Descending, string filter = null, DateTime? fromDate = null, DateTime? toDate = null)
+        {
+            var response = MakeRequest<UserResponse>("users", new string[] { "moderators" }, new
+            {
+                key = apiKey,
+                page = page ?? null,
+                pagesize = pageSize ?? null,
+                filter = filter,
+                sort = sortBy.ToString().ToLower(),
+                order = GetSortDirection(sortDirection),
+                fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
+                todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null
+            });
+            return new PagedList<User>(response.Users, response);
+        }
     }
 }

trunk/source/Stacky/StackyClientAsync/UserMethods.cs

                 todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null
             }, (items) => onSuccess(new PagedList<Reputation>(items.Reputation, items)), onError);
         }
+
+        public void GetModerators(Action<IPagedList<User>> onSuccess, Action<ApiException> onError, int? page = null, int? pageSize = null, UserSort sortBy = UserSort.Reputation, SortDirection sortDirection = SortDirection.Descending, string filter = null, DateTime? fromDate = null, DateTime? toDate = null)
+        {
+            MakeRequest<UserResponse>("users", new string[] { "moderators" }, new
+            {
+                key = apiKey,
+                page = page ?? null,
+                pagesize = pageSize ?? null,
+                filter = filter,
+                sort = sortBy.ToString().ToLower(),
+                order = GetSortDirection(sortDirection),
+                fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
+                todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null
+            }, (response) => onSuccess(new PagedList<User>(response.Users, response)), onError);
+        }
     }
 }

trunk/source/Tests/Stacky.IntegrationTests/UserTests.cs

             Assert.IsTrue(users.TotalItems > 0);
         }
 
-        [TestMethod]        
-        public void User_GetUsers_Async()
-        {
-            bool completed = false;
-            ClientAsync.GetUsers(users =>
-                {
-                    Assert.IsNotNull(users);
-                    completed = true;
-                }, onError: error =>
-                {
-                    Assert.Fail(error.Message);
-                    completed = true;
-                });
-            while (!completed)
-                Thread.Sleep(10);
-        }
-
         [TestMethod]
         public void User_GetUserMentions()
         {
         }
 
         [TestMethod]
-        public void User_GetUserMentions_Async()
-        {
-            ClientAsync.GetUserMentions(22656, mentions => Assert.IsNotNull(mentions));
-        }
-
-        [TestMethod]
         public void User_GetQuestionAnswers()
         {
             var answers = Client.GetQuestionAnswers(31415);
         }
 
         [TestMethod]
-        public void User_GetQuestionAnswers_Async()
-        {
-            ClientAsync.GetQuestionAnswers(31415, answers => Assert.IsNotNull(answers));
-        }
-
-        [TestMethod]
         public void User_GetUserTimeline()
         {
             var events = Client.GetUserTimeline(22656);
         }
 
         [TestMethod]
-        public void User_GetUserTimeline_Async()
-        {
-            ClientAsync.GetUserTimeline(22656, events => Assert.IsNotNull(events));
-        }
-
-        [TestMethod]
         public void User_GetUserReputation()
         {
             var rep = Client.GetUserReputation(22656);
         }
 
         [TestMethod]
-        public void User_GetUserReputation_Async()
-        {
-            ClientAsync.GetUserReputation(22656, rep => Assert.IsNotNull(rep));
-        }
-
-        [TestMethod]
         public void User_Returns_Badge_Counts()
         {
             var user = Client.GetUser(22656);
         }
 
         [TestMethod]
-        public void User_GetUser_Async()
+        public void GetModerators()
         {
-            bool completed = false;
-            ClientAsync.GetUser(22656, user =>
-            {
-                Assert.IsNotNull(user);
-                completed = true;
-            }, onError: error =>
-            {
-                Assert.Fail(error.Message);
-                completed = true;
-            });
-            while (!completed)
-                Thread.Sleep(10);
+            var users = Client.GetModerators();
+            Assert.IsNotNull(users);
         }
     }
 }

trunk/source/Tests/Stacky.Net35.IntegrationTests/UserTests.cs

             Assert.IsFalse(String.IsNullOrEmpty(user.CommentsUrl));
             Assert.IsFalse(String.IsNullOrEmpty(user.ReputationUrl));
         }
+
+        [TestMethod]
+        public void GetModerators()
+        {
+            var users = Client.GetModerators();
+            Assert.IsNotNull(users);
+        }
     }
 }

trunk/source/Tests/Stacky.Silverlight.IntegrationTests/UserTests.cs

     [TestClass]
     public class UserTests : IntegrationTest
     {
-        [TestMethod]
+        [TestMethod, Asynchronous]
         public void User_GetUsers()
         {
             using (var context = new AsynchronusTestContext(this))
             }
         }
 
+        [TestMethod, Asynchronous]
+        public void User_GetModerators()
+        {
+            using (var context = new AsynchronusTestContext(this))
+            {
+                IPagedList<User> received = null;
+                ApiException exception = null;
+
+                bool completed = false;
+                EnqueueCallback(() =>
+                {
+                    Client.GetModerators(results =>
+                    {
+                        received = results;
+                        completed = true;
+                    },
+                    error =>
+                    {
+                        exception = error;
+                        completed = true;
+                    });
+                });
+                EnqueueConditional(() => completed);
+                EnqueueCallback(() => Assert.IsNull(exception));
+                EnqueueCallback(() => Assert.IsNotNull(received));
+            }
+        }
+
         /*
 
         [TestMethod]