ngocnicholas / airtable.net

Airtable .NET API Client
MIT License
138 stars 34 forks source link

Add AirtableMeta.cs #55

Closed Wetzel402 closed 2 years ago

Wetzel402 commented 2 years ago

`string errorMessage = null; var records = new List();

        using (AirtableMeta m = new AirtableMeta(appKey))
        {
            Task<AirtableMetaBasesResponse> task = m.ListBases(appKey);
            AirtableMetaBasesResponse response = await task; //null ref exception

            if (response.Success)
            {
                records.AddRange(response.Bases);
            }
            else if (response.AirtableApiError is AirtableApiException)
            {
                errorMessage = response.AirtableApiError.ErrorMessage;
            }
            else
            {
                errorMessage = "Unknown error";
            }
        }

        if (!string.IsNullOrEmpty(errorMessage))
        {
            Debug.WriteLine(errorMessage);
        }
        else
        {
            // Do something with the retrieved 'records' and the 'offset'
            // for the next page of the record list.
            if (records.Any())
            {
                foreach (var record in records)
                {
                    Debug.WriteLine(record.Id);
                    Debug.WriteLine(record.Name);
                    Debug.WriteLine(record.Permission);
                }
            }
            else
            {
                Debug.WriteLine("records is empty");
            }
        }`

`string errorMessage = null; var records = new List();

        using (AirtableMeta m = new AirtableMeta(appKey))
        {
            Task<AirtableMetaTablesResponse> task = m.ListTables(appKey, baseId);
            AirtableMetaTablesResponse response = await task; //null ref exception

            if (response.Success)
            {
                records.AddRange(response.Tables);
            }
            else if (response.AirtableApiError is AirtableApiException)
            {
                errorMessage = response.AirtableApiError.ErrorMessage;
            }
            else
            {
                errorMessage = "Unknown error";
            }
        }

        if (!string.IsNullOrEmpty(errorMessage))
        {
            Debug.WriteLine(errorMessage);
        }
        else
        {
            // Do something with the retrieved 'records' and the 'offset'
            // for the next page of the record list.
            if (records.Any())
            {
                foreach (var record in records)
                {
                    Debug.WriteLine(record.Id);
                    Debug.WriteLine(record.Name);
                    Debug.WriteLine(record.PrimaryField);
                    foreach (var field in record.Fields)
                    {
                        Debug.WriteLine(field.Id);
                        Debug.WriteLine(field.Name);
                        Debug.WriteLine(field.Type);

                    }
                    foreach (var view in record.Views)
                    {
                        Debug.WriteLine(view.Id);
                        Debug.WriteLine(view.Name);
                        Debug.WriteLine(view.Type);

                    }
                }
            }
            else
            {
                Debug.WriteLine("records is empty");
            }
        }`
Wetzel402 commented 2 years ago

I repurposed the existing code to work with the meta api

ngocnicholas commented 2 years ago

Airtable Metadata is a complete different Airtable API. It does not belong here.