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 65e64b6

Browse files
author
Hariharan Subramanian
committed
Added API's for Suggested Edits 🚀
1 parent ddd3c74 commit 65e64b6

File tree

6 files changed

+162
-9
lines changed

6 files changed

+162
-9
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Collections.Generic;
2+
using StackExchange.NET.Helpers;
3+
using StackExchange.NET.Interfaces;
4+
using StackExchange.NET.Models;
5+
6+
namespace StackExchange.NET.Clients
7+
{
8+
public partial class StackExchangeClient : ISuggestedEdits
9+
{
10+
/// <summary>
11+
/// The SuggestedEdits interface which lists all possible operations.
12+
/// </summary>
13+
public ISuggestedEdits SuggestedEdits => this;
14+
BaseResponse<SuggestedEdits> ISuggestedEdits.GetAllSuggestedEdits(SuggestedEditFilter filters)
15+
{
16+
var url = ApiUrlBuilder
17+
.Initialize(_apiKey)
18+
.ForClient(ClientType.Suggested_Edits)
19+
.WithFilter(filters)
20+
.GetApiUrl();
21+
22+
var response = _httpClient.GetAsync(url).Result.ReadAsJsonAsync<Data<SuggestedEdits>>().ValidateApiResponse();
23+
return response;
24+
}
25+
26+
BaseResponse<SuggestedEdits> ISuggestedEdits.GetSuggestedEditsByIds(List<string> ids,SuggestedEditFilter filters)
27+
{
28+
var url = ApiUrlBuilder.Initialize(_apiKey)
29+
.ForClient(ClientType.Suggested_Edits)
30+
.WithFilter(filters)
31+
.WithIds(ids)
32+
.GetApiUrl();
33+
34+
var response = _httpClient.GetAsync(url).Result.ReadAsJsonAsync<Data<SuggestedEdits>>().ValidateApiResponse();
35+
return response;
36+
}
37+
}
38+
}

‎StackExchange.NET/StackExchange.NET/Helpers/ApiUrlBuilder.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@ public ApiUrlBuilder(string apiKey)
2121
}
2222
public static IApiUrlHelper Initialize(string apikey) => new ApiUrlBuilder(apikey);
2323

24-
public ApiUrlBuilder ForClient(ClientType type,string route ="")
24+
public ApiUrlBuilder ForClient(ClientType type,string route ="")
2525
{
26-
if (string.IsNullOrEmpty(route) || string.IsNullOrWhiteSpace(route))
26+
//Some API url's have hyphens in it. Since its not possible to use Hyphens in enums, using Underscore and replacing it as a workaround!
27+
if (type.ToString().Contains("_"))
2728
{
28-
_apiUrl = $"{BaseUrl}{type.ToString().ToLower()}/";
29+
_apiUrl = $"{BaseUrl}{type.ToString().Replace("_","-").ToLower()}/";
2930
}
30-
else
31+
if(!(string.IsNullOrEmpty(route)||string.IsNullOrWhiteSpace(route)))
3132
{
3233
_apiUrl = $"{BaseUrl}{type.ToString().ToLower()}/{route}";
3334
}
34-
3535
return this;
3636
}
3737

38-
public ApiUrlBuilder WithFilter(Filter filter, string inName="")
38+
public ApiUrlBuilder WithFilter(Filter filter, string inName="")
3939
{
4040
MakeSure.ArgumentNotNull(filter, nameof(filter));
41-
41+
4242
if (string.IsNullOrEmpty(inName) || string.IsNullOrWhiteSpace(inName))
4343
{
4444
_filter = filter.GetQueryParams();
@@ -51,7 +51,7 @@ public ApiUrlBuilder WithFilter(Filter filter, string inName="")
5151
return this;
5252
}
5353

54-
public ApiUrlBuilder WithIds(List<string> ids,string route ="")
54+
public ApiUrlBuilder WithIds(List<string> ids,string route ="")
5555
{
5656
MakeSure.ArgumentNotNullOrEmptyEnumerable(ids, nameof(ids));
5757
var idsToEncode = string.Join(";", ids.ToArray());

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public enum ClientType
99
Badges,
1010
Comments,
1111
Posts,
12-
Questions
12+
Questions,
13+
Suggested_Edits
1314
}
1415
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Collections.Generic;
2+
using StackExchange.NET.Models;
3+
4+
namespace StackExchange.NET.Interfaces
5+
{
6+
public interface ISuggestedEdits
7+
{
8+
/// <summary>
9+
/// Returns all the suggested edits in the systems.
10+
/// </summary>
11+
/// <returns></returns>
12+
BaseResponse<SuggestedEdits> GetAllSuggestedEdits(SuggestedEditFilter filters);
13+
/// <summary>
14+
/// Returns suggested edits identified in ids.
15+
///
16+
/// {ids} can contain up to 100 semicolon delimited ids. To find ids programmatically look for suggested_edit_id on suggested_edit objects.
17+
/// </summary>
18+
/// <returns></returns>
19+
BaseResponse<SuggestedEdits> GetSuggestedEditsByIds(List<string> ids,SuggestedEditFilter filters);
20+
}
21+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
5+
namespace StackExchange.NET.Models
6+
{
7+
public class SuggestedEdits
8+
{
9+
[JsonProperty("proposing_user")]
10+
public ProposingUser ProposingUser { get; set; }
11+
12+
[JsonProperty("creation_date")]
13+
public long CreationDate { get; set; }
14+
15+
[JsonProperty("post_type")]
16+
public PostType PostType { get; set; }
17+
18+
[JsonProperty("post_id")]
19+
public long PostId { get; set; }
20+
21+
[JsonProperty("suggested_edit_id")]
22+
public long SuggestedEditId { get; set; }
23+
24+
[JsonProperty("comment")]
25+
public string Comment { get; set; }
26+
27+
[JsonProperty("rejection_date", NullValueHandling = NullValueHandling.Ignore)]
28+
public long? RejectionDate { get; set; }
29+
30+
[JsonProperty("tags", NullValueHandling = NullValueHandling.Ignore)]
31+
public List<string> Tags { get; set; }
32+
33+
[JsonProperty("title", NullValueHandling = NullValueHandling.Ignore)]
34+
public string Title { get; set; }
35+
36+
[JsonProperty("approval_date", NullValueHandling = NullValueHandling.Ignore)]
37+
public long? ApprovalDate { get; set; }
38+
}
39+
40+
public class ProposingUser
41+
{
42+
[JsonProperty("reputation")]
43+
public long Reputation { get; set; }
44+
45+
[JsonProperty("user_id")]
46+
public long UserId { get; set; }
47+
48+
[JsonProperty("user_type")]
49+
public UserType UserType { get; set; }
50+
51+
[JsonProperty("profile_image")]
52+
public Uri ProfileImage { get; set; }
53+
54+
[JsonProperty("display_name")]
55+
public string DisplayName { get; set; }
56+
57+
[JsonProperty("link")]
58+
public Uri Link { get; set; }
59+
60+
[JsonProperty("accept_rate", NullValueHandling = NullValueHandling.Ignore)]
61+
public long? AcceptRate { get; set; }
62+
}
63+
64+
public enum PostType
65+
{
66+
Answer, Question
67+
}
68+
69+
public enum UserType
70+
{
71+
Registered
72+
}
73+
74+
}

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

Lines changed: 19 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 によって変換されたページ (->オリジナル) /