Add start of functionality to pull user's collection

This commit is contained in:
James Skemp 2019-01-03 20:06:48 -06:00
parent 5f7613fd35
commit 229d3fe5c6
5 changed files with 97 additions and 9 deletions

View File

@ -1,12 +1,57 @@
using System;
using System.IO;
using System.Net.Http;
using Microsoft.Extensions.Configuration;
namespace boardgamegeek_collection
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
class Program
{
private static IConfigurationRoot configuration;
static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
configuration = builder.Build();
Console.WriteLine(configuration["apiBaseUrl"]);
GetData();
Console.WriteLine("Hello World!");
Console.ReadLine();
Console.ReadKey();
}
static async void GetData()
{
string baseUrl = $"{configuration["apiBaseUrl"]}collection/{configuration["defaultUser"]}";
Console.WriteLine(baseUrl);
using (HttpClient client = new HttpClient())
{
using (HttpResponseMessage res = await client.GetAsync(baseUrl))
{
if (res.StatusCode == System.Net.HttpStatusCode.OK)
{
using (HttpContent content = res.Content)
{
string data = await content.ReadAsStringAsync();
if (data != null)
{
Console.WriteLine(data);
}
}
}
else
{
Console.WriteLine(res.StatusCode.ToString());
}
}
}
}
}
}

View File

@ -1,2 +1,13 @@
# boardgamegeek-collection
.NET Core application to pull a user's collection from Board Game Geek.
# BoardGameGeek Collection Data
[].NET Core 2] application to pull a user's collection from [BoardGameGeek][bgg].
This uses the [BGG XML API][bgg-xml-api] to pull information.
## Building the Application
> TODO
## Running the Application
> TODO
[bgg]: https://boardgamegeek.com/
[bgg-xml-api]: https://boardgamegeek.com/wiki/page/BGG_XML_API

4
appsettings.json Normal file
View File

@ -0,0 +1,4 @@
{
"apiBaseUrl": "https://www.boardgamegeek.com/xmlapi/",
"defaultUser": "strivinglife"
}

View File

@ -6,4 +6,15 @@
<RootNamespace>boardgamegeek_collection</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<None Remove="appsettings.json" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.json" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,17 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "boardgamegeek-collection", "boardgamegeek-collection.csproj", "{73693FE0-820F-499B-8345-5AA6232C5020}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{73693FE0-820F-499B-8345-5AA6232C5020}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73693FE0-820F-499B-8345-5AA6232C5020}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73693FE0-820F-499B-8345-5AA6232C5020}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73693FE0-820F-499B-8345-5AA6232C5020}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal