diff --git a/GuardianClient/GuardianClient.Tests/GetItemAsyncTests.cs b/GuardianClient/GuardianClient.Tests/GetItemAsyncTests.cs index d34547c..6a2b7d2 100644 --- a/GuardianClient/GuardianClient.Tests/GetItemAsyncTests.cs +++ b/GuardianClient/GuardianClient.Tests/GetItemAsyncTests.cs @@ -10,27 +10,27 @@ public class GetItemAsyncTests : TestBase public async Task GetItemAsync_WithValidId_ReturnsItem() { // First get a valid item ID from search - var searchResult = await ApiClient.SearchAsync(new GuardianApiContentSearchOptions + var searchResult = await Client.SearchAsync(new SearchOptions { Query = "technology", - PageOptions = new GuardianApiContentPageOptions { PageSize = 1 } + PageOptions = new PageOptions { PageSize = 1 } }); - searchResult.ShouldNotBeNull("Search should return results"); - searchResult.Results.Count.ShouldBe(1, "Should return exactly one result"); + searchResult.ShouldNotBeNull(); + searchResult.Results.Count.ShouldBe(1); var contentItem = searchResult.Results.First(); var itemId = contentItem.Id; // Now get the specific item - var singleItemResult = await ApiClient.GetItemAsync(itemId, - new GuardianApiContentAdditionalInformationOptions { ShowFields = [GuardianApiContentShowFieldsOption.Body] }); + var singleItemResult = await Client.GetItemAsync(itemId, + new AdditionalInformationOptions { ShowFields = [ContentField.Body] }); - singleItemResult.ShouldNotBeNull("GetItem result should not be null"); - singleItemResult.Status.ShouldBe("ok", "API response status should be 'ok'"); - singleItemResult.Content.ShouldNotBeNull("Content should not be null"); - singleItemResult.Content.Id.ShouldBe(itemId, "Returned content ID should match requested ID"); - singleItemResult.Content.WebTitle.ShouldNotBeNullOrEmpty("Content should have a title"); - singleItemResult.Content.Fields.ShouldNotBeNull("Fields should be populated when ShowFields is specified"); + singleItemResult.ShouldNotBeNull(); + singleItemResult.Status.ShouldBe("ok"); + singleItemResult.Content.ShouldNotBeNull(); + singleItemResult.Content.Id.ShouldBe(itemId); + singleItemResult.Content.WebTitle.ShouldNotBeNullOrEmpty(); + singleItemResult.Content.Fields.ShouldNotBeNull(); Console.WriteLine($"Retrieved item: {singleItemResult.Content.WebTitle}"); Console.WriteLine($"Item ID: {singleItemResult.Content.Id}"); @@ -51,7 +51,7 @@ public async Task GetItemAsync_WithInvalidId_ThrowsException() var exception = await Should.ThrowAsync(async () => { - await ApiClient.GetItemAsync(invalidId); + await Client.GetItemAsync(invalidId); }); Console.WriteLine($"Expected exception for invalid ID: {exception.Message}"); @@ -62,7 +62,7 @@ public async Task GetItemAsync_WithNullId_ThrowsArgumentException() { var exception = await Should.ThrowAsync(async () => { - await ApiClient.GetItemAsync(null!); + await Client.GetItemAsync(null!); }); Console.WriteLine($"Expected exception for null ID: {exception.Message}"); @@ -73,7 +73,7 @@ public async Task GetItemAsync_WithEmptyId_ThrowsArgumentException() { var exception = await Should.ThrowAsync(async () => { - await ApiClient.GetItemAsync(""); + await Client.GetItemAsync(""); }); Console.WriteLine($"Expected exception for empty ID: {exception.Message}"); @@ -83,30 +83,30 @@ public async Task GetItemAsync_WithEmptyId_ThrowsArgumentException() public async Task GetItemAsync_WithShowFields_ReturnsEnhancedContent() { // Get a valid item ID - var searchResult = await ApiClient.SearchAsync(new GuardianApiContentSearchOptions + var searchResult = await Client.SearchAsync(new SearchOptions { Query = "politics", - PageOptions = new GuardianApiContentPageOptions { PageSize = 1 } + PageOptions = new PageOptions { PageSize = 1 } }); var itemId = searchResult.Results.First().Id; // Request with multiple fields - var result = await ApiClient.GetItemAsync(itemId, - new GuardianApiContentAdditionalInformationOptions + var result = await Client.GetItemAsync(itemId, + new AdditionalInformationOptions { ShowFields = [ - GuardianApiContentShowFieldsOption.Headline, - GuardianApiContentShowFieldsOption.Body, - GuardianApiContentShowFieldsOption.Byline, - GuardianApiContentShowFieldsOption.Thumbnail + ContentField.Headline, + ContentField.Body, + ContentField.Byline, + ContentField.Thumbnail ] }); result.ShouldNotBeNull(); - result.Content.Fields.ShouldNotBeNull("Fields should be populated"); - result.Content.Fields.Headline.ShouldNotBeNullOrEmpty("Headline should be populated"); + result.Content.Fields.ShouldNotBeNull(); + result.Content.Fields.Headline.ShouldNotBeNullOrEmpty(); Console.WriteLine($"Enhanced content for: {result.Content.WebTitle}"); Console.WriteLine($"Headline: {result.Content.Fields.Headline}"); @@ -118,24 +118,24 @@ public async Task GetItemAsync_WithShowFields_ReturnsEnhancedContent() public async Task GetItemAsync_WithShowTags_ReturnsContentWithTags() { // Get a valid item ID - var searchResult = await ApiClient.SearchAsync(new GuardianApiContentSearchOptions + var searchResult = await Client.SearchAsync(new SearchOptions { Query = "sport", - PageOptions = new GuardianApiContentPageOptions { PageSize = 1 } + PageOptions = new PageOptions { PageSize = 1 } }); var itemId = searchResult.Results.First().Id; // Request with tags - var result = await ApiClient.GetItemAsync(itemId, - new GuardianApiContentAdditionalInformationOptions + var result = await Client.GetItemAsync(itemId, + new AdditionalInformationOptions { - ShowTags = [GuardianApiContentShowTagsOption.Keyword, GuardianApiContentShowTagsOption.Tone, GuardianApiContentShowTagsOption.Type] + ShowTags = [ContentTag.Keyword, ContentTag.Tone, ContentTag.Type] }); result.ShouldNotBeNull(); - result.Content.Tags.ShouldNotBeNull("Tags should be populated"); - result.Content.Tags.Count.ShouldBeGreaterThan(0, "Should have at least one tag"); + result.Content.Tags.ShouldNotBeNull(); + result.Content.Tags.Count.ShouldBeGreaterThan(0); Console.WriteLine($"Content '{result.Content.WebTitle}' has {result.Content.Tags.Count} tags:"); foreach (var tag in result.Content.Tags.Take(5)) // Show first 5 tags @@ -148,19 +148,19 @@ public async Task GetItemAsync_WithShowTags_ReturnsContentWithTags() public async Task GetItemAsync_WithShowElements_ReturnsContentWithElements() { // Get a valid item ID - var searchResult = await ApiClient.SearchAsync(new GuardianApiContentSearchOptions + var searchResult = await Client.SearchAsync(new SearchOptions { Query = "music", - PageOptions = new GuardianApiContentPageOptions { PageSize = 1 } + PageOptions = new PageOptions { PageSize = 1 } }); var itemId = searchResult.Results.First().Id; // Request with elements - var result = await ApiClient.GetItemAsync(itemId, - new GuardianApiContentAdditionalInformationOptions + var result = await Client.GetItemAsync(itemId, + new AdditionalInformationOptions { - ShowElements = [GuardianApiContentShowElementsOption.Image, GuardianApiContentShowElementsOption.Video] + ShowElements = [ContentElement.Image, ContentElement.Video] }); result.ShouldNotBeNull(); @@ -181,17 +181,17 @@ public async Task GetItemAsync_WithShowElements_ReturnsContentWithElements() public async Task GetItemAsync_WithShowBlocks_ReturnsContentWithBlocks() { // Get a valid item ID - var searchResult = await ApiClient.SearchAsync(new GuardianApiContentSearchOptions + var searchResult = await Client.SearchAsync(new SearchOptions { Query = "news", - PageOptions = new GuardianApiContentPageOptions { PageSize = 1 } + PageOptions = new PageOptions { PageSize = 1 } }); var itemId = searchResult.Results.First().Id; // Request with blocks using string array (as it's still string-based) - var result = await ApiClient.GetItemAsync(itemId, - new GuardianApiContentAdditionalInformationOptions + var result = await Client.GetItemAsync(itemId, + new AdditionalInformationOptions { ShowBlocks = ["main", "body"] }); @@ -214,27 +214,27 @@ public async Task GetItemAsync_WithShowBlocks_ReturnsContentWithBlocks() public async Task GetItemAsync_WithAllOptions_ReturnsFullyEnhancedContent() { // Get a valid item ID - var searchResult = await ApiClient.SearchAsync(new GuardianApiContentSearchOptions + var searchResult = await Client.SearchAsync(new SearchOptions { Query = "culture", - PageOptions = new GuardianApiContentPageOptions { PageSize = 1 } + PageOptions = new PageOptions { PageSize = 1 } }); var itemId = searchResult.Results.First().Id; // Request with all enhancement options - var result = await ApiClient.GetItemAsync(itemId, - new GuardianApiContentAdditionalInformationOptions + var result = await Client.GetItemAsync(itemId, + new AdditionalInformationOptions { - ShowFields = [GuardianApiContentShowFieldsOption.All], - ShowTags = [GuardianApiContentShowTagsOption.All], - ShowElements = [GuardianApiContentShowElementsOption.All], + ShowFields = [ContentField.All], + ShowTags = [ContentTag.All], + ShowElements = [ContentElement.All], ShowBlocks = ["all"] }); result.ShouldNotBeNull(); - result.Content.Fields.ShouldNotBeNull("All fields should be populated"); - result.Content.Tags.ShouldNotBeNull("All tags should be populated"); + result.Content.Fields.ShouldNotBeNull(); + result.Content.Tags.ShouldNotBeNull(); Console.WriteLine($"Fully enhanced content: {result.Content.WebTitle}"); Console.WriteLine($" Fields populated: Yes"); diff --git a/GuardianClient/GuardianClient.Tests/GuardianApiClientIntegrationTests.cs b/GuardianClient/GuardianClient.Tests/GuardianApiClientIntegrationTests.cs index 22bcba9..87629f9 100644 --- a/GuardianClient/GuardianClient.Tests/GuardianApiClientIntegrationTests.cs +++ b/GuardianClient/GuardianClient.Tests/GuardianApiClientIntegrationTests.cs @@ -9,41 +9,41 @@ public class GuardianApiClientIntegrationTests : TestBase [TestMethod] public void ApiClient_ShouldNotBeNull() { - ApiClient.ShouldNotBeNull("API client should be properly initialized"); - ApiClient.ShouldBeAssignableTo("API client should implement the interface"); + Client.ShouldNotBeNull(); + Client.ShouldBeAssignableTo(); } [TestMethod] public async Task EndToEnd_SearchAndGetItem_WorksTogether() { // Search for content - var searchResult = await ApiClient.SearchAsync(new GuardianApiContentSearchOptions + var searchResult = await Client.SearchAsync(new SearchOptions { Query = "artificial intelligence", - PageOptions = new GuardianApiContentPageOptions { PageSize = 1 }, - FilterOptions = new GuardianApiContentFilterOptions + PageOptions = new PageOptions { PageSize = 1 }, + FilterOptions = new FilterOptions { Section = "technology" } }); - searchResult.ShouldNotBeNull("Search should return results"); - searchResult.Results.Count.ShouldBe(1, "Should return exactly one result"); + searchResult.ShouldNotBeNull(); + searchResult.Results.Count.ShouldBe(1); // Get the specific item with enhanced information var contentItem = searchResult.Results.First(); - var detailedResult = await ApiClient.GetItemAsync(contentItem.Id, - new GuardianApiContentAdditionalInformationOptions + var detailedResult = await Client.GetItemAsync(contentItem.Id, + new AdditionalInformationOptions { - ShowFields = [GuardianApiContentShowFieldsOption.Headline, GuardianApiContentShowFieldsOption.Body], - ShowTags = [GuardianApiContentShowTagsOption.Keyword] + ShowFields = [ContentField.Headline, ContentField.Body], + ShowTags = [ContentTag.Keyword] }); - detailedResult.ShouldNotBeNull("Detailed result should not be null"); - detailedResult.Content!.Id.ShouldBe(contentItem.Id, "IDs should match"); - detailedResult.Content.WebTitle.ShouldBe(contentItem.WebTitle, "Titles should match"); - detailedResult.Content.Fields.ShouldNotBeNull("Detailed fields should be populated"); - detailedResult.Content.Tags.ShouldNotBeNull("Tags should be populated"); + detailedResult.ShouldNotBeNull(); + detailedResult.Content!.Id.ShouldBe(contentItem.Id); + detailedResult.Content.WebTitle.ShouldBe(contentItem.WebTitle); + detailedResult.Content.Fields.ShouldNotBeNull(); + detailedResult.Content.Tags.ShouldNotBeNull(); Console.WriteLine("=== END-TO-END TEST RESULTS ==="); Console.WriteLine(); @@ -53,12 +53,12 @@ public async Task EndToEnd_SearchAndGetItem_WorksTogether() Console.WriteLine($" Published: {contentItem.WebPublicationDate}"); Console.WriteLine($" URL: {contentItem.WebUrl}"); Console.WriteLine(); - + Console.WriteLine($"DETAILED CONTENT:"); Console.WriteLine($" ID: {detailedResult.Content.Id}"); Console.WriteLine($" Headline: {detailedResult.Content.Fields.Headline ?? "N/A"}"); Console.WriteLine($" Tags: {detailedResult.Content.Tags.Count} tags"); - + if (detailedResult.Content.Tags.Any()) { Console.WriteLine($" Tag List:"); @@ -66,12 +66,13 @@ public async Task EndToEnd_SearchAndGetItem_WorksTogether() { Console.WriteLine($" - {tag.WebTitle} ({tag.Type})"); } + if (detailedResult.Content.Tags.Count > 10) { Console.WriteLine($" ... and {detailedResult.Content.Tags.Count - 10} more tags"); } } - + Console.WriteLine(); Console.WriteLine($"FULL ARTICLE BODY:"); Console.WriteLine("=================="); @@ -83,6 +84,7 @@ public async Task EndToEnd_SearchAndGetItem_WorksTogether() { Console.WriteLine("No body content available"); } + Console.WriteLine("=================="); Console.WriteLine(); } @@ -91,44 +93,44 @@ public async Task EndToEnd_SearchAndGetItem_WorksTogether() public async Task SearchWithComplexOptions_ReturnsExpectedResults() { // Test a complex search with multiple option types - var result = await ApiClient.SearchAsync(new GuardianApiContentSearchOptions + var result = await Client.SearchAsync(new SearchOptions { Query = "climate change", QueryFields = ["body", "headline"], - FilterOptions = new GuardianApiContentFilterOptions + FilterOptions = new FilterOptions { Section = "environment" }, - DateOptions = new GuardianApiContentDateOptions + DateOptions = new DateOptions { FromDate = new DateOnly(2023, 1, 1) }, - PageOptions = new GuardianApiContentPageOptions + PageOptions = new PageOptions { Page = 1, PageSize = 5 }, - OrderOptions = new GuardianApiContentOrderOptions + OrderOptions = new OrderOptions { - OrderBy = GuardianApiContentOrderBy.Relevance + OrderBy = ContentOrder.Relevance }, - AdditionalInformationOptions = new GuardianApiContentAdditionalInformationOptions + AdditionalInformationOptions = new AdditionalInformationOptions { - ShowFields = [GuardianApiContentShowFieldsOption.Headline, GuardianApiContentShowFieldsOption.Score], - ShowTags = [GuardianApiContentShowTagsOption.Tone] + ShowFields = [ContentField.Headline, ContentField.Score], + ShowTags = [ContentTag.Tone] } }); - result.ShouldNotBeNull("Complex search should return results"); - result.Status.ShouldBe("ok", "API should respond successfully"); - result.Results.Count.ShouldBeLessThanOrEqualTo(5, "Should respect page size"); + result.ShouldNotBeNull(); + result.Status.ShouldBe("ok"); + result.Results.Count.ShouldBeLessThanOrEqualTo(5); // Verify enhanced data is present if (result.Results.Any()) { var firstItem = result.Results.First(); - firstItem.Fields.ShouldNotBeNull("Enhanced fields should be present"); - firstItem.Tags.ShouldNotBeNull("Tags should be present"); + firstItem.Fields.ShouldNotBeNull(); + firstItem.Tags.ShouldNotBeNull(); Console.WriteLine($"Complex search returned {result.Results.Count} results"); Console.WriteLine($"First result: {firstItem.WebTitle}"); @@ -140,25 +142,25 @@ public async Task SearchWithComplexOptions_ReturnsExpectedResults() public async Task TypeSafetyTest_EnumsMapToCorrectApiValues() { // This test ensures our enums map to the correct API values - var result = await ApiClient.SearchAsync(new GuardianApiContentSearchOptions + var result = await Client.SearchAsync(new SearchOptions { Query = "test", - PageOptions = new GuardianApiContentPageOptions { PageSize = 1 }, - AdditionalInformationOptions = new GuardianApiContentAdditionalInformationOptions + PageOptions = new PageOptions { PageSize = 1 }, + AdditionalInformationOptions = new AdditionalInformationOptions { ShowFields = [ - GuardianApiContentShowFieldsOption.Headline, - GuardianApiContentShowFieldsOption.TrailText, - GuardianApiContentShowFieldsOption.ShowInRelatedContent + ContentField.Headline, + ContentField.TrailText, + ContentField.ShowInRelatedContent ], - ShowTags = [GuardianApiContentShowTagsOption.Tone, GuardianApiContentShowTagsOption.Type], - ShowElements = [GuardianApiContentShowElementsOption.Image] + ShowTags = [ContentTag.Tone, ContentTag.Type], + ShowElements = [ContentElement.Image] } }); - result.ShouldNotBeNull("Type safety test should work"); - result.Status.ShouldBe("ok", "API should accept enum-mapped values"); + result.ShouldNotBeNull(); + result.Status.ShouldBe("ok"); if (result.Results.Any()) { @@ -169,4 +171,26 @@ public async Task TypeSafetyTest_EnumsMapToCorrectApiValues() Console.WriteLine($" Elements populated: {item.Elements != null}"); } } + + [TestMethod] + public async Task SimpleSearch() + { + var result = await Client.SearchAsync(new SearchOptions + { + AdditionalInformationOptions = new AdditionalInformationOptions + { + ShowFields = [ContentField.Body], + ShowElements = [ContentElement.Image] + }, + PageOptions = new PageOptions + { + Page = 0, + PageSize = 10 + } + }); + + var body = result?.Results.First(r => r.Type == "article").Fields?.Body; + + body.ShouldNotBeNull(); + } } diff --git a/GuardianClient/GuardianClient.Tests/SearchAsyncTests.cs b/GuardianClient/GuardianClient.Tests/SearchAsyncTests.cs index 02bfbb4..8820767 100644 --- a/GuardianClient/GuardianClient.Tests/SearchAsyncTests.cs +++ b/GuardianClient/GuardianClient.Tests/SearchAsyncTests.cs @@ -9,22 +9,22 @@ public class SearchAsyncTests : TestBase [TestMethod] public async Task SearchAsync_WithQuery_ReturnsResults() { - var result = await ApiClient.SearchAsync(new GuardianApiContentSearchOptions + var result = await Client.SearchAsync(new SearchOptions { Query = "climate change", - PageOptions = new GuardianApiContentPageOptions { PageSize = 5 } + PageOptions = new PageOptions { PageSize = 5 } }); - result.ShouldNotBeNull("Search result should not be null"); - result.Status.ShouldBe("ok", "API response status should be 'ok'"); - result.Results.Count.ShouldBeGreaterThan(0, "Should return at least one result"); - result.Results.Count.ShouldBeLessThanOrEqualTo(5, "Should not return more than requested page size"); + result.ShouldNotBeNull(); + result.Status.ShouldBe("ok"); + result.Results.Count.ShouldBeGreaterThan(0); + result.Results.Count.ShouldBeLessThanOrEqualTo(5); var firstItem = result.Results.First(); - firstItem.Id.ShouldNotBeNullOrEmpty("Content item should have an ID"); - firstItem.WebTitle.ShouldNotBeNullOrEmpty("Content item should have a title"); - firstItem.WebUrl.ShouldNotBeNullOrEmpty("Content item should have a web URL"); - firstItem.ApiUrl.ShouldNotBeNullOrEmpty("Content item should have an API URL"); + firstItem.Id.ShouldNotBeNullOrEmpty(); + firstItem.WebTitle.ShouldNotBeNullOrEmpty(); + firstItem.WebUrl.ShouldNotBeNullOrEmpty(); + firstItem.ApiUrl.ShouldNotBeNullOrEmpty(); Console.WriteLine($"Found {result.Results.Count} articles about climate change"); Console.WriteLine($"First article: {firstItem.WebTitle}"); @@ -34,25 +34,25 @@ public async Task SearchAsync_WithQuery_ReturnsResults() [TestMethod] public async Task SearchAsync_WithNonExistentQuery_ReturnsNoResults() { - var result = await ApiClient.SearchAsync(new GuardianApiContentSearchOptions + var result = await Client.SearchAsync(new SearchOptions { Query = "xyzabc123nonexistentquery456" }); - result.ShouldNotBeNull("Search result should not be null even with no matches"); - result.Status.ShouldBe("ok", "API response status should be 'ok'"); - result.Results.Count.ShouldBe(0, "Should return zero results for non-existent query"); + result.ShouldNotBeNull(); + result.Status.ShouldBe("ok"); + result.Results.Count.ShouldBe(0); } [TestMethod] public async Task SearchAsync_WithNoOptions_ReturnsDefaultResults() { - var result = await ApiClient.SearchAsync(); + var result = await Client.SearchAsync(); - result.ShouldNotBeNull("Search result should not be null"); - result.Status.ShouldBe("ok", "API response status should be 'ok'"); - result.Results.Count.ShouldBeGreaterThan(0, "Should return results with default options"); - result.Results.Count.ShouldBeLessThanOrEqualTo(10, "Default page size should be 10 or less"); + result.ShouldNotBeNull(); + result.Status.ShouldBe("ok"); + result.Results.Count.ShouldBeGreaterThan(0); + result.Results.Count.ShouldBeLessThanOrEqualTo(10); Console.WriteLine($"Default search returned {result.Results.Count} results"); } @@ -60,24 +60,24 @@ public async Task SearchAsync_WithNoOptions_ReturnsDefaultResults() [TestMethod] public async Task SearchAsync_WithFilterOptions_ReturnsFilteredResults() { - var result = await ApiClient.SearchAsync(new GuardianApiContentSearchOptions + var result = await Client.SearchAsync(new SearchOptions { Query = "technology", - FilterOptions = new GuardianApiContentFilterOptions + FilterOptions = new FilterOptions { Section = "technology" }, - PageOptions = new GuardianApiContentPageOptions { PageSize = 3 } + PageOptions = new PageOptions { PageSize = 3 } }); - result.ShouldNotBeNull("Search result should not be null"); - result.Status.ShouldBe("ok", "API response status should be 'ok'"); - result.Results.Count.ShouldBeGreaterThan(0, "Should return technology results"); + result.ShouldNotBeNull(); + result.Status.ShouldBe("ok"); + result.Results.Count.ShouldBeGreaterThan(0); // Check that results are from technology section foreach (var item in result.Results) { - item.SectionId.ShouldBe("technology", "All results should be from technology section"); + item.SectionId.ShouldBe("technology"); } Console.WriteLine($"Found {result.Results.Count} technology articles"); @@ -86,19 +86,19 @@ public async Task SearchAsync_WithFilterOptions_ReturnsFilteredResults() [TestMethod] public async Task SearchAsync_WithOrderOptions_ReturnsOrderedResults() { - var result = await ApiClient.SearchAsync(new GuardianApiContentSearchOptions + var result = await Client.SearchAsync(new SearchOptions { Query = "sports", - OrderOptions = new GuardianApiContentOrderOptions + OrderOptions = new OrderOptions { - OrderBy = GuardianApiContentOrderBy.Oldest + OrderBy = ContentOrder.Oldest }, - PageOptions = new GuardianApiContentPageOptions { PageSize = 2 } + PageOptions = new PageOptions { PageSize = 2 } }); - result.ShouldNotBeNull("Search result should not be null"); - result.Status.ShouldBe("ok", "API response status should be 'ok'"); - result.Results.Count.ShouldBeGreaterThan(0, "Should return sports results"); + result.ShouldNotBeNull(); + result.Status.ShouldBe("ok"); + result.Results.Count.ShouldBeGreaterThan(0); // Oldest first means first result should be older than or equal to second if (result.Results.Count >= 2) @@ -108,8 +108,7 @@ public async Task SearchAsync_WithOrderOptions_ReturnsOrderedResults() if (first.WebPublicationDate.HasValue && second.WebPublicationDate.HasValue) { - first.WebPublicationDate.Value.ShouldBeLessThanOrEqualTo(second.WebPublicationDate.Value, - "Results should be ordered oldest first"); + first.WebPublicationDate.Value.ShouldBeLessThanOrEqualTo(second.WebPublicationDate.Value); } } @@ -119,24 +118,25 @@ public async Task SearchAsync_WithOrderOptions_ReturnsOrderedResults() [TestMethod] public async Task SearchAsync_WithAdditionalInformation_ReturnsEnhancedResults() { - var result = await ApiClient.SearchAsync(new GuardianApiContentSearchOptions + var result = await Client.SearchAsync(new SearchOptions { Query = "environment", - PageOptions = new GuardianApiContentPageOptions { PageSize = 2 }, - AdditionalInformationOptions = new GuardianApiContentAdditionalInformationOptions + PageOptions = new PageOptions { PageSize = 2 }, + AdditionalInformationOptions = new AdditionalInformationOptions { - ShowFields = [GuardianApiContentShowFieldsOption.Headline, GuardianApiContentShowFieldsOption.Thumbnail], - ShowTags = [GuardianApiContentShowTagsOption.Keyword, GuardianApiContentShowTagsOption.Tone] + ShowFields = + [ContentField.Headline, ContentField.Thumbnail], + ShowTags = [ContentTag.Keyword, ContentTag.Tone] } }); - result.ShouldNotBeNull("Search result should not be null"); - result.Status.ShouldBe("ok", "API response status should be 'ok'"); - result.Results.Count.ShouldBeGreaterThan(0, "Should return environment results"); + result.ShouldNotBeNull(); + result.Status.ShouldBe("ok"); + result.Results.Count.ShouldBeGreaterThan(0); var firstItem = result.Results.First(); - firstItem.Fields.ShouldNotBeNull("Fields should be populated"); - firstItem.Tags.ShouldNotBeNull("Tags should be populated"); + firstItem.Fields.ShouldNotBeNull(); + firstItem.Tags.ShouldNotBeNull(); Console.WriteLine($"Enhanced search returned {result.Results.Count} environment articles"); Console.WriteLine($"First article has {firstItem.Tags.Count} tags"); diff --git a/GuardianClient/GuardianClient.Tests/TestBase.cs b/GuardianClient/GuardianClient.Tests/TestBase.cs index 45d2a50..5d37207 100644 --- a/GuardianClient/GuardianClient.Tests/TestBase.cs +++ b/GuardianClient/GuardianClient.Tests/TestBase.cs @@ -6,7 +6,7 @@ namespace GuardianClient.Tests; public abstract class TestBase { - protected static IGuardianApiClient ApiClient { get; } + protected static IGuardianApiClient Client { get; } static TestBase() { @@ -16,7 +16,7 @@ static TestBase() var apiKey = config["GuardianApiKey"]!; - ApiClient = new ServiceCollection() + Client = new ServiceCollection() .AddGuardianApiClient(apiKey) .BuildServiceProvider() .GetRequiredService(); diff --git a/GuardianClient/GuardianClient/GuardianApiClient.cs b/GuardianClient/GuardianClient/GuardianApiClient.cs index 92272ff..7c34218 100644 --- a/GuardianClient/GuardianClient/GuardianApiClient.cs +++ b/GuardianClient/GuardianClient/GuardianApiClient.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using System.Text.Json; using GuardianClient.Internal; using GuardianClient.Models; @@ -52,12 +53,20 @@ public GuardianApiClient(string apiKey) ConfigureHttpClient(); } + private void ConfigureHttpClient() + { + var packageVersion = AssemblyInfo.GetPackageVersion(); + + _httpClient.BaseAddress = new Uri(BaseUrl); + _httpClient.DefaultRequestHeaders.Add("User-Agent", $"GuardianClient.NET/{packageVersion}"); + } + public async Task SearchAsync( - GuardianApiContentSearchOptions? options = null, + SearchOptions? options = null, CancellationToken cancellationToken = default ) { - options ??= new GuardianApiContentSearchOptions(); + options ??= new SearchOptions(); var parameters = new List { $"api-key={Uri.EscapeDataString(_apiKey)}" }; @@ -69,6 +78,7 @@ public GuardianApiClient(string apiKey) UrlParameterBuilder.AddAdditionalInformationParameters(options.AdditionalInformationOptions, parameters); var url = $"/search?{string.Join("&", parameters)}"; + DebugWriteLine($"Guardian API URL: {BaseUrl}{url}"); var response = await _httpClient.GetAsync(url, cancellationToken); response.EnsureSuccessStatusCode(); @@ -81,7 +91,7 @@ public GuardianApiClient(string apiKey) public async Task GetItemAsync( string itemId, - GuardianApiContentAdditionalInformationOptions? options = null, + AdditionalInformationOptions? options = null, CancellationToken cancellationToken = default) { ArgumentException.ThrowIfNullOrWhiteSpace(itemId); @@ -101,12 +111,14 @@ public GuardianApiClient(string apiKey) options?.ShowTags, option => option.ToApiString() ); + UrlParameterBuilder.AddParameterIfAny( parameters, "show-elements", options?.ShowElements, option => option.ToApiString() ); + UrlParameterBuilder.AddParameterIfAny( parameters, "show-references", @@ -121,6 +133,7 @@ public GuardianApiClient(string apiKey) ); var url = $"/{itemId}?{string.Join("&", parameters)}"; + DebugWriteLine($"Guardian API URL: {BaseUrl}{url}"); var response = await _httpClient.GetAsync(url, cancellationToken); response.EnsureSuccessStatusCode(); @@ -131,18 +144,16 @@ public GuardianApiClient(string apiKey) return wrapper?.Response; } - public void Dispose() + [Conditional("DEBUG")] + private static void DebugWriteLine(string message) { - Dispose(true); - GC.SuppressFinalize(this); + Debug.WriteLine(message); } - private void ConfigureHttpClient() + public void Dispose() { - var packageVersion = AssemblyInfo.GetPackageVersion(); - - _httpClient.BaseAddress = new Uri(BaseUrl); - _httpClient.DefaultRequestHeaders.Add("User-Agent", $"GuardianClient.NET/{packageVersion}"); + Dispose(true); + GC.SuppressFinalize(this); } /// diff --git a/GuardianClient/GuardianClient/GuardianClient.csproj b/GuardianClient/GuardianClient/GuardianClient.csproj index b385d91..fbd5b3d 100644 --- a/GuardianClient/GuardianClient/GuardianClient.csproj +++ b/GuardianClient/GuardianClient/GuardianClient.csproj @@ -7,13 +7,13 @@ GuardianClient.NET - 0.4.0-alpha + 0.5.0-alpha Andrew Tarr A .NET API wrapper for Guardian services guardian;api;client;wrapper MIT https://github.com/tarrball/GuardianClient.NET - https://github.com/tarrball/GuardianClient.NET + https://github.com/tarrball/GuardianClient.NET.git git main README.md diff --git a/GuardianClient/GuardianClient/IGuardianApiClient.cs b/GuardianClient/GuardianClient/IGuardianApiClient.cs index d3a3f6b..b2667f0 100644 --- a/GuardianClient/GuardianClient/IGuardianApiClient.cs +++ b/GuardianClient/GuardianClient/IGuardianApiClient.cs @@ -34,7 +34,7 @@ public interface IGuardianApiClient /// For simple searches, you can create basic options: new GuardianApiContentSearchOptions { Query = "your search terms" } /// Task SearchAsync( - GuardianApiContentSearchOptions? options = null, + SearchOptions? options = null, CancellationToken cancellationToken = default ); @@ -47,7 +47,7 @@ public interface IGuardianApiClient /// Single item response with content details Task GetItemAsync( string itemId, - GuardianApiContentAdditionalInformationOptions? options = null, + AdditionalInformationOptions? options = null, CancellationToken cancellationToken = default ); } diff --git a/GuardianClient/GuardianClient/Internal/AdditionalInformationExtensions.cs b/GuardianClient/GuardianClient/Internal/AdditionalInformationExtensions.cs index 0327232..e84b797 100644 --- a/GuardianClient/GuardianClient/Internal/AdditionalInformationExtensions.cs +++ b/GuardianClient/GuardianClient/Internal/AdditionalInformationExtensions.cs @@ -7,89 +7,89 @@ namespace GuardianClient.Internal; /// internal static class AdditionalInformationExtensions { - internal static string ToApiString(this GuardianApiContentShowFieldsOption option) => option switch + internal static string ToApiString(this ContentField option) => option switch { - GuardianApiContentShowFieldsOption.TrailText => "trailText", - GuardianApiContentShowFieldsOption.Headline => "headline", - GuardianApiContentShowFieldsOption.ShowInRelatedContent => "showInRelatedContent", - GuardianApiContentShowFieldsOption.Body => "body", - GuardianApiContentShowFieldsOption.LastModified => "lastModified", - GuardianApiContentShowFieldsOption.HasStoryPackage => "hasStoryPackage", - GuardianApiContentShowFieldsOption.Score => "score", - GuardianApiContentShowFieldsOption.Standfirst => "standfirst", - GuardianApiContentShowFieldsOption.ShortUrl => "shortUrl", - GuardianApiContentShowFieldsOption.Thumbnail => "thumbnail", - GuardianApiContentShowFieldsOption.Wordcount => "wordcount", - GuardianApiContentShowFieldsOption.Commentable => "commentable", - GuardianApiContentShowFieldsOption.IsPremoderated => "isPremoderated", - GuardianApiContentShowFieldsOption.AllowUgc => "allowUgc", - GuardianApiContentShowFieldsOption.Byline => "byline", - GuardianApiContentShowFieldsOption.Publication => "publication", - GuardianApiContentShowFieldsOption.InternalPageCode => "internalPageCode", - GuardianApiContentShowFieldsOption.ProductionOffice => "productionOffice", - GuardianApiContentShowFieldsOption.ShouldHideAdverts => "shouldHideAdverts", - GuardianApiContentShowFieldsOption.LiveBloggingNow => "liveBloggingNow", - GuardianApiContentShowFieldsOption.CommentCloseDate => "commentCloseDate", - GuardianApiContentShowFieldsOption.StarRating => "starRating", - GuardianApiContentShowFieldsOption.All => "all", + ContentField.TrailText => "trailText", + ContentField.Headline => "headline", + ContentField.ShowInRelatedContent => "showInRelatedContent", + ContentField.Body => "body", + ContentField.LastModified => "lastModified", + ContentField.HasStoryPackage => "hasStoryPackage", + ContentField.Score => "score", + ContentField.Standfirst => "standfirst", + ContentField.ShortUrl => "shortUrl", + ContentField.Thumbnail => "thumbnail", + ContentField.Wordcount => "wordcount", + ContentField.Commentable => "commentable", + ContentField.IsPremoderated => "isPremoderated", + ContentField.AllowUgc => "allowUgc", + ContentField.Byline => "byline", + ContentField.Publication => "publication", + ContentField.InternalPageCode => "internalPageCode", + ContentField.ProductionOffice => "productionOffice", + ContentField.ShouldHideAdverts => "shouldHideAdverts", + ContentField.LiveBloggingNow => "liveBloggingNow", + ContentField.CommentCloseDate => "commentCloseDate", + ContentField.StarRating => "starRating", + ContentField.All => "all", _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) }; - internal static string ToApiString(this GuardianApiContentShowTagsOption option) => option switch + internal static string ToApiString(this ContentTag option) => option switch { - GuardianApiContentShowTagsOption.Blog => "blog", - GuardianApiContentShowTagsOption.Contributor => "contributor", - GuardianApiContentShowTagsOption.Keyword => "keyword", - GuardianApiContentShowTagsOption.NewspaperBook => "newspaper-book", - GuardianApiContentShowTagsOption.NewspaperBookSection => "newspaper-book-section", - GuardianApiContentShowTagsOption.Publication => "publication", - GuardianApiContentShowTagsOption.Series => "series", - GuardianApiContentShowTagsOption.Tone => "tone", - GuardianApiContentShowTagsOption.Type => "type", - GuardianApiContentShowTagsOption.All => "all", + ContentTag.Blog => "blog", + ContentTag.Contributor => "contributor", + ContentTag.Keyword => "keyword", + ContentTag.NewspaperBook => "newspaper-book", + ContentTag.NewspaperBookSection => "newspaper-book-section", + ContentTag.Publication => "publication", + ContentTag.Series => "series", + ContentTag.Tone => "tone", + ContentTag.Type => "type", + ContentTag.All => "all", _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) }; - internal static string ToApiString(this GuardianApiContentShowElementsOption option) => option switch + internal static string ToApiString(this ContentElement option) => option switch { - GuardianApiContentShowElementsOption.Audio => "audio", - GuardianApiContentShowElementsOption.Image => "image", - GuardianApiContentShowElementsOption.Video => "video", - GuardianApiContentShowElementsOption.All => "all", + ContentElement.Audio => "audio", + ContentElement.Image => "image", + ContentElement.Video => "video", + ContentElement.All => "all", _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) }; - internal static string ToApiString(this GuardianApiContentShowReferencesOption option) => option switch + internal static string ToApiString(this Reference option) => option switch { - GuardianApiContentShowReferencesOption.Author => "author", - GuardianApiContentShowReferencesOption.BisacPrefix => "bisac-prefix", - GuardianApiContentShowReferencesOption.EsaCricketMatch => "esa-cricket-match", - GuardianApiContentShowReferencesOption.EsaFootballMatch => "esa-football-match", - GuardianApiContentShowReferencesOption.EsaFootballTeam => "esa-football-team", - GuardianApiContentShowReferencesOption.EsaFootballTournament => "esa-football-tournament", - GuardianApiContentShowReferencesOption.Isbn => "isbn", - GuardianApiContentShowReferencesOption.Imdb => "imdb", - GuardianApiContentShowReferencesOption.Musicbrainz => "musicbrainz", - GuardianApiContentShowReferencesOption.MusicbrainzGenre => "musicbrainzgenre", - GuardianApiContentShowReferencesOption.OptaCricketMatch => "opta-cricket-match", - GuardianApiContentShowReferencesOption.OptaFootballMatch => "opta-football-match", - GuardianApiContentShowReferencesOption.OptaFootballTeam => "opta-football-team", - GuardianApiContentShowReferencesOption.OptaFootballTournament => "opta-football-tournament", - GuardianApiContentShowReferencesOption.PaFootballCompetition => "pa-football-competition", - GuardianApiContentShowReferencesOption.PaFootballMatch => "pa-football-match", - GuardianApiContentShowReferencesOption.PaFootballTeam => "pa-football-team", - GuardianApiContentShowReferencesOption.R1Film => "r1-film", - GuardianApiContentShowReferencesOption.ReutersIndexRic => "reuters-index-ric", - GuardianApiContentShowReferencesOption.ReutersStockRic => "reuters-stock-ric", - GuardianApiContentShowReferencesOption.WitnessAssignment => "witness-assignment", + Reference.Author => "author", + Reference.BisacPrefix => "bisac-prefix", + Reference.EsaCricketMatch => "esa-cricket-match", + Reference.EsaFootballMatch => "esa-football-match", + Reference.EsaFootballTeam => "esa-football-team", + Reference.EsaFootballTournament => "esa-football-tournament", + Reference.Isbn => "isbn", + Reference.Imdb => "imdb", + Reference.Musicbrainz => "musicbrainz", + Reference.MusicbrainzGenre => "musicbrainzgenre", + Reference.OptaCricketMatch => "opta-cricket-match", + Reference.OptaFootballMatch => "opta-football-match", + Reference.OptaFootballTeam => "opta-football-team", + Reference.OptaFootballTournament => "opta-football-tournament", + Reference.PaFootballCompetition => "pa-football-competition", + Reference.PaFootballMatch => "pa-football-match", + Reference.PaFootballTeam => "pa-football-team", + Reference.R1Film => "r1-film", + Reference.ReutersIndexRic => "reuters-index-ric", + Reference.ReutersStockRic => "reuters-stock-ric", + Reference.WitnessAssignment => "witness-assignment", _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) }; - internal static string ToApiString(this GuardianApiContentShowRightsOption option) => option switch + internal static string ToApiString(this ContentRight option) => option switch { - GuardianApiContentShowRightsOption.Syndicatable => "syndicatable", - GuardianApiContentShowRightsOption.SubscriptionDatabases => "subscription-databases", - GuardianApiContentShowRightsOption.All => "all", + ContentRight.Syndicatable => "syndicatable", + ContentRight.SubscriptionDatabases => "subscription-databases", + ContentRight.All => "all", _ => throw new ArgumentOutOfRangeException(nameof(option), option, null) }; } diff --git a/GuardianClient/GuardianClient/Internal/UrlParameterBuilder.cs b/GuardianClient/GuardianClient/Internal/UrlParameterBuilder.cs index 73981d1..02213c5 100644 --- a/GuardianClient/GuardianClient/Internal/UrlParameterBuilder.cs +++ b/GuardianClient/GuardianClient/Internal/UrlParameterBuilder.cs @@ -36,13 +36,13 @@ internal static void AddParameterIfAny(List parameters, string parame } } - internal static void AddQueryParameters(GuardianApiContentSearchOptions options, List parameters) + internal static void AddQueryParameters(SearchOptions options, List parameters) { AddParameterIfNotEmpty(parameters, "q", options.Query); AddParameterIfAny(parameters, "query-fields", options.QueryFields); } - internal static void AddFilterParameters(GuardianApiContentFilterOptions filterOptions, List parameters) + internal static void AddFilterParameters(FilterOptions filterOptions, List parameters) { AddParameterIfNotEmpty(parameters, "section", filterOptions.Section); AddParameterIfNotEmpty(parameters, "reference", filterOptions.Reference); @@ -56,7 +56,7 @@ internal static void AddFilterParameters(GuardianApiContentFilterOptions filterO AddParameterIfHasValue(parameters, "star-rating", filterOptions.StarRating); } - internal static void AddDateParameters(GuardianApiContentDateOptions dateOptions, List parameters) + internal static void AddDateParameters(DateOptions dateOptions, List parameters) { if (dateOptions.FromDate != default) { @@ -71,7 +71,7 @@ internal static void AddDateParameters(GuardianApiContentDateOptions dateOptions AddParameterIfNotEmpty(parameters, "use-date", dateOptions.UseDate); } - internal static void AddPageParameters(GuardianApiContentPageOptions pageOptions, List parameters) + internal static void AddPageParameters(PageOptions pageOptions, List parameters) { if (pageOptions.Page > 0) { @@ -84,15 +84,15 @@ internal static void AddPageParameters(GuardianApiContentPageOptions pageOptions } } - internal static void AddOrderParameters(GuardianApiContentOrderOptions orderOptions, List parameters) + internal static void AddOrderParameters(OrderOptions orderOptions, List parameters) { if (orderOptions.OrderBy.HasValue) { var orderByValue = orderOptions.OrderBy.Value switch { - GuardianApiContentOrderBy.Newest => "newest", - GuardianApiContentOrderBy.Oldest => "oldest", - GuardianApiContentOrderBy.Relevance => "relevance", + ContentOrder.Newest => "newest", + ContentOrder.Oldest => "oldest", + ContentOrder.Relevance => "relevance", _ => "newest" }; parameters.Add($"order-by={orderByValue}"); @@ -102,9 +102,9 @@ internal static void AddOrderParameters(GuardianApiContentOrderOptions orderOpti { var orderDateValue = orderOptions.OrderDate.Value switch { - GuardianApiContentOrderDate.Published => "published", - GuardianApiContentOrderDate.NewspaperEdition => "newspaper-edition", - GuardianApiContentOrderDate.LastModified => "last-modified", + ContentType.Published => "published", + ContentType.NewspaperEdition => "newspaper-edition", + ContentType.LastModified => "last-modified", _ => "published" }; parameters.Add($"order-date={orderDateValue}"); @@ -112,7 +112,7 @@ internal static void AddOrderParameters(GuardianApiContentOrderOptions orderOpti } internal static void AddAdditionalInformationParameters( - GuardianApiContentAdditionalInformationOptions additionalOptions, + AdditionalInformationOptions additionalOptions, List parameters ) { @@ -120,6 +120,7 @@ List parameters AddParameterIfAny(parameters, "show-tags", additionalOptions.ShowTags, t => t.ToApiString()); AddParameterIfAny(parameters, "show-elements", additionalOptions.ShowElements, e => e.ToApiString()); AddParameterIfAny(parameters, "show-references", additionalOptions.ShowReferences, r => r.ToApiString()); + AddParameterIfAny(parameters, "show-rights", additionalOptions.ShowRights, r => r.ToApiString()); AddParameterIfAny(parameters, "show-blocks", additionalOptions.ShowBlocks); } } \ No newline at end of file diff --git a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentAdditionalInformationOptions.cs b/GuardianClient/GuardianClient/Options/Search/AdditionalInformationOptions.cs similarity index 83% rename from GuardianClient/GuardianClient/Options/Search/GuardianApiContentAdditionalInformationOptions.cs rename to GuardianClient/GuardianClient/Options/Search/AdditionalInformationOptions.cs index f0a4f81..889a743 100644 --- a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentAdditionalInformationOptions.cs +++ b/GuardianClient/GuardianClient/Options/Search/AdditionalInformationOptions.cs @@ -6,28 +6,32 @@ namespace GuardianClient.Options.Search; /// Options for requesting additional information to be included with search results. /// [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")] -public class GuardianApiContentAdditionalInformationOptions +public class AdditionalInformationOptions { /// /// Add fields associated with the content such as headline, body, thumbnail, etc. /// - public GuardianApiContentShowFieldsOption[]? ShowFields { get; set; } + public ContentField[]? ShowFields { get; set; } /// /// Add associated metadata tags such as contributor, keyword, tone, etc. /// - public GuardianApiContentShowTagsOption[]? ShowTags { get; set; } + public ContentTag[]? ShowTags { get; set; } /// /// Add associated media elements such as images, audio, and video. /// - public GuardianApiContentShowElementsOption[]? ShowElements { get; set; } + public ContentElement[]? ShowElements { get; set; } /// /// Add associated reference data such as ISBNs, IMDB IDs, author references, etc. /// - public GuardianApiContentShowReferencesOption[]? ShowReferences { get; set; } + public Reference[]? ShowReferences { get; set; } + /// + /// Add associated rights information such as syndicatable or subscription-databases. + /// + public ContentRight[]? ShowRights { get; set; } /// /// Add associated blocks (single block for content, one or more for liveblogs). diff --git a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowElementsOption.cs b/GuardianClient/GuardianClient/Options/Search/ContentElement.cs similarity index 78% rename from GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowElementsOption.cs rename to GuardianClient/GuardianClient/Options/Search/ContentElement.cs index 275fe03..ef6fdca 100644 --- a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowElementsOption.cs +++ b/GuardianClient/GuardianClient/Options/Search/ContentElement.cs @@ -3,10 +3,10 @@ namespace GuardianClient.Options.Search; /// /// Media element types that can be included with content responses. /// -public enum GuardianApiContentShowElementsOption +public enum ContentElement { Audio, Image, Video, All -} \ No newline at end of file +} diff --git a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowFieldsOption.cs b/GuardianClient/GuardianClient/Options/Search/ContentField.cs similarity index 91% rename from GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowFieldsOption.cs rename to GuardianClient/GuardianClient/Options/Search/ContentField.cs index 32e0251..b6bb483 100644 --- a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowFieldsOption.cs +++ b/GuardianClient/GuardianClient/Options/Search/ContentField.cs @@ -3,7 +3,7 @@ namespace GuardianClient.Options.Search; /// /// Fields that can be included with content responses. /// -public enum GuardianApiContentShowFieldsOption +public enum ContentField { TrailText, Headline, @@ -28,4 +28,4 @@ public enum GuardianApiContentShowFieldsOption CommentCloseDate, StarRating, All -} \ No newline at end of file +} diff --git a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentOrderBy.cs b/GuardianClient/GuardianClient/Options/Search/ContentOrder.cs similarity index 92% rename from GuardianClient/GuardianClient/Options/Search/GuardianApiContentOrderBy.cs rename to GuardianClient/GuardianClient/Options/Search/ContentOrder.cs index b75c022..12fd658 100644 --- a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentOrderBy.cs +++ b/GuardianClient/GuardianClient/Options/Search/ContentOrder.cs @@ -3,7 +3,7 @@ namespace GuardianClient.Options.Search; /// /// Specifies the order in which search results should be returned. /// -public enum GuardianApiContentOrderBy +public enum ContentOrder { /// /// Order by newest content first. Default in all other cases. diff --git a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowReferencesOption.cs b/GuardianClient/GuardianClient/Options/Search/ContentReference.cs similarity index 91% rename from GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowReferencesOption.cs rename to GuardianClient/GuardianClient/Options/Search/ContentReference.cs index 663bb09..9abb094 100644 --- a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowReferencesOption.cs +++ b/GuardianClient/GuardianClient/Options/Search/ContentReference.cs @@ -3,7 +3,7 @@ namespace GuardianClient.Options.Search; /// /// Reference types that can be included with content responses. /// -public enum GuardianApiContentShowReferencesOption +public enum Reference { Author, BisacPrefix, @@ -26,4 +26,4 @@ public enum GuardianApiContentShowReferencesOption ReutersIndexRic, ReutersStockRic, WitnessAssignment -} \ No newline at end of file +} diff --git a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowRightsOption.cs b/GuardianClient/GuardianClient/Options/Search/ContentRight.cs similarity index 79% rename from GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowRightsOption.cs rename to GuardianClient/GuardianClient/Options/Search/ContentRight.cs index 0a57c62..4887439 100644 --- a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowRightsOption.cs +++ b/GuardianClient/GuardianClient/Options/Search/ContentRight.cs @@ -3,9 +3,9 @@ namespace GuardianClient.Options.Search; /// /// Rights types that can be included with content responses. /// -public enum GuardianApiContentShowRightsOption +public enum ContentRight { Syndicatable, SubscriptionDatabases, All -} \ No newline at end of file +} diff --git a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowTagsOption.cs b/GuardianClient/GuardianClient/Options/Search/ContentTag.cs similarity index 85% rename from GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowTagsOption.cs rename to GuardianClient/GuardianClient/Options/Search/ContentTag.cs index d186193..1b09db8 100644 --- a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentShowTagsOption.cs +++ b/GuardianClient/GuardianClient/Options/Search/ContentTag.cs @@ -3,7 +3,7 @@ namespace GuardianClient.Options.Search; /// /// Tag types that can be included with content responses. /// -public enum GuardianApiContentShowTagsOption +public enum ContentTag { Blog, Contributor, @@ -15,4 +15,4 @@ public enum GuardianApiContentShowTagsOption Tone, Type, All -} \ No newline at end of file +} diff --git a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentOrderDate.cs b/GuardianClient/GuardianClient/Options/Search/ContentType.cs similarity index 91% rename from GuardianClient/GuardianClient/Options/Search/GuardianApiContentOrderDate.cs rename to GuardianClient/GuardianClient/Options/Search/ContentType.cs index 10962a8..52340c3 100644 --- a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentOrderDate.cs +++ b/GuardianClient/GuardianClient/Options/Search/ContentType.cs @@ -3,7 +3,7 @@ namespace GuardianClient.Options.Search; /// /// Specifies which type of date is used to order the results. /// -public enum GuardianApiContentOrderDate +public enum ContentType { /// /// The date the content appeared on the web. Default. diff --git a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentDateOptions.cs b/GuardianClient/GuardianClient/Options/Search/DateOptions.cs similarity index 95% rename from GuardianClient/GuardianClient/Options/Search/GuardianApiContentDateOptions.cs rename to GuardianClient/GuardianClient/Options/Search/DateOptions.cs index 0fe11f5..17331a1 100644 --- a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentDateOptions.cs +++ b/GuardianClient/GuardianClient/Options/Search/DateOptions.cs @@ -3,7 +3,7 @@ namespace GuardianClient.Options.Search; /// /// Options for filtering search results by date ranges. /// -public class GuardianApiContentDateOptions +public class DateOptions { /// /// Return only content published on or after that date. diff --git a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentFilterOptions.cs b/GuardianClient/GuardianClient/Options/Search/FilterOptions.cs similarity index 97% rename from GuardianClient/GuardianClient/Options/Search/GuardianApiContentFilterOptions.cs rename to GuardianClient/GuardianClient/Options/Search/FilterOptions.cs index e838e60..0a753df 100644 --- a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentFilterOptions.cs +++ b/GuardianClient/GuardianClient/Options/Search/FilterOptions.cs @@ -6,7 +6,7 @@ namespace GuardianClient.Options.Search; /// Options for filtering content search results by various criteria. /// [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")] -public class GuardianApiContentFilterOptions +public class FilterOptions { /// /// Return only content in those sections. Supports boolean operators. diff --git a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentOrderOptions.cs b/GuardianClient/GuardianClient/Options/Search/OrderOptions.cs similarity index 76% rename from GuardianClient/GuardianClient/Options/Search/GuardianApiContentOrderOptions.cs rename to GuardianClient/GuardianClient/Options/Search/OrderOptions.cs index 606a557..43a5dca 100644 --- a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentOrderOptions.cs +++ b/GuardianClient/GuardianClient/Options/Search/OrderOptions.cs @@ -6,15 +6,15 @@ namespace GuardianClient.Options.Search; /// Options for controlling the ordering of search results. /// [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")] -public class GuardianApiContentOrderOptions +public class OrderOptions { /// /// Returns results in the specified order. Defaults to Newest in most cases, or Relevance when a query parameter is specified. /// - public GuardianApiContentOrderBy? OrderBy { get; set; } + public ContentOrder? OrderBy { get; set; } /// /// Changes which type of date is used to order the results. Defaults to Published. /// - public GuardianApiContentOrderDate? OrderDate { get; set; } + public ContentType? OrderDate { get; set; } } diff --git a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentPageOptions.cs b/GuardianClient/GuardianClient/Options/Search/PageOptions.cs similarity index 92% rename from GuardianClient/GuardianClient/Options/Search/GuardianApiContentPageOptions.cs rename to GuardianClient/GuardianClient/Options/Search/PageOptions.cs index 04ba1ee..502ee3b 100644 --- a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentPageOptions.cs +++ b/GuardianClient/GuardianClient/Options/Search/PageOptions.cs @@ -6,7 +6,7 @@ namespace GuardianClient.Options.Search; /// Options for controlling pagination of search results. /// [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")] -public class GuardianApiContentPageOptions +public class PageOptions { /// /// Return only the result set from a particular page. diff --git a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentSearchOptions.cs b/GuardianClient/GuardianClient/Options/Search/SearchOptions.cs similarity index 73% rename from GuardianClient/GuardianClient/Options/Search/GuardianApiContentSearchOptions.cs rename to GuardianClient/GuardianClient/Options/Search/SearchOptions.cs index 01fbf4d..208cd3f 100644 --- a/GuardianClient/GuardianClient/Options/Search/GuardianApiContentSearchOptions.cs +++ b/GuardianClient/GuardianClient/Options/Search/SearchOptions.cs @@ -6,7 +6,7 @@ namespace GuardianClient.Options.Search; /// Options for searching content using the Guardian API. /// [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")] -public class GuardianApiContentSearchOptions +public class SearchOptions { /// /// Request content containing this free text. Supports AND, OR and NOT operators, and exact phrase queries using double quotes. @@ -23,25 +23,25 @@ public class GuardianApiContentSearchOptions /// /// Options for requesting additional information to be included with search results. /// - public GuardianApiContentAdditionalInformationOptions AdditionalInformationOptions { get; set; } = new(); + public AdditionalInformationOptions AdditionalInformationOptions { get; set; } = new(); /// /// Options for filtering search results by various criteria. /// - public GuardianApiContentFilterOptions FilterOptions { get; set; } = new(); + public FilterOptions FilterOptions { get; set; } = new(); /// /// Options for filtering search results by date ranges. /// - public GuardianApiContentDateOptions DateOptions { get; set; } = new(); + public DateOptions DateOptions { get; set; } = new(); /// /// Options for controlling pagination of search results. /// - public GuardianApiContentPageOptions PageOptions { get; set; } = new(); + public PageOptions PageOptions { get; set; } = new(); /// /// Options for controlling the ordering of search results. /// - public GuardianApiContentOrderOptions OrderOptions { get; set; } = new(); + public OrderOptions OrderOptions { get; set; } = new(); }