Skip to content

unione-repo/unione-csharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unione-csharp

UniOne Email API C# library

Instalation

Add UniOne library to your project references.

Usage

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

{
 "UniOne": 
  {
    "ServerAddress": "https://eu1.unione.io/",
    "ApiUrl": "en/transactional/api/",
    "ApiVersion": "v1",
    "X-API-KEY": "",
    "ServerTimeout": 5,
    "EnableLogging": true
  }
}

Where:

ServerAddress - eu1.unione.io for EU or us1.unione.io for USA & Canada X-API-KEY - Api key generated in Account -> Security tab on your UniOne account ServerTimeout - Default 5 seconds timeout EnableLogging - Set to true if you want to generate logs for library

Creating UniOne instance

var uniOne = new UniOne.UniOne(configuration);

UniOne constructor needs IConfiguration interface with loaded appsettings.json

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

UniOne main classes

Library implements those classes with their respective methods. For more detail refer to UniOne 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 CustomRequest(string request, object obj, Func<string, string, OperationResult> operationResultCreator) where T : class - method allowing to send custom request to UniOne API

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

var customRequest = await uniOne.Generic.CustomRequest<TemplateList>("template/list.json", "{\"limit\": 50,\"offset\":0}", (status, response) => OperationResult<TemplateList>.CreateNew(status, response));

if (customRequest == null)
{
    var error = uniOne.Generic.GetError();
}

Running test

Unit tests

Run RunTests.sh from UniOneTests 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 - UniOneTests.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://eu1.unione.io/ 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

About

UniOne Email API C# library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published