yoanbernabeu/airtable-client-bundle

Simple Client for Airtable API

Installs: 4 450

Dependents: 0

Suggesters: 0

Security: 0

Stars: 32

Watchers: 5

Forks: 11

Open Issues: 5

Type:symfony-bundle

1.1.0 2023-04-02 22:29 UTC

This package is auto-updated.

Last update: 2024-04-03 14:11:25 UTC


README

Static code analysis Testing

The Airtable Client bundle is a Symfony bundle that attempts to make the Airtable API easier to use.

  • Retrieve data from a table, optionally choosing a view
  • Retrieve a recording by ID

Installation

Airtable Client Bundle requires PHP 7.4+ and Symfony 5.2+.

Install this bundle using Composer and Symfony Flex:

composer require yoanbernabeu/airtable-client-bundle

To configure Airtable Client Bundle, please create an airtable_client.yaml file in config/packages/ with the following information:

airtable_client:
  key:
  id:

To find your Airtable base ID, go to your API documentation and look in the Introduction section.

Airtable ID

To find your Airtable API key, go to your Account options and search in the API section.

Airtable KEY

Usage

Find

use Yoanbernabeu\AirtableClientBundle\AirtableClientInterface;

class Foo
{
    public int $id;
    public string $bar;
}

class FooController
{
    public function bar(AirtableClientInterface $airtableClient)
    {
        $records = $airtableClient->findAll('tableName', 'viewName', Foo::class);
        
        foreach($records as $record) {
            /** @var Foo $foo */
            $foo = $record->getFields();
            
            echo $foo->bar;
        }
        
        $airtableClient->findBy('tableName', 'fieldName', 'value', Foo::class);      
          
        $record = $airtableClient->find('tableName', 'id');
        
        /** @var Foo $foo */
        $foo = $record->getFields();
            
        echo $foo->bar;
        
        $airtableClient->findLast('tableName', 'fieldName');

        $airtableClient->add(
            'tableName',
            [
                'id' => 1,
                'bar' => 'lorem ipsum',
                Foo::class
            ]
        );
    }

    // ...
}

Add

use Yoanbernabeu\AirtableClientBundle\AirtableClientInterface;

class Foo
{
    public int $id;
    public string $bar;
}

class FooController
{
    public function bar(AirtableClientInterface $airtableClient)
    {
        $airtableClient->add(
            'tableName',
            [
                'id' => 1,
                'bar' => 'lorem ipsum',
                Foo::class
            ]
        );
    }

    // ...
}

Edit

use Yoanbernabeu\AirtableClientBundle\AirtableClientInterface;

class Foo
{
    public int $id;
    public string $bar;
}

class FooController
{
    public function bar(AirtableClientInterface $airtableClient)
    {
        $airtableClient->update(
            'tableName',
            'recordId',
            [
                'id' => 1,
                'bar' => 'lorem ipsum',
                Foo::class
            ]
        );
    }

    // ...
}

Create Form

use Yoanbernabeu\AirtableClientBundle\AirtableClientInterface;
use Symfony\Component\HttpFoundation\Request;

class FooController
{
    public function bar(AirtableClientInterface $airtableClient, Request $request)
    {
        $form = $airtableClient->createForm([
            'Name' => TextType::class,
            'text' => TextType::class,
            'Submit' => SubmitType::class
        ]);

        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $data = $form->getData();
            $airtableClient->add('test', $data);
        }
        return $this->render('bar.html.twig', [
            'form' => $form->createView()
        ]);
    }

    // ...
}

Metadata

Easy access to Airtable's Metadata via its Metadata API

use Yoanbernabeu\AirtableClientBundle\AirtableClientInterface;

class FooController
{
    public function bar(AirtableClientInterface $airtableClient)
    {
        // Get Metadata for All Tables
        $tablesMeta = $airtableClient->getTablesMetadata();

        // Get Metadata for One Table
        $tableMeta = $airtableClient->getTableMetadata('TableName');

    // ...
}

License

See the bundled LICENSE file.