This commit is contained in:
Paul Schneider 2021-05-10 23:03:59 +01:00
commit b6098c28a6
6 changed files with 53 additions and 56 deletions

View file

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
namespace nuget_cli
{
internal class PushCommand
{
static internal async Task<PushReport> RunAsync(string pkg, string source, string apikey)
{
var report = new PushReport {
PkgName = pkg
};
FileInfo fi = new FileInfo(pkg);
if (!fi.Exists)
throw new Exception("Le fichier n'existe pas");
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("api-key", apikey);
client.BaseAddress = new Uri(source);
var content = new StreamContent(fi.OpenRead());
var response = await client.PutAsync(source, content);
report.StatusCode = response.StatusCode.ToString();
report.Message = await response.Content.ReadAsStringAsync();
report.Executed = true;
return report;
}
}
}