Skip to content

Commit 64abfae

Browse files
committed
Token delete bugfix
1 parent 19f193d commit 64abfae

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

PostTripletex/Authentication.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ private static async Task<string> ToBase64(string sessionToken)
4848
private static async Task<string> GetSessionToken(Credentials credentials)
4949
{
5050
var client = new RestClient(_apiAuthEndpoint);
51-
var request = new RestRequest();
51+
var request = new RestRequest(Method.PUT);
5252

5353
request.AddHeader("Accept", "application/json");
5454
request.AddJsonBody("text/plain", "");
5555
request.AddQueryParameter("consumerToken", credentials.ConsumerToken);
5656
request.AddQueryParameter("employeeToken", credentials.EmployeeToken);
5757
request.AddQueryParameter("expirationDate", credentials.ExpirationDate);
5858

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

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

63-
return response.Value.Token;
63+
return response.Data.Value.Token;
6464
}
6565
}
6666

PostTripletex/FileDoc.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public static string[] ReadFile(string fileName)
4242
return File.Exists(filePath) ? File.ReadAllLines(filePath).Skip(1).ToArray() : null;
4343
}
4444

45+
public static void DeleteFile(string fileName)
46+
{
47+
var filePath = Path.Combine(_directory, fileName);
48+
49+
File.Delete(filePath);
50+
}
51+
4552
public static string GetNumber(string fileName)
4653
{
4754
var filePath = Path.Combine(_directory, fileName);

PostTripletex/Model/Common.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class CustomerCategory
1818
public string name { get; set; }
1919
}
2020

21-
public class SingleValueResponse<T>
21+
public class SingleResponse<T>
2222
{
2323
[JsonProperty("value")]
2424
public T Value { get; set; }

PostTripletex/Post.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static async Task Contact(int number)
4343
request.AddJsonBody(contact);
4444
request.AddHeader("Authorization", $"Basic {Authentication.EncodedCredentials}");
4545

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

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

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

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

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

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

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

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

PostTripletex/Program.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.IO;
32
using System.Linq;
43
using System.Threading.Tasks;
54

@@ -31,7 +30,6 @@ static async Task Main()
3130

3231
private static async Task Run()
3332
{
34-
3533
var command = Console.ReadLine()?.Split(' ').Select(s => s.ToLower()).ToArray();
3634

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

4745
if (command?[0] == "token")
4846
{
49-
File.Delete(Path.Combine("Data", "Tokens.txt"));
50-
Console.WriteLine("Done\n");
47+
FileDoc.DeleteFile("Tokens.txt");
48+
Console.Clear();
5149

5250
await Authentication.Authenticate();
5351
await Get.Sync();

0 commit comments

Comments
 (0)