GithubHelp home page GithubHelp logo

andrantis / bricklinksharp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gebirgslok/bricklinksharp

0.0 1.0 0.0 325 KB

Easy-to-use C# client for the bricklink (LEGO) marketplace API.

Home Page: https://github.com/gebirgslok/BricklinkSharp

License: MIT License

C# 99.21% PowerShell 0.79%

bricklinksharp's Introduction

BricklinkSharp

NuGet Build Status

Introduction

BricklinkSharp is a strongly-typed, easy-to-use C# client for the bricklink marketplace that gets you started with just a few lines of code. It features OAuth1 authentication, error handling and parsing of JSON data into typed instances. It supports all .NET platforms compatible with .NET standard 2.0.

Changelog

1.0.0 (WIP)

  • Covers all public API endpoints
  • New Assembly versioning:
    • Assembly Version: 1.0.0.0
    • Assembly File Version: 1.0.0.<build ID>
    • Assembly Informational File Version: 1.0.0-<build time>+<build date>

0.7.0

  • New method on IBricklinkClient: GetMinifigImage. Builds and returns the image URL for a specific minifigure number.
  • New method on IBricklinkClient: GetSetImage. Builds and returns the image URL for a specific set number.

0.6.1

  • Fixed: OrderMessage.Subject can be Null. Thanks to aalex675 for his contribution.

0.6.0

  • New method on IBricklinkClient: GetPartImageForColor. Builds and returns the image URL for a specific part number / color ID.
  • New helper method on IBricklinkClient: EnsureImageUrlScheme. Adds (ensures) an URI scheme on image URLs returned by the Bricklink API.

0.5.0

  • Coupons
  • Nullable annotations
  • Renamed UpdatedInventory container to UpdateInventory (breaking)

0.4.0

  • Order
  • IBricklinkClient implements IDisposable and manages one instance of HttpClient

0.3.0

  • Feedback
  • Member / Get member rating
  • Push Notification
  • Setting / Shipping methods
  • Renamed IBricklinkClient.GetItemNumber to IBricklinkClient.GetItemNumberAsync (breaking)
  • Renamed IBricklinkClient.GetElementId to IBricklinkClient.GetElementIdAsync (breaking)

0.2.0

  • User Inventory
  • Item Mapping

0.1.0

  • OAuth1 handling
  • Catalog Item
  • Color
  • Category

Get started

Demo project

Check out the demo project for full-featured examples.

Prerequisites

You need to be registered on bricklink as a seller. Then, use this link to add an access token. Add your client IP address (if applicable) or 0.0.0.0 for both IP address and mask to be able to make API requests from any IP.

Install NuGet package

Package Manager Console

Install-Package BricklinkSharp

Command Line

nuget install BricklinkSharp

Setup credentials

BricklinkClientConfiguration.Instance.TokenValue = "<Your Token>";
BricklinkClientConfiguration.Instance.TokenSecret = "<Your Token Secret>";
BricklinkClientConfiguration.Instance.ConsumerKey = "<Your Consumer Key>";
BricklinkClientConfiguration.Instance.ConsumerSecret = "<Your Consumer Secret>";

IBricklinkClient

var client = BricklinkClientFactory.Build();

Usage recommendation

It's recommended to create and use one IBricklinkClient client throughout the lifetime of your application.

In applications using an IoC container you may register the IBricklinkClient as a service and inject it into consuming instances (e.g. controllers). See the below examples to register the IBricklinkClient as single instance (Singleton).

Autofac example

containerBuilder.Register(c => BricklinkClientFactory.Build())
	.As<IBricklinkClient>()
	.SingleInstance();
services.AddSingleton(typeof(IBricklinkClient), provider =>
{
    return BricklinkClientFactory.Build();
});  

Item Catalog

Get item

var catalogItem = await client.GetItemAsync(ItemType.Part, "6089");

Get item image

var catalogImage = await client.GetItemImageAsync(ItemType.OriginalBox, "1-12", 0);

Get part image for color ID

var colorId = 34; //Lime. 
var uri = client.GetPartImageForColor("43898pb006", 34);

Get minifigure image

var uri = client.GetMinifigImage("sw1093");

Get set image

var uri = client.GetSetImage("6090-1");

Ensure image url scheme

var uri = client.EnsureImageUrlScheme("//img.bricklink.com/ItemImage/PN/34/43898pb006.png", "https");
Console.WriteLine(uri.ToString());
//Prints: https://img.bricklink.com/ItemImage/PN/34/43898pb006.png

Get supersets

var supersets = await client.GetSupersetsAsync(ItemType.Minifig, "aqu004", 0);

Get subsets

var subsets = await client.GetSubsetsAsync(ItemType.Set, "1095-1", breakMinifigs: false);

Get price guide

var priceGuide = await client.GetPriceGuideAsync(ItemType.Part, "3003", colorId: 1, priceGuideType: PriceGuideType.Sold, condition: Condition.Used);

Get known colors

var knownColors = await client.GetKnownColorsAsync(ItemType.Part, "3006");

Color

Get color list

var colors = await client.GetColorListAsync();

Get color

var color = await client.GetColorAsync(15);

Category

Get category list

var categories = await client.GetCategoryListAsync();

Get category

var category = await client.GetCategoryAsync(1);

User Inventory

Get inventory list

//Include only parts and minifigs.
var includedTypes = new List<ItemType> { ItemType.Part, ItemType.Minifig };
//Exclude all inventories which are unavailable.
var excludedStatusFlags = new List<InventoryStatusType> { Unavailable };
var inventories = await client.GetInventoryListAsync(includedTypes, excludedStatusFlags: excludedStatusFlags);

Create inventory

var newInventory = new NewInventory
{
	ColorId = 1,
	Condition = Condition.Used,
	Item = new ItemBase
	{
		Number = "3003",
		Type = ItemType.Part
	},
	Quantity = 5,
	UnitPrice = 0.01M,
	Description = "Good used condition"
};
var inventory = await client.CreateInventoryAsync(newInventory);

Create inventories

var newInventories = new NewInventory[] { //fill with inventories... };
//Note that there will be no response data.
await client.CreateInventoriesAsync(newInventories);

Update inventory

var inventoryList = await client.GetInventoryListAsync();
var id = inventoryList.First().InventoryId;
var updateInventory = new UpdateInventory { ChangedQuantity = 21, Remarks = "Remarks added." };
var inventory = await client.UpdateInventoryAsync(id, updateInventory);

Delete inventory

var inventoryList = await client.GetInventoryListAsync();
var id = inventoryList.First().InventoryId;
await client.DeleteInventoryAsync(id);

Item Mapping

Get ElementID

The method returns an array of ItemMapping objects. If a color ID is specified the array will contain just one element. Otherwise the array will contain mappings for every available color.

var itemMappings = await client.GetElementIdAsync("3003", 1);

Get item number

var itemMapping = await client.GetItemNumberAsync("300301");

Push Notification

Get notifications

var notifications = await client.GetNotificationsAsync();

Setting

Get shipping method list

var shippingMethods = await client.GetShippingMethodListAsync();

Get shipping method

var shippingMethod = await client.GetShippingMethodAsync(123);

Member

Get member rating

var rating = await client.GetMemberRatingAsync("bluser");

Feedback

Get feedback list

var feedbackInList = await client.GetFeedbackListAsync(FeedbackDirection.In);
var feedbackOutList = await client.GetFeedbackListAsync(FeedbackDirection.Out);
var feedbackListAll = await client.GetFeedbackListAsync();

Get feedback

var feedbackListAll = await client.GetFeedbackListAsync()
var id = feedbackListAll.First().FeedbackId;
var feedback = await client.GetFeedbackAsync(id);

Post feedback

var orderId = 1234567; //Must be a valid order ID.
var feedback = await client.PostFeedbackAsync(orderId, RatingType.Praise, "Awesome transaction, praise!");

Reply feedback

var feedbackId = 1234567; //Must be a valid feedback ID.
await client.ReplyFeedbackAsync(feedbackId, "Thank you for your kind comment.");

Order

Get Orders

//Exclude all purged orders.
var orders = await client.GetOrdersAsync(OrderDirection.Out, excludedStatusFlags: new List<OrderStatus>
{
	OrderStatus.Purged
});
//Only paid orders that must be shipped.
var orders = await client.GetOrdersAsync(OrderDirection.Out, excludedStatusFlags: new List<OrderStatus>
{
	OrderStatus.Paid
});

Get Order

var orderId = 123456789; //Must be a valid order ID.
var order = await client.GetOrderAsync(orderId);

Get Order Items

var orderId = 1234566789; //Must be a valid order ID.
var itemsBatchList = await client.GetOrderItemsAsync(orderId);

foreach (var itemsBatch in itemsBatchList)
{
	foreach (var item in itemsBatch)
	{
		//Process item...
	}
}

Get Order Messages

var orderId = 123456789; //Must be a valid order ID.
var messages = await client.GetOrderMessagesAsync(orderId);

Get Order Feedback

var orderId = 123456789; //Must be a valid order ID.
var feedbacks = await client.GetOrderFeedbackAsync(orderId);

Update Order

var orderId = 123456789; //Must be a valid order ID.

//Note: you must only set properties which should be updated. Leave all others Null.
var updateOrder = new UpdateOrder();
updateOrder.Remarks = "Add remark";
updateOrder.IsFiled = true;
updateOrder.Cost.Insurance = 2.5m;
updateOrder.Cost.Etc1 = 1.0m;
updateOrder.Shipping.TrackingNo = "1234567892";
updateOrder.Shipping.TrackingLink = "www.foo.bar/123456789";
await client.UpdateOrder(orderId, updateOrder);

Update Order Status

var orderId = 123456789; //Must be a valid order ID.
try
{
	//Note that the order must be outgoing in order to be able to set it to 'Shipped'.
	await client.UpdateOrderStatusAsync(orderId, OrderStatus.Shipped);
}
catch (Exception exception)
{
	//Handle invalid operation.
}

Update Payment Status

var orderId = 123456789; //Must be a valid order ID.
try
{
	//Note that the order must be outgoing in order to be able to set it to 'Received'.
	await client.UpdatePaymentStatusAsync(orderId, PaymentStatus.Received);
}
catch (Exception exception)
{
	//Handle invalid operation.
}

Send Drive Thru

var orderId = 123456789; //Must be a valid order ID.
try
{
	await client.SendDriveThruAsync(orderId, true);
}
catch (Exception exception)
{
	//Handle invalid operation.
}

Coupons

Get Coupons

var includesStatusTypes = new List<CouponStatus>
{
	CouponStatus.Open
}
var coupons = await client.GetCouponsAsync(Direction.Out, includedCouponStatusTypes: includesStatusTypes);

Get Coupon

var couponId = 123456789; //Must be a valid coupon ID.
var coupon = await client.GetCouponAsync(couponId);

Create Coupon

var newCoupon = new NewCoupon("bluser", "Special gift for you")
{
	DiscountType = DiscountType.Percentage,
	DiscountRate = 10
};
newCoupon.AppliesTo.ExceptOnSale = true;
newCoupon.AppliesTo.RestrictionType = CouponRestrictionType.ApplyToSpecifiedItemType;
newCoupon.AppliesTo.ItemType = ItemType.Part; //Only applies to parts.

var coupon = await client.CreateCouponAsync(newCoupon);

Update Coupon

var updateCoupon = new UpdateCoupon
{
	DiscountType = DiscountType.Percentage,
	DiscountRate = 15 //Increase discount rate to 15 percent.
};

var couponId = 123456789; //Must be a valid coupon ID.
var coupon = await client.UpdateCouponAsync(couponId, updateCoupon);

Delete Coupon

var couponId = 123456789; //Must be a valid coupon ID.
await client.DeleteCouponAsync(couponId);

bricklinksharp's People

Contributors

gebirgslok avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.