Skip to content

Commit

Permalink
Remove old twitch API calls
Browse files Browse the repository at this point in the history
Move last remaining v5 api call to helix, search games -> search categories
  • Loading branch information
laurencee committed Feb 9, 2022
1 parent e3b24d7 commit 72e9738
Show file tree
Hide file tree
Showing 46 changed files with 64 additions and 1,033 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,6 @@ FakesAssemblies/
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml

# Credentials
twitchaccesstoken.local
7 changes: 5 additions & 2 deletions ExternalAPIs.Tests/ExternalAPIs.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@
</Choose>
<ItemGroup>
<Compile Include="TwitchTvHelixClientShould.cs" />
<Compile Include="TwitchTvV5ClientShould.cs" />
<Compile Include="YoutubeClientShould.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TwitchTvV3ClientShould.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand All @@ -87,6 +85,11 @@
<ItemGroup>
<Analyzer Include="..\packages\xunit.analyzers.0.10.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
</ItemGroup>
<ItemGroup>
<Content Include="twitchaccesstoken.local">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
Expand Down
18 changes: 18 additions & 0 deletions ExternalAPIs.Tests/TwitchTvHelixClientShould.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using ExternalAPIs.TwitchTv.Helix;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using ExternalAPIs.TwitchTv.Helix.Query;
using Xunit;
Expand All @@ -19,6 +20,13 @@ public class TwitchTvHelixClientShould

private readonly TwitchTvHelixHelixReadonlyClient sut = new TwitchTvHelixHelixReadonlyClient();

public TwitchTvHelixClientShould()
{
// create this file locally, it's already marked to be copied to the output in this test project
var twitchAccessToken = File.ReadAllText("twitchaccesstoken.local");
sut.SetAccessToken(twitchAccessToken);
}

[Fact]
public async Task GetUser()
{
Expand Down Expand Up @@ -97,5 +105,15 @@ public async Task GetChannelVideos(string userId)
Assert.NotNull(channelVideos);
Assert.NotEmpty(channelVideos.Videos);
}

[InlineData("League of Legends")]
[InlineData("Just Chatting")]
[Theory]
public async Task SearchCategories(string category)
{
var twitchCategories = await sut.SearchCategories(category);
Assert.NotNull(twitchCategories);
Assert.NotEmpty(twitchCategories);
}
}
}
133 changes: 0 additions & 133 deletions ExternalAPIs.Tests/TwitchTvV3ClientShould.cs

This file was deleted.

41 changes: 0 additions & 41 deletions ExternalAPIs.Tests/TwitchTvV5ClientShould.cs

This file was deleted.

31 changes: 0 additions & 31 deletions ExternalAPIs/ExternalAPIs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,39 +67,8 @@
<Compile Include="TwitchTv\Helix\Query\GetVideosQuery.cs" />
<Compile Include="TwitchTv\Helix\RequestConstants.cs" />
<Compile Include="TwitchTv\Helix\TwitchTvHelixHelixReadonlyClient.cs" />
<Compile Include="TwitchTv\V3\Dto\Channel.cs" />
<Compile Include="TwitchTv\V3\Dto\ChannelLinks.cs" />
<Compile Include="TwitchTv\V3\Dto\Follow.cs" />
<Compile Include="TwitchTv\V3\Dto\Fps.cs" />
<Compile Include="TwitchTv\V3\Dto\Game.cs" />
<Compile Include="TwitchTv\V3\Dto\PreviewImage.cs" />
<Compile Include="TwitchTv\V3\Dto\QueryRoot\ChannelVideosRoot.cs" />
<Compile Include="TwitchTv\V3\Dto\QueryRoot\GamesRoot.cs" />
<Compile Include="TwitchTv\V3\Dto\QueryRoot\StreamRoot.cs" />
<Compile Include="TwitchTv\V3\Dto\QueryRoot\StreamsRoot.cs" />
<Compile Include="TwitchTv\V3\Dto\QueryRoot\TopGamesRoot.cs" />
<Compile Include="TwitchTv\V3\Dto\QueryRoot\UserFollows.cs" />
<Compile Include="TwitchTv\V3\Dto\Resolutions.cs" />
<Compile Include="TwitchTv\V3\Dto\Stream.cs" />
<Compile Include="TwitchTv\V3\Dto\Thumbnail.cs" />
<Compile Include="TwitchTv\V3\Dto\TopGame.cs" />
<Compile Include="TwitchTv\V3\Dto\Video.cs" />
<Compile Include="TwitchTv\V3\Converters\SingleOrArrayConverter.cs" />
<Compile Include="TwitchTv\V3\Converters\SingleOrArrayThumbnailConverter.cs" />
<Compile Include="TwitchTv\V3\ITwitchTvV3ReadonlyClient.cs" />
<Compile Include="TwitchTv\V3\Query\ChannelVideosQuery.cs" />
<Compile Include="PagedQuery.cs" />
<Compile Include="TopStreamQuery.cs" />
<Compile Include="TwitchTv\V3\RequestConstants.cs" />
<Compile Include="TwitchTv\V3\TwitchTvV3V3ReadonlyClient.cs" />
<Compile Include="TwitchTv\V5\Dto\Box.cs" />
<Compile Include="TwitchTv\V5\Dto\Game.cs" />
<Compile Include="TwitchTv\V5\Dto\QueryRoot\GamesRoot.cs" />
<Compile Include="TwitchTv\V5\Dto\TopGame.cs" />
<Compile Include="TwitchTv\V5\Dto\QueryRoot\TopGamesRoot.cs" />
<Compile Include="TwitchTv\V5\ITwitchTvV5ReadonlyClient.cs" />
<Compile Include="TwitchTv\V5\RequestConstants.cs" />
<Compile Include="TwitchTv\V5\TwitchTvV5ReadonlyClient.cs" />
<Compile Include="Youtube\Dto\Id.cs" />
<Compile Include="Youtube\Dto\Item.cs" />
<Compile Include="Youtube\Dto\LiveStreamingDetails.cs" />
Expand Down
6 changes: 3 additions & 3 deletions ExternalAPIs/TwitchTv/Helix/Dto/TopGames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

namespace ExternalAPIs.TwitchTv.Helix.Dto
{
public class TopGamesRoot
public class TopCategoriesRoot
{
[JsonProperty("data")]
public List<TopGame> TopGames { get; set; }
public List<TwitchCategory> TopCategories { get; set; }

[JsonProperty("pagination")]
public Pagination Pagination { get; set; }
}

public class TopGame
public class TwitchCategory
{
[JsonProperty("id")]
public string Id { get; set; }
Expand Down
4 changes: 3 additions & 1 deletion ExternalAPIs/TwitchTv/Helix/ITwitchTvHelixReadonlyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface ITwitchTvHelixReadonlyClient

Task<StreamsRoot> GetStreams(GetStreamsQuery getStreamsQuery, CancellationToken cancellationToken = default);

Task<List<TopGame>> GetTopGames(CancellationToken cancellationToken = default);
Task<List<TwitchCategory>> GetTopGames(CancellationToken cancellationToken = default);

Task<User> GetUserByUsername(string username, CancellationToken cancellationToken = default);

Expand All @@ -22,6 +22,8 @@ public interface ITwitchTvHelixReadonlyClient

Task<List<Game>> GetGames(GetGamesQuery getGamesQuery, CancellationToken cancellationToken = default);

Task<List<TwitchCategory>> SearchCategories(string searchCategory, CancellationToken cancellationToken = default);

void SetAccessToken(string accessToken);
}
}
1 change: 1 addition & 0 deletions ExternalAPIs/TwitchTv/Helix/RequestConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class RequestConstants
public const string TwitchTvApiRoot = "https://api.twitch.tv/helix";
public const string UserFollows = TwitchTvApiRoot + "/users/follows?from_id={0}";
public const string Streams = TwitchTvApiRoot + "/streams";
public const string SearchCategories = TwitchTvApiRoot + "/search/categories";
public const string Games = TwitchTvApiRoot + "/games";
public const string Videos = TwitchTvApiRoot + "/videos";
public const string TopGames = TwitchTvApiRoot + "/games/top";
Expand Down
17 changes: 14 additions & 3 deletions ExternalAPIs/TwitchTv/Helix/TwitchTvHelixHelixReadonlyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public async Task<StreamsRoot> GetStreams(GetStreamsQuery getStreamsQuery, Cance
return streamsRoot;
}

public async Task<List<TopGame>> GetTopGames(CancellationToken cancellationToken = default)
public async Task<List<TwitchCategory>> GetTopGames(CancellationToken cancellationToken = default)
{
var request = RequestConstants.TopGames;
var gamesRoot = await ExecuteRequest<TopGamesRoot>(request, cancellationToken);
return gamesRoot.TopGames;
var topCategoriesRoot = await ExecuteRequest<TopCategoriesRoot>(request, cancellationToken);
return topCategoriesRoot.TopCategories;
}

public async Task<User> GetUserByUsername(string username, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -189,6 +189,17 @@ public async Task<VideosRoot> GetVideos(GetVideosQuery getVideosQuery, Cancellat
return channelVideosRoot;
}

public async Task<List<TwitchCategory>> SearchCategories(string searchCategory, CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(searchCategory))
throw new ArgumentException("Value cannot be null or empty.", nameof(searchCategory));

var request = RequestConstants.SearchCategories + "?query=" + searchCategory;

var topCategoriesRoot = await ExecuteRequest<TopCategoriesRoot>(request, cancellationToken);
return topCategoriesRoot.TopCategories;
}

public void SetAccessToken(string accessToken)
{
_accessToken = accessToken;
Expand Down
Loading

0 comments on commit 72e9738

Please sign in to comment.