yoanbernabeu / Airtable-Client-Bundle

Simple Client for Airtable API
MIT License
33 stars 12 forks source link
airtable airtable-api bundle php symfony symfony-bundle

Airtable Client Bundle

Static code analysis Testing

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

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.