diff --git a/NotifyScreenAPI.sln b/NotifyScreenAPI.sln new file mode 100644 index 0000000..e2a3dbc --- /dev/null +++ b/NotifyScreenAPI.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30204.135 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NotifyScreenAPI", "NotifyScreenAPI\NotifyScreenAPI.csproj", "{E51D5F1D-4EED-4CAB-8087-DE32CCD9F5DB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E51D5F1D-4EED-4CAB-8087-DE32CCD9F5DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E51D5F1D-4EED-4CAB-8087-DE32CCD9F5DB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E51D5F1D-4EED-4CAB-8087-DE32CCD9F5DB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E51D5F1D-4EED-4CAB-8087-DE32CCD9F5DB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7B599808-868D-4F28-A138-4429BFBF8505} + EndGlobalSection +EndGlobal diff --git a/NotifyScreenAPI/Controllers/FetchController.cs b/NotifyScreenAPI/Controllers/FetchController.cs new file mode 100644 index 0000000..1f02b57 --- /dev/null +++ b/NotifyScreenAPI/Controllers/FetchController.cs @@ -0,0 +1,53 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using NotifyScreenAPI.Models; +using NotifyScreenAPI.Models.Facebook; +using NotifyScreenAPI.Models.Instagram; +using NotifyScreenAPI.Models.YouTube; +using NotifyScreenAPI.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace NotifyScreenAPI.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class FetchController : ControllerBase + { + public ISocialDataService _ISocialDataService; + private readonly IConfiguration _config; + private Settings _settings; + + + public FetchController(ISocialDataService ISocialDataService, IConfiguration config, + IOptions settings) + { + _ISocialDataService = ISocialDataService; + _config = config; + _settings = settings.Value; + + } + [Route("getData")] + [HttpGet] + public async Task> getData() + { + var path = _settings.Path; + var facebookJson = await _ISocialDataService.Read(path + "facebook.txt"); + var instagramJson = await _ISocialDataService.Read(path + "instagram.txt"); + var youtubeJson = await _ISocialDataService.Read(path+ "youtube.txt"); + + var r = new FetchResponse(); + r.facebook = new FacebookData() { Comments = facebookJson.CommentsCount, Likes = facebookJson.LikesCount }; + + r.instagram = new InstagramData() { Follows = instagramJson.NumberOfFollowers }; + r.youtube = new YouTubeData() { Views = youtubeJson.NumberOfViews }; + + var res = new ServiceResponse() { Data = r, Message = "Success", Success = true }; + return res; + } + } +} diff --git a/NotifyScreenAPI/Controllers/SocialDataController.cs b/NotifyScreenAPI/Controllers/SocialDataController.cs new file mode 100644 index 0000000..df6ee75 --- /dev/null +++ b/NotifyScreenAPI/Controllers/SocialDataController.cs @@ -0,0 +1,84 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; +using NotifyScreenAPI.Models; +using NotifyScreenAPI.Models.Facebook; +using NotifyScreenAPI.Models.Instagram; +using NotifyScreenAPI.Models.YouTube; +using NotifyScreenAPI.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace NotifyScreenAPI.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class SocialDataController : ControllerBase + { + public ISocialDataService _ISocialDataService; + private Settings _settings; + public string path; + public SocialDataController(ISocialDataService ISocialDataService, IConfiguration config, + IOptions settings) + { + _ISocialDataService = ISocialDataService; + _settings = settings.Value; + path = _settings.Path; + } + [Route("getFacebookData")] + [HttpPost] + public async Task> GetFacebookData(FacebookRequest facebookRequest) + { + _ISocialDataService.Write(facebookRequest,path +"facebook.txt"); + var fileJson = await _ISocialDataService.Read(path +"facebook.txt"); + + var c = new Comment + { + Number = fileJson.CommentsCount + }; + + var l = new Like + { + Number = fileJson.LikesCount + }; + + var r = new FacebookResponse + { + Comments = c, + Likes = l + }; + + + var res = new ServiceResponse() { Data = r, Message = "Success", Success = true }; + return res; + } + + [Route("getInstagramData")] + [HttpPost] + public async Task> GetInsatagramData(InstagramRequest instagramRequest) + { + + _ISocialDataService.Write(instagramRequest, path + "instagram.txt"); + var fileJson = await _ISocialDataService.Read(path +"instagram.txt"); + var r = new InstagramResponse() { NumberOfFollowers = fileJson.NumberOfFollowers }; + var res = new ServiceResponse() { Data = r, Message = "Success", Success = true }; + return res; + } + + [Route("getYoutubeData")] + [HttpPost] + public async Task> GetYouTubeData(YouTubeRequest youtubeRequest) + { + + _ISocialDataService.Write(youtubeRequest, path + "youtube.txt"); + var fileJson = await _ISocialDataService.Read(path +"youtube.txt"); + var r = new YouTubeResponse() { NumberOfViews = fileJson.NumberOfViews }; + var res = new ServiceResponse() { Data = r, Message = "Success", Success = true }; + + return res; + } + } +} diff --git a/NotifyScreenAPI/Controllers/WeatherForecastController.cs b/NotifyScreenAPI/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..9209ed6 --- /dev/null +++ b/NotifyScreenAPI/Controllers/WeatherForecastController.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace NotifyScreenAPI.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/NotifyScreenAPI/Models/Facebook/FacebookRequest.cs b/NotifyScreenAPI/Models/Facebook/FacebookRequest.cs new file mode 100644 index 0000000..d65091c --- /dev/null +++ b/NotifyScreenAPI/Models/Facebook/FacebookRequest.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace NotifyScreenAPI.Models.Facebook +{ + public class FacebookRequest + { + public int LikesCount { get; set; } + public int CommentsCount { get; set; } + } +} diff --git a/NotifyScreenAPI/Models/Facebook/FacebookResponse.cs b/NotifyScreenAPI/Models/Facebook/FacebookResponse.cs new file mode 100644 index 0000000..8c4c72f --- /dev/null +++ b/NotifyScreenAPI/Models/Facebook/FacebookResponse.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace NotifyScreenAPI.Models.Facebook +{ + public class FacebookResponse + { + public Like Likes { get; set; } + public Comment Comments { get; set; } + } + public class Like + { + public int Number { get; set; } + } + public class Comment + { + public int Number { get; set; } + + } +} + diff --git a/NotifyScreenAPI/Models/FetchResponse.cs b/NotifyScreenAPI/Models/FetchResponse.cs new file mode 100644 index 0000000..4f0159d --- /dev/null +++ b/NotifyScreenAPI/Models/FetchResponse.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace NotifyScreenAPI.Models +{ + public class FetchResponse + { + public FacebookData facebook { get; set; } + public InstagramData instagram { get; set; } + public YouTubeData youtube { get; set; } + } + public class FacebookData + { + public int Likes { get; set; } + public int Comments { get; set; } + } + public class InstagramData + { + public int Follows { get; set; } + } + public class YouTubeData + { + public int Views { get; set; } + } +} diff --git a/NotifyScreenAPI/Models/Instagram/InstagramRequest.cs b/NotifyScreenAPI/Models/Instagram/InstagramRequest.cs new file mode 100644 index 0000000..be25d87 --- /dev/null +++ b/NotifyScreenAPI/Models/Instagram/InstagramRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace NotifyScreenAPI.Models.Instagram +{ + public class InstagramRequest + { + public int NumberOfFollowers { get; set; } + } +} diff --git a/NotifyScreenAPI/Models/Instagram/InstagramResponse.cs b/NotifyScreenAPI/Models/Instagram/InstagramResponse.cs new file mode 100644 index 0000000..d361cec --- /dev/null +++ b/NotifyScreenAPI/Models/Instagram/InstagramResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace NotifyScreenAPI.Models.Instagram +{ + public class InstagramResponse + { + public int NumberOfFollowers { get; set; } + } +} diff --git a/NotifyScreenAPI/Models/ServiceResponse.cs b/NotifyScreenAPI/Models/ServiceResponse.cs new file mode 100644 index 0000000..8989537 --- /dev/null +++ b/NotifyScreenAPI/Models/ServiceResponse.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace NotifyScreenAPI.Models +{ + public class ServiceResponse + { + public T Data { get; set; } + public bool Success { get; set; } + public string Message { get; set; } + + } +} diff --git a/NotifyScreenAPI/Models/Settings.cs b/NotifyScreenAPI/Models/Settings.cs new file mode 100644 index 0000000..0395bc7 --- /dev/null +++ b/NotifyScreenAPI/Models/Settings.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace NotifyScreenAPI.Models +{ + public class Settings + { + public string Path { get; set; } + } +} diff --git a/NotifyScreenAPI/Models/YouTube/YouTubeRequest.cs b/NotifyScreenAPI/Models/YouTube/YouTubeRequest.cs new file mode 100644 index 0000000..ae15fd7 --- /dev/null +++ b/NotifyScreenAPI/Models/YouTube/YouTubeRequest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace NotifyScreenAPI.Models.YouTube +{ + public class YouTubeRequest + { + public int NumberOfViews { get; set; } + } +} diff --git a/NotifyScreenAPI/Models/YouTube/YouTubeResponse.cs b/NotifyScreenAPI/Models/YouTube/YouTubeResponse.cs new file mode 100644 index 0000000..962ab33 --- /dev/null +++ b/NotifyScreenAPI/Models/YouTube/YouTubeResponse.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace NotifyScreenAPI.Models.YouTube +{ + public class YouTubeResponse + { + public int NumberOfViews { get; set; } + } +} diff --git a/NotifyScreenAPI/NotifyScreenAPI.csproj b/NotifyScreenAPI/NotifyScreenAPI.csproj new file mode 100644 index 0000000..46a4c6e --- /dev/null +++ b/NotifyScreenAPI/NotifyScreenAPI.csproj @@ -0,0 +1,12 @@ + + + + net5.0 + + + + + + + + diff --git a/NotifyScreenAPI/Program.cs b/NotifyScreenAPI/Program.cs new file mode 100644 index 0000000..29df64b --- /dev/null +++ b/NotifyScreenAPI/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace NotifyScreenAPI +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/NotifyScreenAPI/Properties/launchSettings.json b/NotifyScreenAPI/Properties/launchSettings.json new file mode 100644 index 0000000..8bc01fa --- /dev/null +++ b/NotifyScreenAPI/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:60543", + "sslPort": 44303 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "NotifyScreenAPI": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/NotifyScreenAPI/Services/SocialDataService.cs b/NotifyScreenAPI/Services/SocialDataService.cs new file mode 100644 index 0000000..42f35be --- /dev/null +++ b/NotifyScreenAPI/Services/SocialDataService.cs @@ -0,0 +1,28 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; + +namespace NotifyScreenAPI.Services +{ + public interface ISocialDataService + { + Task Read(string path); + void Write(T model,string path); + } + public class SocialDataService : ISocialDataService + { + + + public async Task Read(string path) + { + return await Task.Run(()=> JsonConvert.DeserializeObject(File.ReadAllText(path))); + } + public void Write(T model,string path) + { + File.WriteAllText(path, JsonConvert.SerializeObject(model)); + } + } +} diff --git a/NotifyScreenAPI/Startup.cs b/NotifyScreenAPI/Startup.cs new file mode 100644 index 0000000..9687892 --- /dev/null +++ b/NotifyScreenAPI/Startup.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; +using NotifyScreenAPI.Models; +using NotifyScreenAPI.Services; + +namespace NotifyScreenAPI +{ + public class Startup + { + [Obsolete] + public Startup(IConfiguration configuration, Microsoft.AspNetCore.Hosting.IHostingEnvironment env) + { + Configuration = configuration; + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); + // .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); + + // if (env.IsDevelopment()) + // { + // builder.AddUserSecrets(); + // } + + builder.AddEnvironmentVariables(); + Configuration = builder.Build(); + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.Configure(options => Configuration.GetSection("Settings").Bind(options)); + + services.AddScoped(); + services.AddControllers(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "NotifyScreenAPI", Version = "v1" }); + }); + + + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "NotifyScreenAPI v1")); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/NotifyScreenAPI/WeatherForecast.cs b/NotifyScreenAPI/WeatherForecast.cs new file mode 100644 index 0000000..d7ba078 --- /dev/null +++ b/NotifyScreenAPI/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace NotifyScreenAPI +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} diff --git a/NotifyScreenAPI/appsettings.Development.json b/NotifyScreenAPI/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/NotifyScreenAPI/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/NotifyScreenAPI/appsettings.json b/NotifyScreenAPI/appsettings.json new file mode 100644 index 0000000..b0fd52c --- /dev/null +++ b/NotifyScreenAPI/appsettings.json @@ -0,0 +1,14 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "Settings": { + "Path": "C:\\Users\\USER\\Desktop\\Server\\" + }, + "AllowedHosts": "*" + +}