59 lines
2.2 KiB
C#
59 lines
2.2 KiB
C#
using System;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Net.Security;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BackupPipefy.Infrastructure.Services
|
|
{
|
|
public class PipefyClient
|
|
{
|
|
private readonly HttpClient _httpClient;
|
|
private readonly PipefyTokenService _tokenService;
|
|
|
|
public PipefyClient(PipefyTokenService tokenService, bool useProxy = false)
|
|
{
|
|
if (useProxy)
|
|
{
|
|
var handler = new HttpClientHandler
|
|
{
|
|
Proxy = new WebProxy("127.0.0.1", 8888),
|
|
UseProxy = true,
|
|
ServerCertificateCustomValidationCallback = (HttpRequestMessage req, X509Certificate2? cert, X509Chain? chain, SslPolicyErrors errors) => true
|
|
};
|
|
|
|
_httpClient = new HttpClient(handler);
|
|
}
|
|
else
|
|
{
|
|
_httpClient = new HttpClient();
|
|
}
|
|
|
|
_tokenService = tokenService;
|
|
}
|
|
|
|
public async Task<string> GetCardsAsync(int pipeId, DateTime lastUpdated)
|
|
{
|
|
var token = await _tokenService.GetTokenAsync();
|
|
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
|
|
// Montar GraphQL e enviar request
|
|
// Exemplo simplificado:
|
|
var query = new
|
|
{
|
|
query = @"{ allCards(pipeId: 303718996, after: \""WyIxLjAiLCI1MC4wIiw4MTgzNjgwNzhd\""){ edges{ node{ id title emailMessagingAddress } } pageInfo{ endCursor hasNextPage } }}"
|
|
};
|
|
|
|
var content = new StringContent(System.Text.Json.JsonSerializer.Serialize(query));
|
|
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
|
|
|
|
var response = await _httpClient.PostAsync("https://api.pipefy.com/graphql", content);
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
return await response.Content.ReadAsStringAsync();
|
|
}
|
|
}
|
|
}
|