XyloCode.ThirdPartyServices.Pecom 1.1.0

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

// Install XyloCode.ThirdPartyServices.Pecom as a Cake Tool
#tool nuget:?package=XyloCode.ThirdPartyServices.Pecom&version=1.1.0                

PEC API client library

Unofficial .NET library for accessing the PEC API with partial implementation (order pick-up points, calculator).

Supported Platforms
  • .NET 6.0 LTS;
  • .NET 7.0.

PEC

PEK (russian abbr. ПЭК - Первая Экспедиционная Компания, english - First Forwarding Company) is a multi-service logistics operator, an expert in the field of integrated solutions and organization of cargo transportation in Russia and abroad. The company was founded in 2001. The PEC branch network includes over 300 branches in Russia, Azerbaijan, Armenia, Belarus, Kazakhstan, Uzbekistan, Tajikistan, Kyrgyzstan, Turkey and China. Every year, 4.5 million clients use the company’s services.

Official website: https://www.pecom.ru/.

Supported Methods

  • Authorization
  • Getting User Profile Data
  • List of all branches and cities
  • Getting the nearest dates and time intervals for cargo pickup/delivery
  • Calculation

How to use

using XyloCode.ThirdPartyServices.Pecom;
using XyloCode.ThirdPartyServices.Pecom.Calculation.Req;
using XyloCode.ThirdPartyServices.Pecom.Enums;
using XyloCode.ThirdPartyServices.Pecom.Helpers;
using XyloCode.ThirdPartyServices.Pecom.Models;
using XyloCode.ThirdPartyServices.Pecom.Requests;

namespace PecomTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            const string login = "my_login"; // login for https://pecom.ru/
            const string apiKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // api-key from https://pecom.ru/

            var tracer = new LoggingHandler(); // for tracing, needed only for debugging
            var api = new PecClient(login, apiKey, httpMessageHandler: tracer);

            // Getting list of all branches and cities
            var branchs = api.GetAllBranches();

            
            // Getting the nearest dates and time intervals for cargo pickup
            var timeslotReq = new DeliveryTimeSlotRequest
            {
                Date = DateOnly.FromDateTime(DateTime.Today.AddDays(1)),
                CalculateDays = 3,
                Address = "Город Москва, ул Вавилова, д. 19",
            };
            var deliverydays = api.GetDeliveryTimeSlots(timeslotReq);
            var plannedDate = GetPlannedDate(deliverydays);
            

            // Calculation
            var calc = new CalculationRequest
            {
                TransportingTypes = new List<ProductType> { ProductType.LTL },
                IsPickUp = true,
                IsDelivery = true,
                PlannedDateTime = plannedDate,
                Cargos = new List<Cargo>
                {
                    new Cargo
                    {
                        Length = 1,
                        Width = 0.3,
                        Height = 1,
                        Weight = 76,
                    },
                },
                InsurancePrice = 35_000,
                Pickup = new Point("Город Москва, ул Вавилова, д. 19"),
                Delivery = new Point("630099, Новосибирская область, г Новосибирск, пр-кт Димитрова, зд. 2"),
                Counterpart = new Counterpart
                {
                    Inn = "7707083893",
                    WhoMakesCalculation = new List<RoleType> { RoleType.Payer, RoleType.Sender },
                }
            };
            var resCalc = api.Calculation(calc);
        }


        // Select nearest date and time for cargo pickup
        private static DateTime GetPlannedDate(List<DeliveryTimeSlot> list)
        {
            foreach (var day in list)
            {
                if (!day.Date.HasValue) continue;
                var date = day.Date.Value;
                foreach (var ts in day.TimeSlots)
                {
                    if (!ts.PeriodTimeFrom.HasValue) continue;
                    var time = ts.PeriodTimeFrom.Value.AddMinutes(5);
                    if (ts.PeriodTimeFrom?.Hour > 9 && ts.PeriodTimeTo?.Hour < 15)
                    {
                        return new DateTime(date.Year, date.Month, date.Day, time.Hour, time.Minute, 0);
                    }
                }
            }
            throw new Exception();
        }
    }
}

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

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
1.1.0 173 11/16/2023
1.0.2 124 11/8/2023
1.0.1 139 10/17/2023
1.0.0 150 10/12/2023

NET 8.0 support.