-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from granstel/youtube
Youtube
- Loading branch information
Showing
29 changed files
with
296 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 3 additions & 51 deletions
54
Dodo1000Bot.Api/DependencyModules/ExternalServicesRegistration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,23 @@ | ||
using System; | ||
using Dodo1000Bot.Api.Extensions; | ||
using Dodo1000Bot.Api.Extensions; | ||
using Dodo1000Bot.Services; | ||
using Dodo1000Bot.Services.Clients; | ||
using Google.Apis.Auth.OAuth2; | ||
using Google.Cloud.Dialogflow.V2; | ||
using Dodo1000Bot.Services.Configuration; | ||
using GranSteL.Helpers.Redis; | ||
using Grpc.Auth; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using StackExchange.Redis; | ||
|
||
namespace Dodo1000Bot.Api.DependencyModules | ||
{ | ||
internal static class ExternalServicesRegistration | ||
{ | ||
internal static void AddExternalServices(this IServiceCollection services, AppConfiguration configuration) | ||
{ | ||
services.AddSingleton<SessionsClient>(RegisterDialogflowSessionsClient); | ||
|
||
services.AddSingleton<IDatabase>(RegisterRedisClient); | ||
|
||
services.AddSingleton<IRedisCacheService>(RegisterCacheService); | ||
|
||
services.AddHttpClient<IGlobalApiClient, GlobalApiClient>(configuration.GlobalApiEndpoint, | ||
nameof(configuration.GlobalApiEndpoint)); | ||
services.AddHttpClient<IRealtimeBoardApiClient, RealtimeBoardApiClient>(configuration.RealtimeBoardApiClientEndpoint, | ||
nameof(configuration.RealtimeBoardApiClientEndpoint)); | ||
services.AddHttpClient<IRestcountriesApiClient, RestcountriesApiClient>(configuration.RestcountriesApiClientEndpoint, | ||
nameof(configuration.RestcountriesApiClientEndpoint)); | ||
} | ||
|
||
private static SessionsClient RegisterDialogflowSessionsClient(IServiceProvider provider) | ||
{ | ||
var configuration = provider.GetService<DialogflowConfiguration>(); | ||
|
||
var credential = GoogleCredential.FromFile(configuration.JsonPath).CreateScoped(SessionsClient.DefaultScopes); | ||
|
||
var clientBuilder = new SessionsClientBuilder | ||
{ | ||
ChannelCredentials = credential.ToChannelCredentials() | ||
}; | ||
|
||
var client = clientBuilder.Build(); | ||
|
||
return client; | ||
} | ||
|
||
private static IDatabase RegisterRedisClient(IServiceProvider provider) | ||
{ | ||
var configuration = provider.GetService<RedisConfiguration>(); | ||
|
||
var redisClient = ConnectionMultiplexer.Connect(configuration.ConnectionString); | ||
|
||
var dataBase = redisClient.GetDatabase(); | ||
|
||
return dataBase; | ||
} | ||
|
||
private static RedisCacheService RegisterCacheService(IServiceProvider provider) | ||
{ | ||
var configuration = provider.GetService<RedisConfiguration>(); | ||
|
||
var db = provider.GetService<IDatabase>(); | ||
|
||
var service = new RedisCacheService(db, configuration.KeyPrefix); | ||
|
||
return service; | ||
services.AddHttpClient<IYouTubeClient, YouTubeClient>(configuration.YouTube.Endpoint, | ||
nameof(configuration.YouTube)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using Dodo1000Bot.Services; | ||
using Dodo1000Bot.Services.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Dodo1000Bot.Api.Jobs; | ||
|
||
public class YoutubeCheckAndNotifyJob: CheckAndNotifyJob<YoutubeService, YoutubeConfiguration> | ||
{ | ||
public YoutubeCheckAndNotifyJob( | ||
ILogger<YoutubeCheckAndNotifyJob> log, | ||
IServiceProvider provider, | ||
YoutubeConfiguration configuration) : base(log, provider, configuration) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace Dodo1000Bot.Models.Youtube; | ||
|
||
public class SearchResponse | ||
{ | ||
public Video[] Items { get; set; } | ||
} | ||
|
||
public class Video | ||
{ | ||
public Id Id { get; set; } | ||
public Snippet Snippet { get; set; } | ||
} | ||
|
||
public class Id | ||
{ | ||
public string VideoId { get; set; } | ||
} | ||
|
||
public class Snippet | ||
{ | ||
public string PublishedAt { get; set; } | ||
public string LiveBroadcastContent { get; set; } | ||
public string PublishTime { get; set; } | ||
public string Title { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.