Example #1
0
    /// <summary>
    /// Download a notion table and return the parsed object
    /// </summary>
    /// <param name="databaseID"></param>
    public static async Task <TableResult> GetTableAsync(string databaseID)
    {
        string route = $"{API_URL}/databases/{databaseID.Replace("-", "")}/query";

        bool        fetchMore = true;
        string      cursor    = string.Empty;
        TableResult table     = new TableResult();

        Debug.Log("Downloading notion database [" + databaseID + "]...");

        while (fetchMore)
        {
            var json = await GetRequest(route, cursor, "POST");

            if (json != null)
            {
                var pageTable = new TableResult(json);
                table.Merge(pageTable);

                // Pagination
                fetchMore = json["has_more"] != null && ((bool)json["has_more"]);
                if (fetchMore && json["next_cursor"] != null)
                {
                    cursor = json["next_cursor"].ToString();
                }
            }
        }

        Debug.Log("Download completed: " + table.Lines.Length + " found.");

        return(table);
    }