-
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.
- Loading branch information
tal
committed
Feb 7, 2021
1 parent
9495511
commit 97c0007
Showing
21 changed files
with
552 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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,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> settings) | ||
{ | ||
_ISocialDataService = ISocialDataService; | ||
_config = config; | ||
_settings = settings.Value; | ||
|
||
} | ||
[Route("getData")] | ||
[HttpGet] | ||
public async Task<ServiceResponse<FetchResponse>> getData() | ||
{ | ||
var path = _settings.Path; | ||
var facebookJson = await _ISocialDataService.Read<FacebookRequest>(path + "facebook.txt"); | ||
var instagramJson = await _ISocialDataService.Read<InstagramRequest>(path + "instagram.txt"); | ||
var youtubeJson = await _ISocialDataService.Read<YouTubeRequest>(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<FetchResponse>() { Data = r, Message = "Success", Success = true }; | ||
return res; | ||
} | ||
} | ||
} |
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,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> settings) | ||
{ | ||
_ISocialDataService = ISocialDataService; | ||
_settings = settings.Value; | ||
path = _settings.Path; | ||
} | ||
[Route("getFacebookData")] | ||
[HttpPost] | ||
public async Task<ServiceResponse<FacebookResponse>> GetFacebookData(FacebookRequest facebookRequest) | ||
{ | ||
_ISocialDataService.Write(facebookRequest,path +"facebook.txt"); | ||
var fileJson = await _ISocialDataService.Read<FacebookRequest>(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<FacebookResponse>() { Data = r, Message = "Success", Success = true }; | ||
return res; | ||
} | ||
|
||
[Route("getInstagramData")] | ||
[HttpPost] | ||
public async Task<ServiceResponse<InstagramResponse>> GetInsatagramData(InstagramRequest instagramRequest) | ||
{ | ||
|
||
_ISocialDataService.Write(instagramRequest, path + "instagram.txt"); | ||
var fileJson = await _ISocialDataService.Read<InstagramRequest>(path +"instagram.txt"); | ||
var r = new InstagramResponse() { NumberOfFollowers = fileJson.NumberOfFollowers }; | ||
var res = new ServiceResponse<InstagramResponse>() { Data = r, Message = "Success", Success = true }; | ||
return res; | ||
} | ||
|
||
[Route("getYoutubeData")] | ||
[HttpPost] | ||
public async Task<ServiceResponse<YouTubeResponse>> GetYouTubeData(YouTubeRequest youtubeRequest) | ||
{ | ||
|
||
_ISocialDataService.Write(youtubeRequest, path + "youtube.txt"); | ||
var fileJson = await _ISocialDataService.Read<YouTubeRequest>(path +"youtube.txt"); | ||
var r = new YouTubeResponse() { NumberOfViews = fileJson.NumberOfViews }; | ||
var res = new ServiceResponse<YouTubeResponse>() { Data = r, Message = "Success", Success = true }; | ||
|
||
return res; | ||
} | ||
} | ||
} |
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,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<WeatherForecastController> _logger; | ||
|
||
public WeatherForecastController(ILogger<WeatherForecastController> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
[HttpGet] | ||
public IEnumerable<WeatherForecast> 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(); | ||
} | ||
} | ||
} |
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,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; } | ||
} | ||
} |
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,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; } | ||
|
||
} | ||
} | ||
|
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,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; } | ||
} | ||
} |
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,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; } | ||
} | ||
} |
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,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; } | ||
} | ||
} |
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,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace NotifyScreenAPI.Models | ||
{ | ||
public class ServiceResponse<T> | ||
{ | ||
public T Data { get; set; } | ||
public bool Success { get; set; } | ||
public string Message { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
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,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; } | ||
} | ||
} |
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,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; } | ||
} | ||
} |
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,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,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<Startup>(); | ||
}); | ||
} | ||
} |
Oops, something went wrong.