-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GetColorsAsync GetColorAsync GetPartsAsync GetElementAsync methods
- Loading branch information
1 parent
cbccabe
commit 449ed38
Showing
26 changed files
with
1,214 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[*.cs] | ||
csharp_style_namespace_declarations=file_scoped:suggestion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
# RebrickableSharp | ||
Easy-to-use C# client for the Rebrickable (LEGO) API. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#region License | ||
// Copyright (c) 2022 Jens Eisenbach | ||
// | ||
// 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.Text.Json.Serialization; | ||
using RebrickableSharp.Client.Json; | ||
|
||
namespace RebrickableSharp.Client; | ||
|
||
public class Color | ||
{ | ||
[JsonPropertyName("id")] | ||
public int Id { get; set; } | ||
|
||
[JsonPropertyName("name")] | ||
public string Name { get; set; } = null!; | ||
|
||
[JsonPropertyName("rgb"), JsonConverter(typeof(HtmlCodeConverter))] | ||
public string HtmlCode { get; set; } = null!; | ||
|
||
[JsonPropertyName("is_trans")] | ||
public bool IsTransparent { get; set; } | ||
|
||
[JsonPropertyName("external_ids")] | ||
public ExternalColorData ExternalData { get; set; } = new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#region License | ||
// Copyright (c) 2022 Jens Eisenbach | ||
// | ||
// 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.Text.Json.Serialization; | ||
|
||
namespace RebrickableSharp.Client; | ||
|
||
public class Element | ||
{ | ||
[JsonPropertyName("part")] | ||
public Part Part { get; set; } = null!; | ||
|
||
[JsonPropertyName("color")] | ||
public Color Color { get; set; } = null!; | ||
|
||
[JsonPropertyName("element_id")] | ||
public string ElementId { get; set; } = null!; | ||
|
||
[JsonPropertyName("design_id")] | ||
public string DesignId { get; set; } = null!; | ||
|
||
[JsonPropertyName("element_img_url")] | ||
public string? ElementImageUrl { get; set; } | ||
|
||
[JsonPropertyName("part_img_url")] | ||
public string? partImageUrl { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#region License | ||
// Copyright (c) 2022 Jens Eisenbach | ||
// | ||
// 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 | ||
|
||
namespace RebrickableSharp.Client.Extensions; | ||
|
||
internal static class BooleanExtensions | ||
{ | ||
public static string ToQueryParam(this bool b) | ||
{ | ||
return b ? "1" : "0"; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
RebrickableSharp.Client/Extensions/NameValueCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#region License | ||
// Copyright (c) 2022 Jens Eisenbach | ||
// | ||
// 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.Collections.Specialized; | ||
|
||
namespace RebrickableSharp.Client.Extensions; | ||
|
||
internal static class NameValueCollectionExtensions | ||
{ | ||
public static void AddIfNotNull<T>(this NameValueCollection collection, string key, T value, Func<T, string>? toString = null) | ||
{ | ||
if (value != null) | ||
{ | ||
collection[key] = toString == null ? value.ToString() : toString.Invoke(value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#region License | ||
// Copyright (c) 2022 Jens Eisenbach | ||
// | ||
// 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.Text.Json.Serialization; | ||
|
||
namespace RebrickableSharp.Client; | ||
|
||
public class ExternalColorData | ||
{ | ||
[JsonPropertyName("LDraw")] | ||
public ExternalColorIds LDraw { get; set; } = new(); | ||
|
||
[JsonPropertyName("BrickLink")] | ||
public ExternalColorIds BrickLink { get; set; } = new(); | ||
|
||
[JsonPropertyName("BrickOwl")] | ||
public ExternalColorIds BrickOwl { get; set; } = new(); | ||
|
||
[JsonPropertyName("LEGO")] | ||
public ExternalColorIds Lego { get; set; } = new(); | ||
|
||
[JsonPropertyName("Peeron")] | ||
public ExternalColorIds Peeron { get; set; } = new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#region License | ||
// Copyright (c) 2022 Jens Eisenbach | ||
// | ||
// 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.Text.Json.Serialization; | ||
|
||
namespace RebrickableSharp.Client; | ||
|
||
public class ExternalColorIds | ||
{ | ||
[JsonPropertyName("ext_ids")] | ||
public int?[] Ids { get; set; } = Array.Empty<int?>(); | ||
|
||
[JsonPropertyName("ext_descrs")] | ||
public string[][] Descriptions { get; set; } = Array.Empty<string[]>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#region License | ||
// Copyright (c) 2022 Jens Eisenbach | ||
// | ||
// 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.Text.Json.Serialization; | ||
|
||
namespace RebrickableSharp.Client; | ||
|
||
public class ExternalPartIds | ||
{ | ||
private class ExternalPartIdStringBuilder | ||
{ | ||
private readonly IDictionary<string, int> _externalIdCount = new Dictionary<string, int>(); | ||
|
||
public void Append(string[] ids, string externalSource) | ||
{ | ||
if (ids.Any()) | ||
{ | ||
_externalIdCount.Add(externalSource, ids.Length); | ||
} | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
if (!_externalIdCount.Any()) | ||
{ | ||
return "No external IDs available"; | ||
} | ||
|
||
return string.Join(",", _externalIdCount.Select(kvp => $"{kvp.Key}:{kvp.Value}")); | ||
} | ||
} | ||
|
||
[JsonPropertyName("BrickLink")] | ||
public string[] BricklinkIds { get; set; } = Array.Empty<string>(); | ||
|
||
[JsonPropertyName("BrickOwl")] | ||
public string[] BrickOwlIds { get; set; } = Array.Empty<string>(); | ||
|
||
[JsonPropertyName("Brickset")] | ||
public string[] BricksetIds { get; set; } = Array.Empty<string>(); | ||
|
||
[JsonPropertyName("LEGO")] | ||
public string[] LegoIds { get; set; } = Array.Empty<string>(); | ||
|
||
[JsonPropertyName("LDraw")] | ||
public string[] LDrawIds { get; set; } = Array.Empty<string>(); | ||
|
||
[JsonPropertyName("Peeron")] | ||
public string[] PeeronIds { get; set; } = Array.Empty<string>(); | ||
|
||
public override string ToString() | ||
{ | ||
var builder = new ExternalPartIdStringBuilder(); | ||
builder.Append(BricklinkIds, "BrickLink"); | ||
builder.Append(BrickOwlIds, "BrickOwl"); | ||
builder.Append(BricksetIds, "Brickset"); | ||
builder.Append(LegoIds, "LEGO"); | ||
builder.Append(LDrawIds, "LDraw"); | ||
builder.Append(PeeronIds, "Peeron"); | ||
return builder.ToString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> | ||
<NullGuard IncludeDebugAssert="false" | ||
Mode="NullableReferenceTypes" /> | ||
</Weavers> |
Oops, something went wrong.