Skip to content

Commit

Permalink
version 2.0.1
Browse files Browse the repository at this point in the history
hotfix workaround to challonge api bug
  • Loading branch information
Abrahamh08 committed Oct 17, 2021
1 parent 935edd3 commit 2ba7442
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 307 deletions.
70 changes: 10 additions & 60 deletions ChallongeApiWrapper/ChallongeApiWrapper.csproj
Original file line number Diff line number Diff line change
@@ -1,70 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk.Web" ToolsVersion="15.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Fizzi.Libraries.ChallongeApiWrapper</RootNamespace>
<AssemblyName>ChallongeApiWrapper</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<LangVersion>latest</LangVersion>
<OldToolsVersion>2.0</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<Reference Include="RestSharp">
<HintPath>..\packages\RestSharp.104.4.0\lib\net4\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ChallongeApiException.cs" />
<Compile Include="ChallongePortal.cs" />
<Compile Include="Match.cs" />
<Compile Include="Participant.cs" />
<Compile Include="SetScore.cs" />
<Compile Include="Tournament.cs" />
<Compile Include="Enums.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<PackageReference Include="RestSharp" Version="106.11.8-alpha.0.14" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="106.11.8-alpha.0.14" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
43 changes: 37 additions & 6 deletions ChallongeApiWrapper/ChallongePortal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
using System.Text;
using RestSharp;
using System.Xml.Linq;
using RestSharp.Serialization.Json;
using RestSharp.Serializers.NewtonsoftJson;
using System.Text.Json;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;

namespace Fizzi.Libraries.ChallongeApiWrapper
{
Expand Down Expand Up @@ -31,16 +36,29 @@ private void throwOnError(IRestResponse response)
}
}

[DataContract(Name = "tournament")]
private class TournamentWrapper
{
[DataMember(Name = "tournament")]
public Tournament Tournament;
}

public IEnumerable<Tournament> GetTournaments()
{
var request = new RestRequest("tournaments.xml", Method.GET);
var request = new RestRequest("tournaments.json", Method.GET);
request.AddParameter("api_key", ApiKey);
if (!string.IsNullOrWhiteSpace(Subdomain)) request.AddParameter("subdomain", Subdomain);

var response = client.Execute<List<Tournament>>(request);
// work around challonge api bug
var response = client.Execute(request);
throwOnError(response);

return response.Data;
var ms = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(response.Content));
var ser = new DataContractJsonSerializer(typeof(List<TournamentWrapper>));
var tournaments = ser.ReadObject(ms) as List<TournamentWrapper>;
ms.Close();

return tournaments.Select(x => x.Tournament).Reverse();
}

public Tournament ShowTournament(int tournamentId)
Expand All @@ -65,15 +83,28 @@ public IEnumerable<Match> GetMatches(int tournamentId)
return response.Data;
}

[DataContract(Name ="participant")]
private class ParticipantWrapper
{
[DataMember(Name = "participant")]
public Participant Participant;
}

public IEnumerable<Participant> GetParticipants(int tournamentId)
{
var request = new RestRequest(string.Format("tournaments/{0}/participants.xml", tournamentId), Method.GET);
var request = new RestRequest(string.Format("tournaments/{0}/participants.json", tournamentId), Method.GET);
request.AddParameter("api_key", ApiKey);

var response = client.Execute<List<Participant>>(request);
// work around challonge api bug
var response = client.Execute(request);
throwOnError(response);

return response.Data;
var ms = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(response.Content));
var ser = new DataContractJsonSerializer(typeof(List<ParticipantWrapper>));
var participants = ser.ReadObject(ms) as List<ParticipantWrapper>;
ms.Close();

return participants.Select(x => x.Participant);
}

public void SetParticipantMisc(int tournamentId, int participantId, string misc)
Expand Down
7 changes: 7 additions & 0 deletions ChallongeApiWrapper/Participant.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace Fizzi.Libraries.ChallongeApiWrapper
{
[DataContract(Name="participant")]
public class Participant
{
[DataMember(Name="id")]
public int Id { get; set; }
[DataMember(Name="name")]
public string Name { get; set; }
[DataMember(Name="challongeUsername")]
public string ChallongeUsername { get; set; }

[DataMember(Name="seed")]
public int Seed { get; set; }

[DataMember(Name="misc")]
public string Misc { get; set; }

public string NameOrUsername { get { return string.IsNullOrEmpty(Name) ? ChallongeUsername : Name; } }
Expand Down
15 changes: 15 additions & 0 deletions ChallongeApiWrapper/Tournament.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using Newtonsoft.Json;

namespace Fizzi.Libraries.ChallongeApiWrapper
{
[DataContract(Name = "tournament")]
public class Tournament
{
[DataMember(Name = "createdAt")]
public DateTime? CreatedAt { get; set; }
[DataMember(Name = "startedAt")]
public DateTime? StartedAt { get; set; }
[DataMember(Name = "completedAt")]
public DateTime? CompletedAt { get; set; }

[DataMember(Name = "name")]
public string Name { get; set; }
public string Description { get; set; }
[DataMember(Name = "id")]
public int Id { get; set; }

[DataMember(Name = "participantsCount")]
public int ParticipantsCount { get; set; }
[DataMember(Name = "progressMeter")]
public int ProgressMeter { get; set; }

[DataMember(Name = "state")]
public string State { get; set; }
[DataMember(Name = "tournamentType")]
public string TournamentType { get; set; }

[DataMember(Name = "url")]
public string Url { get; set; }
[DataMember(Name = "fullChallongeUrl")]
public string FullChallongeUrl { get; set; }
[DataMember(Name = "liveImageUrl")]
public string LiveImageUrl { get; set; }
}
}
4 changes: 3 additions & 1 deletion ChallongeApiWrapper/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="RestSharp" version="104.4.0" targetFramework="net40" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />
<package id="RestSharp" version="106.11.8-alpha.0.14" targetFramework="net472" />
<package id="RestSharp.Serializers.NewtonsoftJson" version="106.11.8-alpha.0.14" targetFramework="net472" />
</packages>
32 changes: 19 additions & 13 deletions ChallongeMatchDisplay.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
# Visual Studio 15
VisualStudioVersion = 15.0.28307.1525
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChallongeVisualization", "ChallongeMatchDisplay\ChallongeVisualization.csproj", "{CA5673AD-D9D2-4292-9921-6AD3FC041607}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChallongeVisualization", "ChallongeMatchDisplay\ChallongeVisualization.csproj", "{CA5673AD-D9D2-4292-9921-6AD3FC041607}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChallongeApiWrapper", "ChallongeApiWrapper\ChallongeApiWrapper.csproj", "{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChallongeApiWrapper", "ChallongeApiWrapper\ChallongeApiWrapper.csproj", "{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SandBox", "SandBox\SandBox.csproj", "{70FEB780-FDBF-460B-849D-1CA6213E7202}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SandBox", "SandBox\SandBox.csproj", "{70FEB780-FDBF-460B-849D-1CA6213E7202}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -22,31 +22,34 @@ Global
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|Any CPU.ActiveCfg = Debug|x64
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|Mixed Platforms.ActiveCfg = Debug|x64
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|Mixed Platforms.Build.0 = Debug|x64
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x64.ActiveCfg = Debug|x64
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x64.Build.0 = Debug|x64
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x86.ActiveCfg = Debug|x86
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x86.Build.0 = Debug|x86
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|Any CPU.Build.0 = Debug|x64
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x64.ActiveCfg = Debug|Any CPU
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x64.Build.0 = Debug|Any CPU
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x86.ActiveCfg = Debug|Any CPU
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Debug|x86.Build.0 = Debug|Any CPU
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|Any CPU.ActiveCfg = Release|x64
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|Mixed Platforms.ActiveCfg = Release|x64
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|Mixed Platforms.Build.0 = Release|x64
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|x64.ActiveCfg = Release|x64
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|x64.Build.0 = Release|x64
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|x64.ActiveCfg = Release|Any CPU
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|x64.Build.0 = Release|Any CPU
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|x86.ActiveCfg = Release|x86
{CA5673AD-D9D2-4292-9921-6AD3FC041607}.Release|x86.Build.0 = Release|x86
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|x64.ActiveCfg = Debug|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|x64.Build.0 = Debug|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|x86.ActiveCfg = Debug|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Debug|x86.Build.0 = Debug|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|Any CPU.Build.0 = Release|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|x64.ActiveCfg = Release|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|x64.Build.0 = Release|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|x86.ActiveCfg = Release|Any CPU
{BEC62B0A-47BA-4018-9EF8-A6B159AA11E4}.Release|x86.Build.0 = Release|Any CPU
{70FEB780-FDBF-460B-849D-1CA6213E7202}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -69,4 +72,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C8047850-B82B-4321-99B0-1E4E6B6BE2B1}
EndGlobalSection
EndGlobal
Loading

0 comments on commit 2ba7442

Please sign in to comment.