コード例 #1
0
        //----------------------------------------------------------------------------
        //
        // AirtableBase.BuildUriForListRecords
        //
        // Build URI for the List Records operation
        //
        //----------------------------------------------------------------------------

        private Uri BuildUriForListRecords(
            string tableName,
            string offset,
            IEnumerable <string> fields,
            string filterByFormula,
            int?maxRecords,
            int?pageSize,
            IEnumerable <Sort> sort,
            string view)
        {
            var uriBuilder = new UriBuilder(AIRTABLE_API_URL + BaseId + "/" + Uri.EscapeDataString(tableName));

            if (!string.IsNullOrEmpty(offset))
            {
                AddParametersToQuery(ref uriBuilder, $"offset={HttpUtility.UrlEncode(offset)}");
            }

            if (fields != null)
            {
                string flattenFieldsParam = QueryParamHelper.FlattenFieldsParam(fields);
                AddParametersToQuery(ref uriBuilder, flattenFieldsParam);
            }

            if (!string.IsNullOrEmpty(filterByFormula))
            {
                AddParametersToQuery(ref uriBuilder, $"filterByFormula={HttpUtility.UrlEncode(filterByFormula)}");
            }

            if (sort != null)
            {
                string flattenSortParam = QueryParamHelper.FlattenSortParam(sort);
                AddParametersToQuery(ref uriBuilder, flattenSortParam);
            }

            if (!string.IsNullOrEmpty(view))
            {
                AddParametersToQuery(ref uriBuilder, $"view={HttpUtility.UrlEncode(view)}");
            }

            if (maxRecords != null)
            {
                if (maxRecords <= 0)
                {
                    throw new ArgumentException("Maximum Number of Records must be > 0", "maxRecords");
                }
                AddParametersToQuery(ref uriBuilder, $"maxRecords={maxRecords}");
            }

            if (pageSize != null)
            {
                if (pageSize <= 0 || pageSize > MAX_PAGE_SIZE)
                {
                    throw new ArgumentException("Page Size must be > 0 and <= 100", "pageSize");
                }
                AddParametersToQuery(ref uriBuilder, $"pageSize={pageSize}");
            }
            return(uriBuilder.Uri);
        }
コード例 #2
0
        //----------------------------------------------------------------------------
        //
        // AirtableBase.BuildUriForListRecords
        //
        // Build URI for the List Records operation
        //
        //----------------------------------------------------------------------------

        private Uri BuildUriForListRecords(
            string tableName,
            string offset,
            IEnumerable <string> fields,
            string filterByFormula,
            int?maxRecords,
            int?pageSize,
            IEnumerable <Sort> sort,
            string view)
        {
            var uriBuilder = new UriBuilder(AIRTABLE_API_URL + BaseId + "/" + tableName);

            var query = HttpUtility.ParseQueryString(uriBuilder.Query);

            if (!string.IsNullOrEmpty(offset))
            {
                query["offset"] = offset;
            }

            if (fields != null)
            {
                QueryParamHelper.FlattenFieldsParam(fields, query);
            }

            if (!string.IsNullOrEmpty(filterByFormula))
            {
                query["filterByFormula"] = filterByFormula;
            }

            if (sort != null)
            {
                QueryParamHelper.FlattenSortParam(sort, query);
            }

            if (!string.IsNullOrEmpty(view))
            {
                query["view"] = view;
            }

            if (query.Count > 0)
            {
                if (uriBuilder.Query != null && uriBuilder.Query.Length > 1)
                {
                    uriBuilder.Query = uriBuilder.Query.Substring(1) + "&" + query.ToString();
                }
                else
                {
                    uriBuilder.Query = query.ToString();
                }
            }

            if (maxRecords != null)
            {
                if (maxRecords <= 0)
                {
                    throw new ArgumentException("Maximum Number of Records must be > 0", "maxRecords");
                }

                if (uriBuilder.Query != null && uriBuilder.Query.Length > 1)
                {
                    uriBuilder.Query = uriBuilder.Query.Substring(1) + "&maxRecords=" + maxRecords;
                }
                else
                {
                    uriBuilder.Query = $"maxRecords={maxRecords}";
                }
            }

            if (pageSize != null)
            {
                if (pageSize <= 0 || pageSize > MAX_PAGE_IZE)
                {
                    throw new ArgumentException("Page Size must be > 0 and <= 100", "pageSize");
                }

                if (uriBuilder.Query != null && uriBuilder.Query.Length > 1)
                {
                    uriBuilder.Query = uriBuilder.Query.Substring(1) + "&pageSize=" + pageSize;
                }
                else
                {
                    uriBuilder.Query = $"pageSize={pageSize}";
                }
            }

            return(uriBuilder.Uri);
        }