Commits

lfoust  committed 52d6215

Added Revision, Search, and Similiar methods

  • Participants
  • Parent commits 8682032
  • Branches V2.0

Comments (0)

Files changed (4)

File trunk/data/V2.0 Upgrade Checklist.xlsx

Binary file modified.

File trunk/source/Stacky/StackyClient/QuestionMethods.cs

             });
             return new PagedList<Question>(response);
         }
+
+        // <summary>
+        /// See https://api.stackexchange.com/docs/search
+        /// </summary>
+        /// TODO: Fix Sort
+        public IPagedList<Question> SearchQuestions(QuestionSort? sortBy = null, SortDirection? sortDirection = null, int? page = null, int? pageSize = null, DateTime? fromDate = null, DateTime? toDate = null, DateTime? min = null, DateTime? max = null, string[] tagged = null, string[] notTagged = null, string inTitle = null, string filter = null)
+        {
+            if (((tagged != null && tagged.Length == 0) || tagged == null) &&
+                ((notTagged != null && notTagged.Length == 0) || notTagged == null))
+            {
+                throw new ArgumentException("At least one of tagged or intitle must be set on this method");
+            }
+
+            var response = MakeRequest<Question>("search", null, new
+            {
+                site = this.SiteUrlName,
+                page = page ?? null,
+                pagesize = pageSize ?? null,
+                fromdate = GetDateValue(fromDate),
+                todate = GetDateValue(toDate),
+                sort = GetEnumValue(sortBy),
+                order = GetSortDirection(sortDirection),
+                min = GetDateValue(min),
+                max = GetDateValue(max),
+                tagged = tagged != null ? String.Join(";", tagged) : null,
+                nottagged = notTagged != null ? String.Join(";", notTagged) : null,
+                intitle = inTitle,
+                filter = filter
+            });
+            return new PagedList<Question>(response);
+        }
+
+        // <summary>
+        /// See https://api.stackexchange.com/docs/similar
+        /// </summary>
+        /// TODO: Fix Sort
+        public IPagedList<Question> SimiliarQuestions(string title, QuestionSort? sortBy = null, SortDirection? sortDirection = null, int? page = null, int? pageSize = null, DateTime? fromDate = null, DateTime? toDate = null, DateTime? min = null, DateTime? max = null, string[] tagged = null, string[] notTagged = null, string filter = null)
+        {
+            var response = MakeRequest<Question>("similar", null, new
+            {
+                site = this.SiteUrlName,
+                page = page ?? null,
+                pagesize = pageSize ?? null,
+                fromdate = GetDateValue(fromDate),
+                todate = GetDateValue(toDate),
+                sort = GetEnumValue(sortBy),
+                order = GetSortDirection(sortDirection),
+                min = GetDateValue(min),
+                max = GetDateValue(max),
+                tagged = tagged != null ? String.Join(";", tagged) : null,
+                nottagged = notTagged != null ? String.Join(";", notTagged) : null,
+                title = title,
+                filter = filter
+            });
+            return new PagedList<Question>(response);
+        }
     }
 }

File trunk/source/Stacky/StackyClient/RevisionMethods.cs

 {
     public partial class StackyClient
     {
-        public virtual IEnumerable<Revision> GetRevisions(IEnumerable<int> ids, DateTime? fromDate = null, DateTime? toDate = null)
+        /// <summary>
+        /// See https://api.stackexchange.com/docs/revisions-by-guids
+        /// </summary>
+        public IPagedList<Revision> GetRevisions(IEnumerable<string> ids, int? page = null, int? pageSize = null, DateTime? fromDate = null, DateTime? toDate = null, string filter = null)
         {
-            return MakeRequest<Revision>("revisions", new string[] { ids.Vectorize() }, new
-            {
-                site = this.SiteUrlName,
-                fromdate = fromDate.HasValue ? (long?)fromDate.Value.ToUnixTime() : null,
-                todate = toDate.HasValue ? (long?)toDate.Value.ToUnixTime() : null
-            }).Items;
+            return Execute<Revision>("revisions", new string[] { ids.Vectorize() },
+                null, null, page, pageSize, fromDate, toDate, null, null, filter);
         }
 
-        public virtual IEnumerable<Revision> GetRevisions(int id, DateTime? fromDate = null, DateTime? toDate = null)
+        /// <summary>
+        /// See https://api.stackexchange.com/docs/revisions-by-guids
+        /// </summary>
+        public IPagedList<Revision> GetRevisions(IEnumerable<Guid> ids, int? page = null, int? pageSize = null, DateTime? fromDate = null, DateTime? toDate = null, string filter = null)
         {
-            return GetRevisions(id.ToArray(), fromDate, toDate);
+            return GetRevisions(ids.Select(i => i.ToString()), page, pageSize, fromDate, toDate, filter);
         }
 
-        public virtual Revision GetRevision(int id, Guid revision)
+        /// <summary>
+        /// See https://api.stackexchange.com/docs/revisions-by-guids
+        /// </summary>
+        public Revision GetRevision(string id, int? page = null, int? pageSize = null, DateTime? fromDate = null, DateTime? toDate = null, string filter = null)
         {
-            return MakeRequest<Revision>("revisions", new string[] { id.ToString(), revision.ToString() }, new
-            {
-                site = this.SiteUrlName,
-            }).Items.FirstOrDefault();
+            return GetRevisions(new string[] { id }, page, pageSize, fromDate, toDate, filter).FirstOrDefault();
+        }
+
+        /// <summary>
+        /// See https://api.stackexchange.com/docs/revisions-by-guids
+        /// </summary>
+        public Revision GetRevision(Guid id, int? page = null, int? pageSize = null, DateTime? fromDate = null, DateTime? toDate = null, string filter = null)
+        {
+            return GetRevisions(new string[] { id.ToString() }, page, pageSize, fromDate, toDate, filter).FirstOrDefault();
         }
     }
 }

File trunk/source/Tests/Stacky.IntegrationTests/RevisionTests.cs

     [TestClass]
     public class RevisionTests : IntegrationTest
     {
-        [TestMethod]
-        public void Revision_GetRevisions()
-        {
-            var revisions = Client.GetRevisions(31415);
-            Assert.IsNotNull(revisions);
-        }
-
-        [TestMethod]
-        public void Revision_GetRevisions_Async()
-        {
-            ClientAsync.GetRevisions(31415, revisions => Assert.IsNotNull(revisions), error => Assert.Fail());
-        }
-
-        [TestMethod]
-        public void Revision_GetRevision()
-        {
-            var revision = Client.GetRevision(31415, Guid.Parse("5a1fd2ac-421a-43a9-a2a3-2e9b5afe1b23"));
-            Assert.IsNotNull(revision);
-        }
-
-        [TestMethod]
-        public void Revision_GetRevision_Async()
-        {
-            ClientAsync.GetRevision(31415, Guid.Parse("5a1fd2ac-421a-43a9-a2a3-2e9b5afe1b23"), revision => Assert.IsNotNull(revision));
-        }
+        
     }
 }