Skip to content

Commit

Permalink
added color list, added spectre.console tables for nicer display in t…
Browse files Browse the repository at this point in the history
…he demos

closes #4
  • Loading branch information
stephanstapel committed Aug 4, 2024
1 parent 681bcb6 commit 9fc43fa
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 8 deletions.
19 changes: 16 additions & 3 deletions BrickOwlSharp.Client/BrickOwlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
using BrickOwlSharp.Client.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Security.Cryptography;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
Expand Down Expand Up @@ -208,7 +210,7 @@ public async Task<List<string>> CatalogIdLookupAsync(string boid, ItemType type,
CatalogItemIds result = await ExecuteGet<CatalogItemIds>(url, cancellationToken);
_measureRequest(ResourceType.Catalog, cancellationToken);
return result.BOIDs;
}
} // !CatalogIdLookupAsync()


public async Task<NewInventoryResult> CreateInventoryAsync(
Expand All @@ -226,7 +228,7 @@ public async Task<NewInventoryResult> CreateInventoryAsync(
NewInventoryResult result = await ExecutePost<NewInventoryResult>(url, formData, cancellationToken: cancellationToken);
_measureRequest(ResourceType.Inventory, cancellationToken);
return result;
}
} // !CreateInventoryAsync()


public async Task<bool> UpdateInventoryAsync(
Expand All @@ -239,7 +241,7 @@ public async Task<bool> UpdateInventoryAsync(
BrickOwlResult result = await ExecutePost<BrickOwlResult>(url, formData, cancellationToken: cancellationToken);
_measureRequest(ResourceType.Inventory, cancellationToken);
return (result?.Status == "success");
}
} // !UpdateInventoryAsync()


public async Task<List<Inventory>> GetInventoryAsync(
Expand Down Expand Up @@ -277,6 +279,17 @@ public async Task<bool> DeleteInventoryAsync(
} // !GetInventoryAsync()


public async Task<List<Color>> GetColorListAsyn(CancellationToken cancellationToken = default)
{
var url = new Uri(_baseUri, $"catalog/color_list").ToString();

Dictionary<string, Color> result = await ExecuteGet<Dictionary<string, Color>>(url, cancellationToken);
_measureRequest(ResourceType.Catalog, cancellationToken);
return result.Values.ToList();
} // !GetColorListAsyn()



private static string AppendApiKey(string url)
{
BrickOwlClientConfiguration.Instance.ValidateThrowException();
Expand Down
2 changes: 1 addition & 1 deletion BrickOwlSharp.Client/BrickOwlSharp.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ With BrickOwlSharp, developers can easily integrate BrickOwl into their applicat
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

</Project>
58 changes: 58 additions & 0 deletions BrickOwlSharp.Client/Color.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#region License
// Copyright (c) 2024 Stephan Stapel
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
# endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace BrickOwlSharp.Client
{
public class Color
{
[JsonPropertyName("id")]
public string Id { get; set; }

[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("hex")]
public string Hex { get; set; }

[JsonPropertyName("peeron_names")]
public List<string> PeeronNames { get; set; }

[JsonPropertyName("ldraw_ids")]
public List<string> LdrawIds { get; set; }

[JsonPropertyName("bl_ids")]
public List<string> BlIds { get; set; }

[JsonPropertyName("bl_names")]
public List<string> BlNames { get; set; }

[JsonPropertyName("lego_colors")]
public List<LegoColor> LegoColors { get; set; }
}
}
2 changes: 2 additions & 0 deletions BrickOwlSharp.Client/IBrickOwlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ Task<List<Inventory>> GetInventoryAsync(
Task<bool> DeleteInventoryAsync(
DeleteInventory deleteInventory,
CancellationToken cancellationToken = default);

Task<List<Color>> GetColorListAsyn(CancellationToken cancellationToken = default);
}
}
40 changes: 40 additions & 0 deletions BrickOwlSharp.Client/LegoColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#region License
// Copyright (c) 2024 Stephan Stapel
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
# endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace BrickOwlSharp.Client
{
public class LegoColor
{
[JsonPropertyName("lego_id")]
public string LegoId { get; set; }

[JsonPropertyName("raw_name")]
public string RawName { get; set; }
}
}
4 changes: 4 additions & 0 deletions BrickOwlSharp.Demos/BrickOwlSharp.Demos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Spectre.Console" Version="0.49.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BrickOwlSharp.Client\BrickOwlSharp.Client.csproj" />
</ItemGroup>
Expand Down
47 changes: 47 additions & 0 deletions BrickOwlSharp.Demos/ColorDemo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#region License
// Copyright (c) 2024 Stephan Stapel
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
# endregion
using BrickOwlSharp.Client;
using Spectre.Console;

internal class ColorDemo
{
internal async Task RunAsync()
{
IBrickOwlClient client = BrickOwlClientFactory.Build();
List<BrickOwlSharp.Client.Color> allColors = await client.GetColorListAsyn();

var table = new Table();
table.AddColumn("Id");
table.AddColumn("Name");
table.AddColumn("Hex");

foreach (BrickOwlSharp.Client.Color color in allColors)
{
table.AddRow(color.Id, color.Name, color.Hex);
}

AnsiConsole.Write(table);
}
}
18 changes: 16 additions & 2 deletions BrickOwlSharp.Demos/InventoryDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
// OTHER DEALINGS IN THE SOFTWARE.
# endregion
using BrickOwlSharp.Client;
using Spectre.Console;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -37,6 +39,8 @@ internal async Task RunAsync()
{
IBrickOwlClient client = BrickOwlClientFactory.Build();

/*
NewInventoryResult newInventoryResult = await client.CreateInventoryAsync(new NewInventory()
{
Id = "414759", // Bracket 1 x 2 - 1 x 2 Inverted
Expand All @@ -51,12 +55,22 @@ internal async Task RunAsync()
AbsoluteQuantity = 23
});
*/

var table = new Table();
table.AddColumn("Id");
table.AddColumn("Lot Id");
table.AddColumn("Quantity");
table.AddColumn("Type");

foreach (Inventory inventory in await client.GetInventoryAsync())
{
Console.WriteLine($"{inventory.Id}: quantity {inventory.Quantity}, lot id: {inventory.LotId}, type: {inventory.Type}");
table.AddRow(inventory.Id, inventory.LotId.HasValue ? inventory.LotId.Value.ToString() : "", inventory.Quantity.HasValue ? inventory.Quantity.Value.ToString() : "", inventory.Type.ToString());
}

bool result = await client.DeleteInventoryAsync(new DeleteInventory() { LotId = newInventoryResult.LotId.Value });
AnsiConsole.Write(table);

// bool result = await client.DeleteInventoryAsync(new DeleteInventory() { LotId = newInventoryResult.LotId.Value });
}
}
}
8 changes: 6 additions & 2 deletions BrickOwlSharp.Demos/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ static async Task<int> Main()
demo.Run();
*/

/*

InventoryDemo demo = new InventoryDemo();
await demo.RunAsync();
*/

/*
CatalogDemo catalogDemo = new CatalogDemo();
catalogDemo.Run();
*/

ColorDemo colorDemo = new ColorDemo();
await colorDemo.RunAsync();

return 0;
}
Expand Down

0 comments on commit 9fc43fa

Please sign in to comment.