refact
This commit is contained in:
parent
36e1137e50
commit
b6098c28a6
6 changed files with 53 additions and 56 deletions
30
src/nuget-cli/PushCommand.cs
Normal file
30
src/nuget-cli/PushCommand.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue