Ejemplo n.º 1
0
 public string Request(TablesParameters parameters)
 {
     using (WebClient client = new WebClient())
     {
         return(client.DownloadString(Utility.GetURI(parameters, _baseUrls, _apiKey)));
     }
 }
Ejemplo n.º 2
0
        public ExcelTableParameters GetNewtableParameter()
        {
            var t = new ExcelTableParameters();

            TablesParameters.Add(t);
            return(t);
        }
Ejemplo n.º 3
0
        public async Task <DataTable> GetDataTableAsync(TablesParameters parameters)
        {
            parameters.ReturnFormat = ReturnFormat.JSON;

            string content = await RequestAsync(parameters);

            JObject jContent = JObject.Parse(content);

            return(JsonConvert.DeserializeObject <DataTable>(jContent["datatable"].ToString()));
        }
Ejemplo n.º 4
0
        public DataTableMetaData GetDataTableMetaData(TablesParameters parameters)
        {
            parameters.ReturnFormat = ReturnFormat.JSON;

            parameters.Metadata = true;

            string content = Request(parameters);

            JObject jContent = JObject.Parse(content);

            return(JsonConvert.DeserializeObject <DataTableMetaData>(jContent["datatable"].ToString()));
        }
Ejemplo n.º 5
0
        public static Uri GetURI(TablesParameters parameters, BaseUrls baseUrls, string apiKey)
        {
            string url = $"{baseUrls.TablesUrl}{parameters.VendorCode}/{parameters.DatatableCode}";

            url += parameters.Metadata.HasValue && parameters.Metadata.Value ? $"/metadata" : string.Empty;

            url += $".{GetReturnFormat(parameters.ReturnFormat)}";

            UriBuilder uriBuilder = new UriBuilder(url);

            string uriQuery = $"api_key={apiKey}";

            if (parameters.RowsFilter != null && parameters.RowsFilter.Any())
            {
                foreach (KeyValuePair <string, List <string> > rowFilter in parameters.RowsFilter)
                {
                    if (rowFilter.Value != null && rowFilter.Value.Any())
                    {
                        uriQuery += $"&{rowFilter.Key}=";

                        rowFilter.Value.ToList().ForEach(v => uriQuery += rowFilter.Value.Last() != v ? $"{v}," : v);
                    }
                }
            }

            if (parameters.Columns != null && parameters.Columns.Any())
            {
                uriQuery += $"&qopts.columns=";

                parameters.Columns.ToList().ForEach(col => uriQuery += parameters.Columns.Last() != col ? $"{col}," : col);
            }

            if (parameters.PerPage.HasValue)
            {
                uriQuery += $"&qopts.per_page={parameters.PerPage}";
            }

            if (!string.IsNullOrEmpty(parameters.CursorID))
            {
                uriQuery += $"&qopts.cursor_id={parameters.CursorID}";
            }

            if (parameters.Export.HasValue && parameters.Export.Value)
            {
                uriQuery += "&qopts.export=true";
            }

            uriBuilder.Query = uriQuery;

            return(uriBuilder.Uri);
        }
Ejemplo n.º 6
0
        private static void GetTablesData()
        {
            TablesParameters parameters = new TablesParameters();

            Console.WriteLine("Vendor Code *:");

            parameters.VendorCode = Console.ReadLine();

            Console.WriteLine("Datatable Code *:");

            parameters.DatatableCode = Console.ReadLine();

            Console.WriteLine("Return Format (JSON, CSV, or XML) *:");

            parameters.ReturnFormat = (ReturnFormat)Enum.Parse(typeof(ReturnFormat), Console.ReadLine(), true);

            Console.WriteLine("Per Page:");

            parameters.PerPage = ParseInt(Console.ReadLine());

            Console.WriteLine("CursorID:");

            parameters.CursorID = Console.ReadLine();

            Console.WriteLine("Meta Data (Y / N):");

            parameters.Metadata = ParseBool(Console.ReadLine());

            Console.WriteLine("Export (Y / N):");

            parameters.Export = ParseBool(Console.ReadLine());

            Console.WriteLine("Row Filter (e = end)");

            parameters.RowsFilter = GetRowFilter();

            Console.WriteLine("Columns (Separate with comma):");

            parameters.Columns = GetColumns(Console.ReadLine());

            Console.WriteLine("Result:");

            Console.WriteLine(_client.Request(parameters));
        }