Skip to content

benoror/ember-airtable

Repository files navigation

ember-airtable

Blog post: https://medium.com/@benoror/creating-an-ember-addon-for-airtable-api-d9e38d7bef97#.33q0r7hhm

Node Proxy (Optional): https://github.com/benoror/airtable-api-proxy

NPM

Download count all time Ember Observer Score Build Status PRs Welcome

Ember addon for Airtable APIs

Dummy app: https://github.com/benoror/ember-airtable/tree/master/tests/dummy/app

*Originally based on: https://github.com/benoror/fieldbook-app

Usage

Install

ember install ember-airtable

Adapter

Use AirtableAdapter as you application's main adapter:

adapters/application.js:
import AirtableAdapter from "ember-airtable/adapter";

export default AirtableAdapter.extend({

  // API Version + Base ID
  namespace: 'v0/app_YOUR_AIRTABLE_BASE_KEY',

  headers: {
    'Accept': 'application/json',
    // API Token
    'Authorization': `Bearer key_YOUR_AIRTABLE_API_KEY`
  }
});

Serializer

Use AirtableSerializer as you application's main serializer:

serializers/application.js:
import AirtableSerializer from "ember-airtable/serializer";

export default AirtableSerializer.extend();

Models

If you want to skip persistance of certain attributes (ex. formula columns) add the readOnly option:

models/product.js:
import DS from 'ember-data';

export default DS.Model.extend({
  formula: DS.attr('string', { readOnly: true })
});

Querying Airtable API

You can use all of the API features when querying Airtable:

routes/products.js:
import Ember from 'ember';

export default Ember.Route.extend({
  model() {
    return this.store.query('product', {
      // Only data for fields whose names are in this list will be included in the records.
      fields: ['name', 'description'],
      // A formula used to filter records.
      filterByFormula: "NOT({name} = 'MacBook')",
      // The maximum total number of records that will be returned.
      maxRecords: 50,
      // The number of records returned in each request.
      pageSize: 10,
      // A list of sort objects that specifies how the records will be ordered.
      sort: [{field: "name", direction: "desc"}],
      // The name or ID of a view in the table. 
      view: 'active_products'
    });
  }
});

Development

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • npm test (Runs ember try:testall to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://ember-cli.com/.