yoanbernabeu/airtable-client-bundle

Simple Client for Airtable API

0.1.2 2021-07-30 22:18 UTC

This package is auto-updated.

Last update: 2021-11-28 14:12:45 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
            ]
        );
    }

    // ...
}

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()
        ]);
    }

    // ...
}

License

See the bundled LICENSE file.