Esempio n. 1
0
        private async Task <List <T> > GetDataFromAPI <T>(Type type, SupplierConnection connection, string url, CommonRQ request)
        {
            Dictionary <string, string> headers = new Dictionary <string, string> {
                { "X-FareHarbor-API-App", connection.Login },
                { "X-FareHarbor-API-User", connection.Secret },
            };
            List <T> list = new List <T>();

            //convert strongly typed class to dictionary of request parameters
            Dictionary <string, string> parameters = request.AsDictionary();
            string result = await ApiInvoker.SendRequestGet(connection.URL + url, parameters, headers);

            var      rs     = JsonConvert.DeserializeObject(result, type); //Deserialize the data as the provided type
            CommonRS common = (CommonRS)rs;                                //We know all returned data can be cast to this basic type
            var      data   = common.GetData <T>();                        //Get the actual list of results as generic type

            list.AddRange(data);
            return(list);
        }