Skip to content

uizaio/api-wrapper-dotnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

The Uiza API is organized around RESTful standard. Our API has predictable, resource-oriented URLs, and uses HTTP response codes to indicate API errors. JSON is returned by all API responses, including errors, although our API libraries convert responses to appropriate language-specific objects.

The library building project provides convenient access to the Uiza API, supporting .NET Standard 1.6+, .NET Core 2.0+, and .NET Framework 4.5.2+

Documentation

See the .NET API docs.

Installation

Install Uiza via NuGet

From the command line:

nuget install Uiza

From Package Manager:

PM> Install-Package Uiza

From within Visual Studio:

  1. Open the Solution Explorer.
  2. Right-click on a project within your solution.
  3. Click on Manage NuGet Packages...
  4. Click on the Browse tab and search for "Uiza".
  5. Click on the Uiza package, select the appropriate version in the right-tab and click Install.

Set the API Key for your project

You can configure the Uiza package to use your secret API key by the way:

In your application initialization, set your API key (only once once during startup):

UizaConfiguration.SetupUiza(new UizaConfigOptions
{
	ApiKey = "Your api key here",
	AppId = "Your AppId"
});

You can obtain your secret API key from the API Settings in the Dashboard.

Additional Resources

Support

  • Make sure to review open issues and pull requests before opening a new issue.
  • Feel free to leave a comment or reaction on any existing issues.

Helpful Library Information

Responses

TheUizaData class inheritance from UizaResponse.

    /// <summary>
    /// 
    /// </summary>
    public class UizaData : UizaResponse
    {
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("data")]
        public dynamic Data { get; set; }
    }

Using QueryJsonDynamic to Parse API Response

see the Create Entity API and Example

	var service = new EntityService();
	var result = service.Create(...);
	Console.WriteLine(string.Format("Create New Entity Id = {0} Success", result.Data.id));

UizaException

TheUizaException Object is an attribute inheritance from Exception

	/// <summary>
    /// 
    /// </summary>
    public class UizaException : Exception
    {
        /// <summary>
        /// constain errors with Uiza.Net Format
        /// </summary>
        public UizaExceptionResponse UizaInnerException { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public UizaException()
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public UizaException(string message)
            : base(message)
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public UizaException(string message, Exception ex)
            : base(message, ex)
        {
        }
        /// <summary>
        /// Constructor Exception from API Response
        /// </summary>
        /// <param name="error"></param>
        public UizaException(UizaExceptionResponse error)
            : base(error.Message)
        {
            this.UizaInnerException = error;
        }

        /// <summary>
        /// Constructor Exception with custom Error
        /// </summary>
        /// <param name="message"></param>
        /// <param name="error"></param>
        public UizaException(string message, UizaExceptionResponse error)
            : base(message)
        {
            this.UizaInnerException = error;
        }
    }

using try catch to handle Error

 try
 {
	////
 }
 catch (UizaException ex)
 {
	var result = ex.UizaInnerException.Error;
 }

UizaExceptionResponse TheUizaExceptionResponse

public class UizaExceptionResponse
{
	/// <summary>
	/// 
	/// </summary>
	[JsonProperty("code")]
	public int Code { get; set; }

	/// <summary>
	/// 
	/// </summary>
	[JsonProperty("type")]
	public string Type { get; set; }

	/// <summary>
	/// 
	/// </summary>
	[JsonProperty("retryable")]
	public bool RetryAble { get; set; }

	/// <summary>
	/// 
	/// </summary>
	[JsonProperty("message")]
	public string Message { get; set; }

	/// <summary>
	/// 
	/// </summary>
	[JsonProperty("data")]
	public dynamic Data { get; set; }

	/// <summary>
	/// 
	/// </summary>
	public ErrorData Error
	{
		get
		{
			return Errors.FirstOrDefault() ?? new ErrorData();
		}
	}

	/// <summary>
	/// 
	/// </summary>
	public List<ErrorData> Errors
	{
		get
		{
			if (Data is JArray)
				return JsonConvert.DeserializeObject<List<ErrorData>>(JsonConvert.SerializeObject(Data));
			if (Data is string)
				return new List<ErrorData>() {
					new ErrorData()
					{
						Message = Message,
						Type = Type
					}
				};
			if (Data is JObject)
				return new List<ErrorData>() {
					 JsonConvert.DeserializeObject<ErrorData>(JsonConvert.SerializeObject(Data))
				};

			return new List<ErrorData>() {
				JsonConvert.DeserializeObject<ErrorData>(JsonConvert.SerializeObject(Data))
			};
		}
	}

	/// <summary>
	/// 
	/// </summary>
	public string DescriptionLink { get; set; }
}

/// <summary>
/// 
/// </summary>
public class ErrorData
{
	/// <summary>
	/// 
	/// </summary>
	[JsonProperty("message")]
	public string Message { get; set; }

	/// <summary>
	/// 
	/// </summary>
	[JsonProperty("type")]
	public string Type { get; set; }

	/// <summary>
	/// 
	/// </summary>
	[JsonProperty("field")]
	public string Field { get; set; }
}

Test

Uiza use Xunit to Unitest and OpenCover to test Code Coverage See details here.

Usage

	try
	{
		var service = new EntityService();
		var result = service.Create(...);
		Console.WriteLine(string.Format("Create New Entity Id = {0} Success", result.Data.id));
		Console.ReadLine();
	}
	catch (UizaException ex)
	{
		var result = ex.UizaInnerException.Error;
		Console.WriteLine(ex.Message);
		Console.ReadLine();
	}

Entity

These below APIs used to take action with your media files (we called Entity). Entity API. See details here.

var result = UizaServices.Entity.Create(new CreateEntityParameter()
{
	Name = "Sample Video",
	InputType = EntityInputTypes.S3Uiza,
	URL = ""
});
Console.WriteLine(string.Format("Create New Entity Id = {0} Success", result.Data.id));

Category

Category has been splits into 3 types: folder, playlist and tag. These will make the management of category more easier. Category API.

See details here.

 var createResult = UizaServices.Category.Create(new CreateCategoryParameter()
{
	Name = string.Format("Category name {0}", Guid.NewGuid().ToString()),
	Type = CategoryTypes.Folder
});

Console.WriteLine(string.Format("Create New Category Id = {0} Success", createResult.Data.id));

Storage

You can add your storage (FTP, AWS S3) with UIZA. After synced, you can select your content easier from your storage to Store API.

See details here.

var result = UizaServices.Storage.Add(new AddStorageParameter()
{
    Name = "FTP Uiza",
    Host = "ftp-example.uiza.io",
    Description = "FTP of Uiza, use for transcode",
    StorageType = StorageInputTypes.Ftp,
    UserName = "uiza",
    Password = "=59x@LPsd+w7qW",
    Port = 21
});
Console.WriteLine(string.Format("Add New Storage Id = {0} Success", result.Data.id));

Live

These APIs used to create and manage live streaming event.

  • When a Live is not start : it's named as Event.
  • When have an Event , you can start it : it's named as Feed.
using Uiza.Net.Services;

UizaConfiguration.SetupUiza(new UizaConfigOptions
{
	ApiKey = "your-ApiKey",
	ApiBase = "your-workspace-api-domain.uiza.co"
});

 var result = UizaServices.Storage.Add(new AddStorageParameter()
{
	Name = "FTP Uiza",
	Host = "ftp-example.uiza.io",
	Description = "FTP of Uiza, use for transcode",
	StorageType = StorageInputTypes.Ftp,
	UserName = "uiza",
	Password = "=59x@LPsd+w7qW",
	Port = 21
});

Console.WriteLine(string.Format("Create Live Streaming Success New Id = {0}", result.Data.id));

See details here.

Callback

Callback used to retrieve an information for Uiza to your server, so you can have a trigger notice about an entity is upload completed and .

using Uiza.Net.Services;

UizaConfiguration.SetupUiza(new UizaConfigOptions
{
	ApiKey = "your-ApiKey",
	ApiBase = "your-workspace-api-domain.uiza.co"
});

var createResult = UizaServices.Callback.Create(new CreateCallbackParameter()
{
	Url = "https://callback-url.uiza.co",
	Method = CallbackMethodTypes.Post,
});

Console.WriteLine(string.Format("Create New Callback Id = {0} Success", createResult.Data.id));

See details here.

Contribution Guidelines

We welcome contributions from anyone interested in Uiza or Uiza.net development. If you'd like to submit a pull request, it's best to start with an issue to describe what you'd like to build.