Adiciona novo construtor à classe Fatura com HttpClient
Inclui uma sobrecarga do construtor de Fatura que recebe id, fatura_path e HttpClient, realiza requisição para obter status da fatura, faz parsing do JSON de resposta e inicializa propriedades relevantes, incluindo suporte a faturas agrupadas.
This commit is contained in:
parent
0aad4ce2c3
commit
bf824a885d
@ -54,7 +54,30 @@ namespace Faturas
|
|||||||
Agrupada_children = faturaParsed.GetProperty("children").EnumerateArray();
|
Agrupada_children = faturaParsed.GetProperty("children").EnumerateArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public Fatura(string id, string fatura_path, HttpClient httpClient)
|
||||||
|
{
|
||||||
|
// Utilizado para gerar novo token
|
||||||
|
// this.token = Req_token(HttpClient).ToString();
|
||||||
|
HttpResponseMessage fatura_response = GetStatus(httpClient, Token, id);
|
||||||
|
if (fatura_response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
faturaParsed = JsonDocument.Parse(fatura_response.Content.ReadAsStringAsync().Result).RootElement;
|
||||||
|
Agrupada = faturaParsed.TryGetProperty("multiple", out var _);
|
||||||
|
Status = faturaParsed.GetProperty("status").GetString();
|
||||||
|
Arquivo = new FileInfo(fatura_path);
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (faturaParsed.GetProperty("external").GetString() is not null)
|
||||||
|
{
|
||||||
|
pagina = JsonDocument.Parse(faturaParsed.GetProperty("external").GetString()!).RootElement.GetProperty("origin")[0].GetProperty("page").GetInt32();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Agrupada)
|
||||||
|
{
|
||||||
|
Agrupada_children = faturaParsed.GetProperty("children").EnumerateArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Fatura"/> class.
|
/// Initializes a new instance of the <see cref="Fatura"/> class.
|
||||||
/// Inicializa uma nova instância da classe <see cref="Fatura"/> para faturas já processadas.
|
/// Inicializa uma nova instância da classe <see cref="Fatura"/> para faturas já processadas.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user