Confiti.MoySklad.Remap.Sdk 0.21.1

dotnet add package Confiti.MoySklad.Remap.Sdk --version 0.21.1                
NuGet\Install-Package Confiti.MoySklad.Remap.Sdk -Version 0.21.1                
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="Confiti.MoySklad.Remap.Sdk" Version="0.21.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Confiti.MoySklad.Remap.Sdk --version 0.21.1                
#r "nuget: Confiti.MoySklad.Remap.Sdk, 0.21.1"                
#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 Confiti.MoySklad.Remap.Sdk as a Cake Addin
#addin nuget:?package=Confiti.MoySklad.Remap.Sdk&version=0.21.1

// Install Confiti.MoySklad.Remap.Sdk as a Cake Tool
#tool nuget:?package=Confiti.MoySklad.Remap.Sdk&version=0.21.1                

МойСклад C# API client

Реализация C# клиента для МойСклад API

Поддерживаемые API

  • МойСклад Remap API v1.2

Начало работы c Remap API

Быстрый старт

var credentials = new MoySkladCredentials()
{
    AccessToken = "your-access-token"
    // или
    Username = "your-username",
    Password = "your-password",
};
var api = new MoySkladApi(credentials);
var response = await api.Assortment.GetAllAsync();

Пользовательский HttpClient

var httpClient = new HttpClient(new HttpClientHandler()
{
    // gZip обязателен
    AutomaticDecompression = DecompressionMethods.GZip
});
var credentials = new MoySkladCredentials()
{
    AccessToken = "your-access-token"
};
var api = new MoySkladApi(credentials, httpClient);

Фильтрация

var query = new AssortmentApiParameterBuilder();

// фильтр '='
query.Parameter(p => p.Name).Should().Be("foo");
// вложенный фильтр '='
query.Parameter(p => p.Alcoholic.Type).Should().Be(123);
// множественный фильтр '='
query.Parameter(p => p.Archived).Should().Be(true).Or.Be(false);
// фильтр '~'
query.Parameter(p => p.Article).Should().Contains("foo");
// фильтр '~='
query.Parameter(p => p.Article).Should().StartsWith("foo");
// фильтр '>=' и '<='
query.Parameter(p => p.Updated).Should()
    .BeGreaterOrEqualTo(DateTime.Parse("2020-07-10 12:00:00"))
    .And
    .BeLessOrEqualTo(DateTime.Parse("2020-07-12 12:00:00"));

// фильтр по пользовательскому полю
query.Parameter("your-custom-attribute-href").Should().Be(123);

var response = await api.Assortment.GetAllAsync(query);

Сортировка

query.Order().By(p => p.Name)
    // пользовательское поле
    .And.By("your-custom-property-name");

// по убыванию
query.Order().By(p => p.Name, OrderBy.Desc)

Limit и Offset

query.Limit(100);
query.Offset(50);

Контекстный поиск

query.Search("foo");

Группировка

query.GroupBy(GroupBy.Consignment);

Expand

query.Expand().With(p => p.Images)
    .And.With(p => p.Product)
    // вложенный
    .And.With(p => p.SalePrices.Currency)
    .And.With(p => p.BuyPrice.Currency)
    .And.With(p => p.Product.SalePrices.Currency)
    .And.With(p => p.Product.BuyPrice.Currency)
    // пользовательское поле
    .And.With("your-custom-property-name")

Загрузка картинок

var imagesResponse = await api.Product.Images.GetAllAsync(Guid.Parse("product-id"));

foreach (var image in imagesResponse.Payload.Rows)
{
    var imageDataResponse = await api.Product.Images.DownloadAsync(image);

    await using (imageDataResponse.Payload)
    {
        if (imageDataResponse.Payload is MemoryStream memoryStream)
        {
            var imageData = memoryStream.ToArray();

            // обработать изображение
        }
    }
}

Получение метаданных

await api.Product.Metadata.GetAsync();

Обработка исключений

try
{
    await _moySkladApi.Counterparty.GetAsync(counterpartyId);
}
catch (ApiException ex)
{
    // обработать код ошибки
    if (ex.ErrorCode == 404) { ... }

    // обработать ошибки
    foreach (var error in ex.Errors) { ... }

    // полное описание ошибки
    // cодержит все коды/описания по каждой ошибке из ex.Errors.
    _logger.Log(ex.Message);
}

Сборка и запуск тестов

  • В корневой папке в файле build.ps1 укажите API_LOGIN и API_PASSWORD
  build.ps1
# Enter your login and password
# $Env:API_LOGIN = "enter-your-api-login-here"
# $Env:API_PASSWORD = "enter-your-api-password-here"
  • Запустите build.ps1

Поддержка

Я открыт для любого сотрудничества и расширения функционала данного проекта. Pull requests приветствуются, однако сначала откройте issue для обсуждения.

Если вам понравился данный проект, воткните ⭐

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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
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
0.21.1 677 7/22/2024
0.21.0 103 7/22/2024
0.20.1 107 7/18/2024
0.20.0 105 6/17/2024
0.19.0 111 5/16/2024
0.18.0 708 10/19/2023
0.17.1 381 12/26/2022
0.17.0 357 11/13/2022
0.16.1 438 10/30/2022
0.15.2 434 8/16/2022
0.15.1 414 8/15/2022
0.15.0 410 8/14/2022
0.14.0 414 8/14/2022
0.13.1 485 4/11/2022
0.13.0 432 3/23/2022
0.12.0 431 3/23/2022
0.11.0 436 3/18/2022
0.9.1 398 9/4/2021
0.9.0 318 9/1/2021
0.8.0 354 6/25/2021
0.7.0 384 6/17/2021
0.6.0 380 6/13/2021
0.5.0 321 5/9/2021
0.4.2 314 4/15/2021
0.3.2 345 2/13/2021
0.3.1 334 2/12/2021
0.3.0 353 2/7/2021