/// <summary> /// Starts the execution of a Connector based on the parameters /// </summary> /// <param name="sdk"></param> /// <param name="request"></param> /// <returns></returns> public static async Task <Item> CreateItem(PluggyAPI sdk, ItemParameters request) { try { return(await sdk.CreateItem(request)); } catch (ValidationException e) { Console.WriteLine("Execution not started, reason {0} ", e.Message); if (e.ApiError.Errors != null && e.ApiError.Errors.Count > 0) { foreach (var error in e.ApiError.Errors) { Console.WriteLine("[X] {0} ", error.Message); } } Console.ReadLine(); return(null); } catch (ApiException e) { Console.WriteLine("There was an issue starting the execution"); Console.WriteLine(e.Message); Console.ReadLine(); return(null); } }
/// <summary> /// Once the execution has been submited correctly, /// Poll for the execution status, in an interval /// </summary> /// <param name="sdk"></param> /// <param name="item"></param> /// <returns></returns> public static async Task <Item> WaitAndCollectResponse(PluggyAPI sdk, Item item) { Item itemResponse; do { await Task.Delay(PluggyAPI.STATUS_POLL_INTERVAL); Console.WriteLine("Checking Connection status..."); itemResponse = await sdk.FetchItem(item.Id); // For MFA connections, we require to provide an extra credential if (itemResponse.Status == ItemStatus.WAITING_USER_INPUT) { var credential = itemResponse.Parameter; Console.WriteLine("What is your {0}?", credential.Label); string response = Console.ReadLine(); var parameter = new ItemParameter(credential.Name, response); itemResponse = await sdk.UpdateItemMFA(item.Id, new List <ItemParameter> { parameter }); } }while (!itemResponse.HasFinished()); return(itemResponse); }
/// <summary> /// This application is intended to explain a basic flow of the Pluggy API /// </summary> /// <param name="args"></param> /// <returns></returns> static async Task Main(string[] args) { // Fetching keys from appsettings.json var(CLIENT_ID, CLIENT_SECRET, URL_BASE) = Configuration(); var sdk = new PluggyAPI(CLIENT_ID, CLIENT_SECRET, URL_BASE); Console.WriteLine("Please select an operation to walkthrough"); Console.WriteLine("1. Create an Item"); Console.WriteLine("2. Update an Item"); Console.WriteLine("3. Create a ConnectToekn for Widget"); string action = Console.ReadLine(); switch (action) { case "1": await CreateItem(sdk); break; case "2": await UpdateItem(sdk); break; case "3": await CreateConnectToken(sdk); break; } Console.WriteLine("Explore our SDK to know what else you can do!"); Console.ReadLine(); }
/// <summary> /// Using the SDK we retrieve a connector by its Id /// Different exceptions are provided to use on the flow /// </summary> /// <param name="sdk"></param> /// <param name="connectorId"></param> /// <returns></returns> public static async Task <Connector> FetchConnector(PluggyAPI sdk, long connectorId) { try { return(await sdk.FetchConnector(connectorId)); } catch (NotFoundException) { Console.WriteLine("The connector with Id {0} was not found.", connectorId); Console.ReadLine(); return(null); } catch (ApiException e) { Console.WriteLine("There was an issue retrieving connection"); Console.WriteLine(e.Message); Console.ReadLine(); return(null); } }