Skip to content

Provides the source code for a C# wrapper around the WeTransfer public API

License

Notifications You must be signed in to change notification settings

VoxelGroup/ThirdPartyFork.WeTransfer-C-wrapper

 
 

Repository files navigation

WeTransfer-C#-wrapper

Provides the source code for a C# wrapper around the WeTransfer public API

HOW TO USE THE V1 API
Use as follows:
The Program.cs file in the Console application gives an example how to use the Communicator class.
// Fill in your API-key and the directory where the chunks for partial upload can be created.
var uploader = new Communicator(apiKey: "your_secret_API_key",
chunkDirectory:@"The directory you want to use to store chuncks of split files.");

var progress = new Progress();
progress.ProgressChanged += (sender,report) => Console.WriteLine($"{report.Message}: {report.Percentage}");

// Fill in the full paths to the file(s) you want to upload
var result = uploader.UploadFiles(new[] { @"Full path to the first file",
@"Full path to the second file" },
"My beautiful upload request",
progress).Result;

// The result.DownloadUrl can be used by the recipient to download the uploaded files.

HOW TO USE THE V2 API
Unit tests document pretty much how the TransferApiCommunicator and BoardApiCommunicator classes should be used.

TRANSFERAPI

    public void UploadTwoFiles()
    {
        //Act
        var files = new List<FileInfo>();
        foreach (string fileName in new[] { "TextFile1.txt", "picture.jpg" })
        {
            var info = new FileInfo(Path.Combine(_appPath, "Chunks", fileName));
            files.Add(info);
        }
        var result=  _communicator.UploadFiles(files.Select(file => file.FullName), "Testtransfer",_user).Result;
        Assert.IsFalse(string.IsNullOrWhiteSpace(result.DownloadUrl));
        Debug.Print(result.DownloadUrl);
    }

BOARDAPI // boardResponse.Id is the Board Id. This id is needed for the calls to add files, add links and get Board info.

    public void AddTwoFilesToBoard()
    {
        //Arrange
        BoardApiCommunicator.ClearToken();
        _communicator.GetToken("Username").Wait();
        var boardResponse = _communicator.CreateBoard(_user, "My beautiful board").Result;

        var fileRequests = new List<(string name,int size,string fullPath)>();
        var infos = new List<string>();
        foreach (string fileName in new[] { "TextFile1.txt","picture.jpg" })
        {
            var info = new FileInfo(Path.Combine(_appPath, "Chunks", fileName));
            infos.Add(info.FullName);
            fileRequests.Add((name: info.Name, size: (int)info.Length, fullPath: info.FullName));
        }

        //Act
        var fileUploadResponse = _communicator.UploadFilesToBoard(boardResponse.Id, infos,_user).Result;

        //Assert
        Assert.AreEqual(UploadResultV2.ResultCode.Success, fileUploadResponse.Result);

        //Act: get board information
        var infoResponse = _communicator.GetBoardInfo(boardResponse.Id).Result;
    }
    
    public void AddLinksToBoard()
    {
        //Arrange
        var boardResponse = _communicator.CreateBoard(_user,"Links board").Result;
        var links = new[] { (url: "http://wetransfer.com", title: "End user portal for We Transfer"),
                            (url: "http://developers.wetransfer.com",title:"Developers portal for We Transfer")};

        //Act
        var response= _communicator.AddLinks(boardResponse.Id, links).Result;

        //Assert
        Assert.IsTrue(response.statusCode == HttpStatusCode.Created);
        Assert.AreEqual(2,response.responseArray.Length);
    }

About

Provides the source code for a C# wrapper around the WeTransfer public API

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%