mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
OddsService WIP
This commit is contained in:
parent
e49daefae3
commit
8ec099f688
BIN
.vs/MyCore/DesignTimeBuild/.dtbcache
Normal file
BIN
.vs/MyCore/DesignTimeBuild/.dtbcache
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -8,6 +8,8 @@ using MQTTnet;
|
|||||||
using MQTTnet.Client;
|
using MQTTnet.Client;
|
||||||
using MQTTnet.Server;
|
using MQTTnet.Server;
|
||||||
using MyCore.Models;
|
using MyCore.Models;
|
||||||
|
using MyCore.Services;
|
||||||
|
using static MyCore.Services.OddService;
|
||||||
|
|
||||||
namespace MyCore.Controllers
|
namespace MyCore.Controllers
|
||||||
{
|
{
|
||||||
@ -16,6 +18,9 @@ namespace MyCore.Controllers
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class ValuesController : ControllerBase
|
public class ValuesController : ControllerBase
|
||||||
{
|
{
|
||||||
|
private OddService oddService = new OddService(OddService.RegionOdd.UK);
|
||||||
|
|
||||||
|
|
||||||
// GET api/values
|
// GET api/values
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// It's a test ! :)
|
/// It's a test ! :)
|
||||||
@ -27,6 +32,28 @@ namespace MyCore.Controllers
|
|||||||
{
|
{
|
||||||
WidgetWeather widgetWeather = new WidgetWeather();
|
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" };
|
return new string[] { "value1", "value2" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
32
MyCore/DTO/Odd.cs
Normal file
32
MyCore/DTO/Odd.cs
Normal file
@ -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<string> Teams;
|
||||||
|
public int Commence_time;
|
||||||
|
public string Home_team;
|
||||||
|
public List<OddSite> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -12,7 +12,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="DTO\" />
|
|
||||||
<Folder Include="wwwroot\" />
|
<Folder Include="wwwroot\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
117
MyCore/Services/OddService.cs
Normal file
117
MyCore/Services/OddService.cs
Normal file
@ -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<League> allLeagues = new List<League>();
|
||||||
|
|
||||||
|
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<List<Odd>> GetOddsForLeague(League league)
|
||||||
|
{
|
||||||
|
List<Odd> oddsToReturn = new List<Odd>();
|
||||||
|
|
||||||
|
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<Odd> GetOddsForAllLeagues()
|
||||||
|
{
|
||||||
|
List<Odd> oddsToReturn = new List<Odd>();
|
||||||
|
return oddsToReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user