Skip to content

Commit

Permalink
New API support (#15)
Browse files Browse the repository at this point in the history
* Fix CoyoteHandler to work with new Coyote API format
* Change endpoints to new dev server
  • Loading branch information
ktos authored Jan 30, 2020
1 parent 307efaf commit 5bfc4f5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 38 deletions.
16 changes: 8 additions & 8 deletions src/CoyoteApi/CoyoteHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ public async Task<Post> GetSinglePost(int postId)

var post = new Post
{
created_at = result.data.created_at,
forum_id = result.data.forum_id,
id = result.data.id,
text = result.data.text,
topic_id = result.data.topic_id,
user = result.data.user,
user_name = result.data.user_name,
url = result.data.url
created_at = result.created_at,
forum_id = result.forum_id,
id = result.id,
html = result.html,
topic_id = result.topic_id,
user = result.user,
user_name = result.user_name,
url = result.url
};

return post;
Expand Down
10 changes: 5 additions & 5 deletions src/CoyoteApi/Endpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,26 @@ public static class Endpoints
/// <summary>
/// Coyote API endpoint for getting new posts
/// </summary>
public static string PostsApi => IsDebug ? "http://api.dev.4programmers.info/v1/posts" : "https://api.4programmers.net/v1/posts";
public static string PostsApi => IsDebug ? "http://api.4programmers.dev/v1/posts" : "https://api.4programmers.net/v1/posts";

/// <summary>
/// Coyote URL for main page
/// </summary>
public static string MainPage => IsDebug ? "http://dev.4programmers.info/" : "https://4programmers.net";
public static string MainPage => IsDebug ? "http://4programmers.dev/" : "https://4programmers.net";

/// <summary>
/// Coyote URL for login page
/// </summary>
public static string LoginPage => IsDebug ? "http://dev.4programmers.info/Login" : "https://4programmers.net/Login";
public static string LoginPage => IsDebug ? "http://4programmers.dev/Login" : "https://4programmers.net/Login";

/// <summary>
/// Coyote URL for comment to a post link
/// </summary>
public static string CommentPage => IsDebug ? "http://dev.4programmers.info/Forum/Comment" : "https://4programmers.net/Forum/Comment";
public static string CommentPage => IsDebug ? "http://4programmers.dev/Forum/Comment" : "https://4programmers.net/Forum/Comment";

/// <summary>
/// Coyote URL to logout link
/// </summary>
public static string LogoutPage => IsDebug ? "http://dev.4programmers.info/Logout" : "https://4programmers.net/Logout";
public static string LogoutPage => IsDebug ? "http://4programmers.dev/Logout" : "https://4programmers.net/Logout";
}
}
10 changes: 2 additions & 8 deletions src/CoyoteApi/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ public class PostsApiResult

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class SinglePostApiResult
{
public SinglePost data { get; set; }
}

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class SinglePost
{
public int id { get; set; }
public object user_name { get; set; }
Expand All @@ -61,7 +55,7 @@ public class SinglePost
public int topic_id { get; set; }
public DateTime created_at { get; set; }
public User user { get; set; }
public string text { get; set; }
public string html { get; set; }
public string url { get; set; }
public IEnumerable<Comment> comments { get; set; }
}
Expand Down Expand Up @@ -90,7 +84,7 @@ public class Post
public int topic_id { get; set; }
public DateTime created_at { get; set; }
public User user { get; set; }
public string text { get; set; }
public string html { get; set; }
public string url { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion src/PostAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public List<PostProblems> Analyze(CoyoteApi.Post post)

private NotFormattedCodeFound CheckForUnformattedCode(CoyoteApi.Post post)
{
var text = HtmlCleaner.RemoveProperCode(post.text);
var text = HtmlCleaner.RemoveProperCode(post.html);
text = HtmlCleaner.RemoveDownloadLinks(text);
text = HtmlCleaner.RemoveQuotes(text);

Expand Down
18 changes: 9 additions & 9 deletions test/BotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async void AnalyzePostAsync_Post_ShouldUpdateAlreadyAnalyzed()
bot.IgnoreAlreadyAnalyzed = true;
bot.LoadAlreadyAnalyzed();

await bot.AnalyzePostAsync(new Post() { id = 1, text = "" });
await bot.AnalyzePostAsync(new Post() { id = 1, html = "" });

Assert.Single(bot.AlreadyAnalyzedDatabase);
Assert.Equal(1, bot.AlreadyAnalyzedDatabase.First());
Expand All @@ -82,8 +82,8 @@ public async void AnalyzePostAsync_SamePostIdTestedForSecondTime_ShouldBeIgnored
bot.IgnoreAlreadyAnalyzed = true;
bot.LoadAlreadyAnalyzed();

await bot.AnalyzePostAsync(new Post() { id = 1, text = "one text" });
await bot.AnalyzePostAsync(new Post() { id = 1, text = "different text" });
await bot.AnalyzePostAsync(new Post() { id = 1, html = "one text" });
await bot.AnalyzePostAsync(new Post() { id = 1, html = "different text" });

var logs = GetFakeLogs();

Expand All @@ -98,7 +98,7 @@ public async void AnalyzePostAsync_PostFromBlacklist_ShouldBeIgnored()
bot.LoadAlreadyAnalyzed();
bot.BlacklistDefinition = "1";

await bot.AnalyzePostAsync(new Post() { id = 1, text = "", forum_id = 1 });
await bot.AnalyzePostAsync(new Post() { id = 1, html = "", forum_id = 1 });
var logs = GetFakeLogs();

Assert.Equal("[Debug] Ignoring post 1 because of blacklist", logs.Last());
Expand All @@ -121,11 +121,11 @@ public void Endpoints_WhenDebug_ShouldBeBasedOn4pinfo()
{
Endpoints.IsDebug = true;

Assert.Contains("dev.4programmers.info", Endpoints.CommentPage);
Assert.Contains("dev.4programmers.info", Endpoints.LoginPage);
Assert.Contains("dev.4programmers.info", Endpoints.MainPage);
Assert.Contains("dev.4programmers.info", Endpoints.LogoutPage);
Assert.Contains("dev.4programmers.info", Endpoints.PostsApi);
Assert.Contains("4programmers.dev", Endpoints.CommentPage);
Assert.Contains("4programmers.dev", Endpoints.LoginPage);
Assert.Contains("4programmers.dev", Endpoints.MainPage);
Assert.Contains("4programmers.dev", Endpoints.LogoutPage);
Assert.Contains("4programmers.dev", Endpoints.PostsApi);
}
}
}
Loading

0 comments on commit 5bfc4f5

Please sign in to comment.