diff --git a/.vs/MyCore/DesignTimeBuild/.dtbcache b/.vs/MyCore/DesignTimeBuild/.dtbcache new file mode 100644 index 0000000..e42343d Binary files /dev/null and b/.vs/MyCore/DesignTimeBuild/.dtbcache differ diff --git a/.vs/MyCore/v15/Server/sqlite3/storage.ide b/.vs/MyCore/v15/Server/sqlite3/storage.ide index 03ed2c6..ace4fd9 100644 Binary files a/.vs/MyCore/v15/Server/sqlite3/storage.ide and b/.vs/MyCore/v15/Server/sqlite3/storage.ide differ diff --git a/.vs/MyCore/v15/Server/sqlite3/storage.ide-shm b/.vs/MyCore/v15/Server/sqlite3/storage.ide-shm index e5f9e40..8131853 100644 Binary files a/.vs/MyCore/v15/Server/sqlite3/storage.ide-shm and b/.vs/MyCore/v15/Server/sqlite3/storage.ide-shm differ diff --git a/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal b/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal index a8ce292..f80eca8 100644 Binary files a/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal and b/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal differ diff --git a/MyCore/Controllers/ValuesController.cs b/MyCore/Controllers/ValuesController.cs index cbc5fd0..81a094f 100644 --- a/MyCore/Controllers/ValuesController.cs +++ b/MyCore/Controllers/ValuesController.cs @@ -8,6 +8,8 @@ using MQTTnet; using MQTTnet.Client; using MQTTnet.Server; using MyCore.Models; +using MyCore.Services; +using static MyCore.Services.OddService; namespace MyCore.Controllers { @@ -16,6 +18,9 @@ namespace MyCore.Controllers [ApiController] public class ValuesController : ControllerBase { + private OddService oddService = new OddService(OddService.RegionOdd.UK); + + // GET api/values /// /// It's a test ! :) @@ -27,6 +32,28 @@ namespace MyCore.Controllers { WidgetWeather widgetWeather = new WidgetWeather(); + try + { + League league = new League("BE"); + oddService.GetOddsForLeague(league).ContinueWith(res => + { + if (res.Status == TaskStatus.RanToCompletion) + { + var test = res.Result; + } + else + { + + } + }); ; + } + catch (Exception e) + { + Console.WriteLine(e); + } + + + return new string[] { "value1", "value2" }; } diff --git a/MyCore/DTO/Odd.cs b/MyCore/DTO/Odd.cs new file mode 100644 index 0000000..5eed4f0 --- /dev/null +++ b/MyCore/DTO/Odd.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyCore.DTO +{ + public class Odd + { + public string Sport_nice; + public List Teams; + public int Commence_time; + public string Home_team; + public List Sites; + + } + + public class OddSite + { + public string Site_key; + public string Site_nice; + public int Last_update; + public OddMatch OddMatch; + } + + public class OddMatch + { + public double HomeOdd; + public double DrawOdd; + public double VisitOdd; + } +} diff --git a/MyCore/MyCore.csproj b/MyCore/MyCore.csproj index 29853f9..34fa4e7 100644 --- a/MyCore/MyCore.csproj +++ b/MyCore/MyCore.csproj @@ -12,7 +12,6 @@ - diff --git a/MyCore/Services/OddService.cs b/MyCore/Services/OddService.cs new file mode 100644 index 0000000..abbd015 --- /dev/null +++ b/MyCore/Services/OddService.cs @@ -0,0 +1,117 @@ +using MyCore.DTO; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using System.Web; + +namespace MyCore.Services +{ + public class OddService + { + private HttpClient _client = new HttpClient(); + private string _servicePoint = "https://api.the-odds-api.com/v3/odds/?"; + private string _apiKey = "285d0ebdb4b29415f6fef8b83729f655"; + private string _url; + private string _region; + + public List allLeagues = new List(); + + public class League + { + public string ApiIdentifiant { get; set; } + + public League(string league) { + switch (league) + { + case "BE": + ApiIdentifiant = "soccer_belgium_first_div"; + break; + case "UK": + ApiIdentifiant = "soccer_epl"; + break; + case "DK": + ApiIdentifiant = "soccer_denmark_superliga"; + break; + case "FR": + ApiIdentifiant = "soccer_france_ligue_one"; + break; + case "DE": + ApiIdentifiant = "soccer_germany_bundesliga"; + break; + case "IT": + ApiIdentifiant = "soccer_italy_serie_a"; + break; + case "NE": + ApiIdentifiant = "soccer_netherlands_eredivisie"; + break; + case "PT": + ApiIdentifiant = "soccer_portugal_primeira_liga"; + break; + case "RU": + ApiIdentifiant = "soccer_russia_premier_league"; + break; + case "ES": + ApiIdentifiant = "soccer_spain_la_liga"; + break; + case "CH": + ApiIdentifiant = "soccer_switzerland_superleague"; + break; + case "TR": + ApiIdentifiant = "soccer_turkey_super_league"; + break; + default: + ApiIdentifiant = "soccer_epl"; + break; + + } + } + } + + public class RegionOdd + { + public static string UK { get; set; } = "uk"; + public static string US { get; set; } = "us"; + public static string AU { get; set; } = "au"; + } + + public OddService(string region) + { + + _region = region; + + _url = $"{_servicePoint}apiKey={_apiKey}®ion={_region}"; + + _client.BaseAddress = new Uri(_url); + } + + public async Task> GetOddsForLeague(League league) + { + List oddsToReturn = new List(); + + var builder = new UriBuilder(_servicePoint); + builder.Port = -1; + var query = HttpUtility.ParseQueryString(builder.Query); + query["apiKey"] = _apiKey; + query["region"] = _region; + query["sport"] = league.ApiIdentifiant; + builder.Query = query.ToString(); + string url = builder.ToString(); + + _client.BaseAddress = new Uri(url); + var result = await _client.GetAsync(url); + + Console.WriteLine(result.StatusCode); + + return oddsToReturn; + } + + public List GetOddsForAllLeagues() + { + List oddsToReturn = new List(); + return oddsToReturn; + } + + } +}