Skip to content

Commit

Permalink
2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CircuitRCAY committed Apr 4, 2019
1 parent 0c01ca2 commit ce2d9f7
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 42 deletions.
17 changes: 9 additions & 8 deletions NewsAPI.Net.Tests/EndpointTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using NewsAPI.Net.Models;
using Newtonsoft.Json;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -14,26 +15,26 @@ public EndpointTest(ITestOutputHelper output)
}

[Fact]
public void Test1()
public void SourcesTest()
{
NewsClient client = new NewsClient("550d4e974dcc4cf1b4675a5ce91b202e");
NewsClient client = new NewsClient("bb554838724b452fb14adf8661be7646");
Models.NewsSourcesModel s = client.GetSourcesAsync().GetAwaiter().GetResult();
output.WriteLine(JsonConvert.SerializeObject(s));
}

[Fact]
public void Test2()
public void EverythingTest()
{
NewsClient client = new NewsClient("550d4e974dcc4cf1b4675a5ce91b202e");
Models.NewsModel s = client.GetEverythingAsync("bitcoin").GetAwaiter().GetResult();
NewsClient client = new NewsClient("bb554838724b452fb14adf8661be7646");
Models.NewsModel s = client.GetEverythingAsync("bitcoin", lang: Language.ENGLISH).GetAwaiter().GetResult();
output.WriteLine(JsonConvert.SerializeObject(s));
}

[Fact]
public void Test3()
public void TopHeadlinesTest()
{
NewsClient client = new NewsClient("550d4e974dcc4cf1b4675a5ce91b202e");
Models.NewsModel s = client.GetTopHeadlinesAsync("bitcoin").GetAwaiter().GetResult();
NewsClient client = new NewsClient("bb554838724b452fb14adf8661be7646");
Models.NewsModel s = client.GetTopHeadlinesAsync("abc-news", lang:Language.ENGLISH).GetAwaiter().GetResult();
output.WriteLine(JsonConvert.SerializeObject(s));
}
}
Expand Down
2 changes: 2 additions & 0 deletions NewsAPI.Net/Extensions/HttpExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Runtime.InteropServices;
using System.Web;

namespace NewsAPI.Net.Extensions
{
internal static class HttpExtensions
{

internal static Uri AddQuery(this Uri url, string paramName, string paramValue)
{
UriBuilder uriBuilder = new UriBuilder(url);
Expand Down
35 changes: 35 additions & 0 deletions NewsAPI.Net/Models/Language.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NewsAPI.Net.Models
{
public class Language
{
public static string ARABIC { get { return "ar"; } }

public static string GERMAN { get { return "de"; } }

public static string ENGLISH { get { return "en"; } }

public static string SPANISH { get { return "es"; } }

public static string FRENCH { get { return "fr"; } }

public static string HEBREW { get { return "he"; } }

public static string ITALIAN { get { return "it"; } }

public static string GEKOLONISEERD { get { return "nl"; } }

public static string NORSE { get { return "no"; } }

public static string PORTUGUESE { get { return "pt"; } }

public static string RUSSIAN { get { return "ru"; } }

public static string SWEDISH { get { return "se"; } }

public static string CHINESE { get { return "zh"; } }
}
}
24 changes: 8 additions & 16 deletions NewsAPI.Net/NewsAPI.Net.csproj
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;netstandard2.0;net472</TargetFrameworks>
<Company />
<Version>2.0.0</Version>
<PackageLicenseUrl>https://github.com/The-Grape-Vine/NewsAPI.Net/blob/master/LICENSE</PackageLicenseUrl>
<Authors>CircuitRCAY</Authors>
<Copyright>Copyright 2019-present The Grape Vine</Copyright>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>2.2.0</Version>
<RepositoryUrl>https://github.com/The-Grape-Vine/NewsAPI.Net/</RepositoryUrl>
<PackageProjectUrl>https://circuitrcay.com</PackageProjectUrl>
<PackageTags>news</PackageTags>
<Authors>circuitrcay</Authors>
<PackageLicenseUrl>https://github.com/The-Grape-Vine/NewsAPI.Net/blob/master/LICENSE</PackageLicenseUrl>
<Description>A C# library wrapping https://newsapi.org</Description>
<PackageReleaseNotes>Released 2.0.0, a major refactor in the core implementation.</PackageReleaseNotes>
<PackageReleaseNotes>Released 2.2.0, added support for specific languages.</PackageReleaseNotes>
<Copyright>2019-present The Grape Vine.</Copyright>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Web.HttpUtility, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<HintPath>..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.netcore.app\2.1.0\ref\netcoreapp2.1\System.Web.HttpUtility.dll</HintPath>
</Reference>
</ItemGroup>



</Project>
26 changes: 12 additions & 14 deletions NewsAPI.Net/NewsApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,22 @@ public async Task<NewsSourcesModel> GetSourcesAsync()
}

/// <summary>
/// Returns a <see cref="NewsModel"/> containing a list of articles relating to <paramref name="q"/>.
/// Returns a <see cref="NewsModel"/> containing a list of articles relating to <paramref name="query"/>.
/// </summary>
/// <param name="query">Keywords or phrases to search for.</param>
/// <param name="sources">A comma-separated string of identifiers (maximum 20) for the news sources or blogs you want headlines from.</param>
/// <param name="lang">The language you want to get headlines for. Default being all languages returned.</param>
/// <param name="domains"> A comma-separated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to restrict the search to. </param>
/// <returns></returns>
public async Task<NewsModel> GetEverythingAsync(string query = null, string sources = null, string domains = null)
/// <returns>Task{TResult}</returns>
public async Task<NewsModel> GetEverythingAsync(string query = null, string sources = null, string domains = null, string lang = null)
{
if (q == null)
{
throw new ArgumentNullException(nameof(query));
}


Uri uri = new Uri(_baseUrl + "everything")
.AddQuery("apiKey", _key)
.AddQuery("q", query)
.AddQuery("sources", sources)
.AddQuery("language", lang.ToString())
.AddQuery("domains", domains);
HttpResponseMessage response = await _client.GetAsync(uri);
response.EnsureSuccessStatusCode();
Expand All @@ -88,23 +87,22 @@ public async Task<NewsModel> GetEverythingAsync(string query = null, string sour
}

/// <summary>
/// Returns a <see cref="NewsModel"/> containing a list of top articles relating to <paramref name="q"/>.
/// Returns a <see cref="NewsModel"/> containing a list of top articles relating to <paramref name="query"/>.
/// </summary>
/// <param name="query">Keywords or phrases to search for.</param>
/// <param name="sources">A comma-separated string of identifiers (maximum 20) for the news sources or blogs you want headlines from.</param>
/// <param name="lang">The language you want to return top</param>
/// <param name="domains"> A comma-separated string of domains (eg bbc.co.uk, techcrunch.com, engadget.com) to restrict the search to. </param>
/// <returns></returns>
public async Task<NewsModel> GetTopHeadlinesAsync(string query, string sources = null, string domains = null)
/// <returns>Task{TResult}</returns>
public async Task<NewsModel> GetTopHeadlinesAsync(string query = null, string sources = null, string domains = null, string lang = null)
{
if (q == null)
{
throw new ArgumentNullException(nameof(query));
}


Uri uri = new Uri(_baseUrl + "top-headlines")
.AddQuery("apiKey", _key)
.AddQuery("q", query)
.AddQuery("sources", sources)
.AddQuery("language", lang.ToString())
.AddQuery("domains", domains);
HttpResponseMessage response = await _client.GetAsync(uri);
response.EnsureSuccessStatusCode();
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ var api = new NewsAPIClient("api-key");

var sources = await api.GetSourcesAsync();

var everything = await api.GetEverythingAsync("bitcoin", "sources", "domains");
var everything = await api.GetEverythingAsync("bitcoin", "sources", "domains", Language.ENGLISH);

var topHeadlines = await api.GetTopHeadlinesAsync("dotnet", "sources", "domains");
var topHeadlines = await api.GetTopHeadlinesAsync("dotnet", "sources", "domains", Language.ENGLISH);
```

# Documentation
- under construction
## Documentation
- under construction


## License
We abide by the MIT License, provided [here](https://github.com/The-Grape-Vine/NewsAPI.Net/blob/master/LICENSE).


0 comments on commit ce2d9f7

Please sign in to comment.