Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f0bbf40

Browse files
author
Hariharan Subramanian
committed
Completed IQuestions implementation
1 parent 7dc8250 commit f0bbf40

File tree

10 files changed

+322
-8
lines changed

10 files changed

+322
-8
lines changed

‎.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,5 @@ healthchecksdb
349349
MigrationBackup/
350350

351351
# Ionide (cross platform F# VS Code tools) working folder
352-
.ionide/
352+
.ionide/
353+
/StackExchange.NET/Tests/QuestionsClient.cs
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using StackExchange.NET.Helpers;
4+
using StackExchange.NET.Interfaces;
5+
using StackExchange.NET.Models;
6+
7+
namespace StackExchange.NET.Clients
8+
{
9+
public partial class StackExchangeClient : IQuestions
10+
{
11+
/// <summary>
12+
/// StackExchangeClient used to perform operations on APIs.
13+
/// </summary>
14+
public IQuestions Questions => this;
15+
BaseResponse<Question> IQuestions.GetAllQuestions(QuestionFilters filters)
16+
{
17+
var url = ApiUrlBuilder
18+
.Initialize(_apiKey)
19+
.ForClient(ClientType.Questions)
20+
.WithFilter(filters)
21+
.GetApiUrl();
22+
var response = _httpClient.GetAsync(url).Result.ReadAsJsonAsync<Data<Question>>().ValidateApiResponse();
23+
return response;
24+
}
25+
26+
BaseResponse<Question> IQuestions.GetQuestionsByIds(List<string> ids, QuestionFilters filters)
27+
{
28+
var url = ApiUrlBuilder.Initialize(_apiKey)
29+
.ForClient(ClientType.Questions)
30+
.WithFilter(filters)
31+
.WithIds(ids)
32+
.GetApiUrl();
33+
var response = _httpClient.GetAsync(url).Result.ReadAsJsonAsync<Data<Question>>().ValidateApiResponse();
34+
return response;
35+
}
36+
37+
BaseResponse<Answer> IQuestions.GetAnswersByQuestionIds(List<string> ids, QuestionFilters filters)
38+
{
39+
var url = ApiUrlBuilder.Initialize(_apiKey)
40+
.ForClient(ClientType.Questions)
41+
.WithFilter(filters)
42+
.WithIds(ids)
43+
.GetApiUrl();
44+
var response = _httpClient.GetAsync(url).Result.ReadAsJsonAsync<Data<Answer>>().ValidateApiResponse();
45+
return response;
46+
}
47+
48+
BaseResponse<Comment> IQuestions.GetCommentsByQuestionIds(List<string> ids, QuestionFilters filters)
49+
{
50+
var url = ApiUrlBuilder.Initialize(_apiKey)
51+
.ForClient(ClientType.Questions)
52+
.WithFilter(filters)
53+
.WithIds(ids)
54+
.GetApiUrl();
55+
var response = _httpClient.GetAsync(url).Result.ReadAsJsonAsync<Data<Comment>>().ValidateApiResponse();
56+
return response;
57+
}
58+
59+
BaseResponse<Question> IQuestions.GetLinkedQuestions(List<string> ids, QuestionFilters filters)
60+
{
61+
var url = ApiUrlBuilder.Initialize(_apiKey)
62+
.ForClient(ClientType.Questions)
63+
.WithFilter(filters)
64+
.WithIds(ids,"linked")
65+
.GetApiUrl();
66+
var response = _httpClient.GetAsync(url).Result.ReadAsJsonAsync<Data<Question>>().ValidateApiResponse();
67+
return response;
68+
}
69+
70+
BaseResponse<Question> IQuestions.GetRelatedQuestions(List<string> ids, QuestionFilters filters)
71+
{
72+
var url = ApiUrlBuilder.Initialize(_apiKey)
73+
.ForClient(ClientType.Questions)
74+
.WithFilter(filters)
75+
.WithIds(ids,"related")
76+
.GetApiUrl();
77+
var response = _httpClient.GetAsync(url).Result.ReadAsJsonAsync<Data<Question>>().ValidateApiResponse();
78+
return response;
79+
}
80+
81+
BaseResponse<Question> IQuestions.GetTimeLine(List<string> ids, QuestionFilters filters)
82+
{
83+
throw new NotImplementedException();
84+
}
85+
86+
BaseResponse<Question> IQuestions.GetFeaturedQuestions(QuestionFilters filters)
87+
{
88+
var url = ApiUrlBuilder
89+
.Initialize(_apiKey)
90+
.ForClient(ClientType.Questions,"featured")
91+
.WithFilter(filters)
92+
.GetApiUrl();
93+
var response = _httpClient.GetAsync(url).Result.ReadAsJsonAsync<Data<Question>>().ValidateApiResponse();
94+
return response;
95+
}
96+
97+
BaseResponse<Question> IQuestions.GetQuestionsWithNoAnswers(QuestionFilters filters)
98+
{
99+
var url = ApiUrlBuilder
100+
.Initialize(_apiKey)
101+
.ForClient(ClientType.Questions,"no-answers")
102+
.WithFilter(filters)
103+
.GetApiUrl();
104+
var response = _httpClient.GetAsync(url).Result.ReadAsJsonAsync<Data<Question>>().ValidateApiResponse();
105+
return response;
106+
}
107+
108+
BaseResponse<Question> IQuestions.GetUnansweredQuestions(QuestionFilters filters)
109+
{
110+
var url = ApiUrlBuilder
111+
.Initialize(_apiKey)
112+
.ForClient(ClientType.Questions,"unanswered")
113+
.WithFilter(filters)
114+
.GetApiUrl();
115+
var response = _httpClient.GetAsync(url).Result.ReadAsJsonAsync<Data<Question>>().ValidateApiResponse();
116+
return response;
117+
}
118+
}
119+
}

‎StackExchange.NET/StackExchange.NET/Helpers/ClientType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public enum ClientType
88
Answers,
99
Badges,
1010
Comments,
11-
Posts
11+
Posts,
12+
Questions
1213
}
1314
}

‎StackExchange.NET/StackExchange.NET/Interfaces/IQuestions.cs

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,96 @@
33

44
namespace StackExchange.NET.Interfaces
55
{
6-
interface IQuestions
6+
/// <summary>
7+
/// The Questions interface which lists all possible operations.
8+
/// </summary>
9+
public interface IQuestions
710
{
11+
/// <summary>
12+
/// <para>Gets all the questions on the site.</para>
13+
/// </summary>
14+
/// <param name="filters">The Question filters.</param>
15+
/// <returns></returns>
816
BaseResponse<Question> GetAllQuestions(QuestionFilters filters);
17+
/// <summary>
18+
/// Returns the questions identified in {ids}.
19+
///
20+
/// This is most useful for fetching fresh data when maintaining a cache of question ids, or polling for changes.
21+
/// </summary>
22+
/// <param name="ids"></param>
23+
/// <param name="filters"></param>
24+
/// <returns></returns>
925
BaseResponse<Question> GetQuestionsByIds(List<string> ids, QuestionFilters filters);
10-
BaseResponse<Question> GetAnswersByQuestionIds(List<string> ids, QuestionFilters filters);
11-
BaseResponse<Question> GetCommentsByQuestionIds(List<string> ids, QuestionFilters filters);
26+
/// <summary>
27+
/// Gets the answers to a set of questions identified in id.
28+
///
29+
/// This method is most useful if you have a set of interesting questions, and you wish to obtain all of their answers at once or if you are polling for new or updates answers (in conjunction with sort=activity).
30+
/// </summary>
31+
/// <param name="ids"></param>
32+
/// <param name="filters"></param>
33+
/// <returns></returns>
34+
BaseResponse<Answer> GetAnswersByQuestionIds(List<string> ids, QuestionFilters filters);
35+
/// <summary>
36+
/// Gets the comments on a question.
37+
///
38+
/// If you know that you have an question id and need the comments, use this method. If you know you have a answer id, use GetAnswersWithIds. If you are unsure, use GetPostsWithIds.
39+
/// </summary>
40+
/// <param name="ids"></param>
41+
/// <param name="filters"></param>
42+
/// <returns></returns>
43+
BaseResponse<Comment> GetCommentsByQuestionIds(List<string> ids, QuestionFilters filters);
44+
/// <summary>
45+
/// Gets questions which link to those questions identified in {ids}.
46+
///
47+
/// This method only considers questions that are linked within a site, and will never return questions from another Stack Exchange site.
48+
///
49+
/// A question is considered "linked" when it explicitly includes a hyperlink to another question. There are no other heuristics.
50+
/// </summary>
51+
/// <param name="ids"></param>
52+
/// <param name="filters"></param>
53+
/// <returns></returns>
1254
BaseResponse<Question> GetLinkedQuestions(List<string> ids, QuestionFilters filters);
55+
/// <summary>
56+
/// Returns questions that the site considers related to those identified in {ids}.
57+
///
58+
/// The algorithm for determining if questions are related is not documented, and subject to change at any time. Furthermore, these values are very heavily cached, and may not update immediately after a question has been editted. It is also not guaranteed that a question will be considered related to any number (even non-zero) of questions, and a consumer should be able to handle a variable number of returned questions.
59+
/// </summary>
60+
/// <param name="ids"></param>
61+
/// <param name="filters"></param>
62+
/// <returns></returns>
1363
BaseResponse<Question> GetRelatedQuestions(List<string> ids, QuestionFilters filters);
64+
/// <summary>
65+
/// Returns a subset of the events that have happened to the questions identified in id.
66+
///
67+
/// This provides data similar to that found on a question's timeline page.
68+
///
69+
/// Voting data is scrubbed to deter inferencing of voter identity.
70+
/// </summary>
71+
/// <param name="ids"></param>
72+
/// <param name="filters"></param>
73+
/// <returns></returns>
1474
BaseResponse<Question> GetTimeLine(List<string> ids, QuestionFilters filters);
75+
/// <summary>
76+
/// Returns all the questions with active bounties in the system.
77+
///
78+
/// The sorts accepted by this method operate on the following fields of the question object:
79+
/// </summary>
80+
/// <param name="filters"></param>
81+
/// <returns></returns>
1582
BaseResponse<Question> GetFeaturedQuestions(QuestionFilters filters);
16-
BaseResponse<Question> GetQuestionsWithNoAnswers();
17-
BaseResponse<Question> GetUnansweredQuestions();
83+
/// <summary>
84+
/// Returns questions which have received no answers.
85+
///
86+
/// Compare with /questions/unanswered which merely returns questions that the sites consider insufficiently well answered.
87+
/// </summary>
88+
/// <returns></returns>
89+
BaseResponse<Question> GetQuestionsWithNoAnswers(QuestionFilters filters);
90+
/// <summary>
91+
/// Returns questions the site considers to be unanswered.
92+
///
93+
/// Note that just because a question has an answer, that does not mean it is considered answered. While the rules are subject to change, at this time a question must have at least one upvoted answer to be considered answered.
94+
/// </summary>
95+
/// <returns></returns>
96+
BaseResponse<Question> GetUnansweredQuestions(QuestionFilters filters);
1897
}
1998
}

‎StackExchange.NET/StackExchange.NET/Models/Answers.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public class Answer
2929
public long QuestionId { get; set; }
3030
}
3131

32+
/// <summary>
33+
/// This filter should be used while using the Answers methods.
34+
/// </summary>
3235
public class AnswerFilters : Filter
3336
{
3437
public AnswerFilters()

‎StackExchange.NET/StackExchange.NET/Models/Questions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class QuestionFilters : Filter
6161
public QuestionFilters()
6262
{
6363
Order = Models.Order.Desc;
64-
Sort = QuestionSort.Week;
64+
Sort = QuestionSort.Hot;
6565
Site = "stackoverflow";
6666
}
6767
}

‎StackExchange.NET/StackExchange.NET/StackExchange.NET.xml

Lines changed: 111 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /