Skip to content

Commit

Permalink
Token delete bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaughub committed Jan 28, 2021
1 parent 19f193d commit 64abfae
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
8 changes: 4 additions & 4 deletions PostTripletex/Authentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ private static async Task<string> ToBase64(string sessionToken)
private static async Task<string> GetSessionToken(Credentials credentials)
{
var client = new RestClient(_apiAuthEndpoint);
var request = new RestRequest();
var request = new RestRequest(Method.PUT);

request.AddHeader("Accept", "application/json");
request.AddJsonBody("text/plain", "");
request.AddQueryParameter("consumerToken", credentials.ConsumerToken);
request.AddQueryParameter("employeeToken", credentials.EmployeeToken);
request.AddQueryParameter("expirationDate", credentials.ExpirationDate);

var response = await client.PutAsync<SingleValueResponse<AuthResponse>>(request);
var response = await client.ExecuteAsync<SingleResponse<AuthResponse>>(request);

if (response.Value == null) throw new Exception("Authentication failed");
if (response.Data?.Value?.Token == null) ErrorHandler.Handel(response.Content);

return response.Value.Token;
return response.Data.Value.Token;
}
}

Expand Down
7 changes: 7 additions & 0 deletions PostTripletex/FileDoc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public static string[] ReadFile(string fileName)
return File.Exists(filePath) ? File.ReadAllLines(filePath).Skip(1).ToArray() : null;
}

public static void DeleteFile(string fileName)
{
var filePath = Path.Combine(_directory, fileName);

File.Delete(filePath);
}

public static string GetNumber(string fileName)
{
var filePath = Path.Combine(_directory, fileName);
Expand Down
2 changes: 1 addition & 1 deletion PostTripletex/Model/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CustomerCategory
public string name { get; set; }
}

public class SingleValueResponse<T>
public class SingleResponse<T>
{
[JsonProperty("value")]
public T Value { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions PostTripletex/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static async Task Contact(int number)
request.AddJsonBody(contact);
request.AddHeader("Authorization", $"Basic {Authentication.EncodedCredentials}");

var response = await client.ExecutePostAsync<SingleValueResponse<KeyInfo>>(request);
var response = await client.ExecutePostAsync<SingleResponse<KeyInfo>>(request);

if (!response.IsSuccessful) ErrorHandler.Handel(response.Content);

Expand Down Expand Up @@ -83,7 +83,7 @@ public static async Task Product(int number)
request.AddJsonBody(product);
request.AddHeader("Authorization", $"Basic {Authentication.EncodedCredentials}");

var response = await client.ExecutePostAsync<SingleValueResponse<KeyInfo>>(request);
var response = await client.ExecutePostAsync<SingleResponse<KeyInfo>>(request);

if (!response.IsSuccessful) ErrorHandler.Handel(response.Content);

Expand Down Expand Up @@ -151,7 +151,7 @@ public static async Task Customer(int number)
request.AddJsonBody(new {name = personNameGenerator.GenerateRandomFirstAndLastName()});
request.AddHeader("Authorization", $"Basic {Authentication.EncodedCredentials}");

var response = await client.ExecutePostAsync<SingleValueResponse<KeyInfo>>(request);
var response = await client.ExecutePostAsync<SingleResponse<KeyInfo>>(request);

if (!response.IsSuccessful) ErrorHandler.Handel(response.Content);

Expand Down
6 changes: 2 additions & 4 deletions PostTripletex/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -31,7 +30,6 @@ static async Task Main()

private static async Task Run()
{

var command = Console.ReadLine()?.Split(' ').Select(s => s.ToLower()).ToArray();

if (command?[0] == "q") Environment.Exit(0);
Expand All @@ -46,8 +44,8 @@ private static async Task Run()

if (command?[0] == "token")
{
File.Delete(Path.Combine("Data", "Tokens.txt"));
Console.WriteLine("Done\n");
FileDoc.DeleteFile("Tokens.txt");
Console.Clear();

await Authentication.Authenticate();
await Get.Sync();
Expand Down

0 comments on commit 64abfae

Please sign in to comment.