README.md

    unigo-csharp

    UniGo Email API C# library

    Instalation

    Add UniGo library to your project references.

    Usage

    ###Configuration First step is adding necessary configuration to your appsettings.json file.

    {
     "UniGo": 
      {
        "ServerAddress": "https://go1.unisender.ru/",
        "ApiUrl": "ru/transactional/api/",
        "ApiVersion": "v1",
        "X-API-KEY": "",
        "ServerTimeout": 5,
        "EnableLogging": true
      }
    }
    

    Where:

    ServerAddress - go1.unisender.ru or go2.unisender.ru X-API-KEY - Api key generated in Account -> Security tab on your UniGo account ServerTimeout - Default 5 seconds timeout EnableLogging - Set to true if you want to generate logs for library

    Creating UniGo instance

    var uniGo = new UniGo.UniGo(configuration);
    

    UniGo constructor needs IConfiguration interface with loaded appsettings.json

    IConfiguration configuration = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
        .Build();
    

    UniGo main classes

    Library implements those classes with their respective methods. For more detail refer to UniGo api documentations.

    Email Method related to sending emails.

    • async Task Send(EmailMessageData message)
    • async Task<IOperationResult> Subscribe(string fromEmail, string fromName, string toEmail)

    EmailValidation

    • async Task ValidationSingle(string emailAddress)

    Template

    • async Task<IOperationResult> Set(TemplateData templateData)
    • async Task Get(string id)
    • async Task List(int limit = 50, int offset = 0)
    • async Task<IOperationResult> Detele(string id)

    Webhook

    • async Task<IOperationResult> Set(WebhookData webhookData)
    • async Task Get(string url)
    • async Task List(int limit = 50, int offset = 0)
    • async Task<IOperationResult> Delete(string url)

    Suppression

    • async Task Set(string email, string cause, DateTime created)
    • async Task Get(string email, bool all_projects)
    • async Task List(string cause ="" , string source = "" , DateTime? start_time = null, string cursor = "", int limit = 50)
    • async Task Delete(string email)

    Domain

    • async Task GetDNSRecords(string domain)
    • async Task ValidateVerificationRecord(string domain)
    • async Task ValidateDkim(string domain)
    • async Task List(string domain, int limit = 50,int offset = 0 )

    EventDump

    • async Task<IOperationResult> Create(EventDumpRequest request)
    • async Task Get(string dumpId)
    • async Task List(int limit = 50, int offset = 0)
    • async Task<IOperationResult> Detele(string dumpId)

    Tag

    • async Task List()
    • async Task<IOperationResult> Detele(int tagId)

    Project

    • async Task Create(string name, string country, bool send_enabled, bool custom_unsubscribe_url_enabled, int backendId)
    • async Task Update(string id,string name, string country, bool send_enabled, bool custom_unsubscribe_url_enabled, int backendId)
    • async Task List(string project_id = "" , string project_api_key = "")
    • async Task<IOperationResult> Delete(string id, string project_api_key)

    System

    • async Task SystemInfo()

    Obsolete

    • async Task UnsubscribedSet(string emailAddress)
    • async Task UnsubscribedCheck(string emailAddress)
    • async Task UnsubscribedList(string emailAddress)

    Generic

    • async Task<IOperationResult> CustomRequest(string request, object obj) - method allowing to send custom request to Unisender Go API

      Before you send custom request, you have to provide expected class for method result.

      var customRequest = await uniGo.Generic.CustomRequest<TemplateList>("template/list.json", "{\"limit\": 50,\"offset\":0}");
      
      if (customRequest == null)
      {
          var error = uniGo.Generic.GetError();
      }
      
      

      Running test

      Unit tests

      Run RunTests.sh from UniGoTests solution.

      $ ./RunTests.sh
      
      

      Result should look like this:

        Determining projects to restore...
        All projects are up-to-date for restore.
        
      Microsoft (R) Test Execution Command Line Tool Version 17.5.0 (x64)
      Copyright (c) Microsoft Corporation.  All rights reserved.
      
      Starting test execution, please wait...
      A total of 1 test files matched the specified pattern.
      
      Passed!  - Failed:     0, Passed:    78, Skipped:     0, Total:    78, Duration: 10 ms - UniGoTests.dll (net7.0)
      
      

      DemoApp/Tests

      From DemoApp directory run Build-and-run.sh which requires 4 arguments:

      - **HOST_NAME** is the host for connection.
      - **API_KEY** is the API key used for connection.
      - **WEBHOOK_URL** is the url to set the webhook handler to.
      - **FROM_EMAIL** is the from_email parameter for email/send method.
      

      Example:

      
      ./Build-and-run.sh https://go1.unisender.ru/ MY_API_KEY https://someweb.site myTestAccount@test.ts
      
      

      Script output should look like this:

      
      Build succeeded.
          0 Warning(s)
          0 Error(s)
      
      Time Elapsed 00:00:00.73
      Build successfull.
      Error count:0/11
      
      
    Конвейеры
    0 успешных
    0 с ошибкой