LegoSharp 7.0.0

dotnet add package LegoSharp --version 7.0.0
NuGet\Install-Package LegoSharp -Version 7.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LegoSharp" Version="7.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LegoSharp --version 7.0.0
#r "nuget: LegoSharp, 7.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LegoSharp as a Cake Addin
#addin nuget:?package=LegoSharp&version=7.0.0

// Install LegoSharp as a Cake Tool
#tool nuget:?package=LegoSharp&version=7.0.0

LegoSharp

LegoSharp is an unofficial C# library for interacting with Lego's web APIs.

Build Status

Nuget

Basic Usage

Searching the Lego graph is currently the only supported action.

To search the graph, make a graph client:

LegoGraphClient graphClient = new LegoGraphClient();

You can then query different graph APIs.

Pick a Brick

You can query Pick a Brick:

LegoGraphClient graphClient = new LegoGraphClient();

PickABrickQuery query = new PickABrickQuery();
query.addFilter(new BrickColorFilter()
    .addValue(BrickColor.Black)
);
query.query = "wheel";

PickABrickResult result = await graphClient.pickABrick(query);
foreach (Brick brick in result.elements)
{
    // do something with each brick
}

You can query for Lego Products:

LegoGraphClient graphClient = new LegoGraphClient();

ProductSearchQuery query = new ProductSearchQuery();
query.addFilter(new ProductTypeFilter()
    .addValue(ProductType.Sets)
);
query.addFilter(new ProductPriceFilter()
    .fromTo(1000, 2500)
);
query.query = "train";

ProductSearchResult result = await graphClient.productSearch(query);
foreach (Product product in result.products)
{
    // do something with each product
}

Advanced Usage

There is also built in functionality to scrape the Lego graph.

Scraping Facets

Items in the graph (products and bricks), are made up of facets. You can scrape for facets by making a facet scraper:

FacetScraper facetScraper = new FacetScraper<ProductSearchQuery, ProductSearchResult>(new List<ProductSearchQuery> { new ProductSearchQuery() }, new ProductSearchFacetExtractor());

The facet scraper takes in a list of queries. It uses the results of these queries to scrape facets. Scraping a facet means to get all of its current possible values.

You can use scrapeFacet to scrape a specific facet:

facetScraper.scrapeFacet("variants.attributes.flags.key", "product.facet.flags");

Or you can use scrapeFacets to scrape all available facets:

facetScraper.scrapeFacets();

Contributing

Contributions are welcome. I'd reccomend first opening an issue for what you want to add so we can talk about implementation details. When you're ready to code, simply fork, make your changes, and then open a pull request. I will ask you to add tests for most code changes, and tests are required to pass before merging.

Why does this exist?

This library exists for a few reasons:

  1. I wanted to see what it is like to reverse engineer an API.
  2. I like Legos (though I don't buy them that often, they're pretty expensive...).
  3. I work in TS for my day job, so I wanted to do a project in another language. Since C# is used a lot where I work, I chose it. Not only am I keeping myself familiar in C#, it's also fun to see how my TS brain handles having to work in C#.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
7.0.0 353 2/14/2021
6.0.0 501 12/18/2020
5.3.0 392 6/29/2020
5.2.0 439 6/19/2020
5.1.0 400 6/3/2020
5.0.0 454 6/2/2020
4.0.0 395 5/24/2020
3.0.0 495 5/24/2020
2.0.0 417 5/22/2020
1.0.0 454 5/21/2020