app_rail-airtable

Gem to help building App Rail servers using Airtable as a backend


License
MIT
Install
gem install app_rail-airtable -v 0.2.11

Documentation

App Rail Airtable

App Rail Airtable is a micro-framework based on Sinatra and Airrecord which faciliates use of Airtable as a backend for App Rail Apps. You can deploy a template repo to Heroku for fast start.

Quick Start

Visit App Rail Airtable Template and follow instructions.

Installation

Add this line to your application's Gemfile:

gem 'app_rail-airtable'

Usage

App Rail Airtable has two important concepts, models and servers. The App Rail Petshop provides useful examples.

Models

App Rail Airtable makes the following assumptions

  1. Your App will connect to a single Airtable Base
  2. Your Airtable Base implements a normalised datamodel
  3. Your tables in Airtable are plural versions of the models you create in Ruby

API keys have account scope in Airtable so it is recommended to create a new account for each project so that API keys do not leak data, e.g. bob+@gmail.com. You can share the project with your main account so you don't need to login to separate accounts for each project.

You should create a model class for each table you want to use in your App. Model classes should extend AppRail::Airtable::ApplicationRecord and define table name and associations

To provide support for routes, models can implement

  • ar_list_item (index)
  • ar_stack (show)
  • self.create_as_json (create)

In order to support authentication you should create a class (normally User) and inherit from AppRail::Airtable::AuthenticationRecord. Your table needs Email, Password Hash and Access Token columns.

Servers

You should create a single server which extends AppRail::Airtable::Sinatra.

App Rail Airtable provides two helpers to generate routes

resources(name, only:) Creates routes that map to a table. It delegates from the route to a model method

  • index to ar_list_item
  • show to ar_stack
  • create to self.create_as_json

authenticable_resources(name, , only:) Acts as resources but also takes a block of routes. Those nested routes will all call the authenticate! helper method before running. The authenticate! helper will call a lookup helper find_authenticatable_resource(access_token:) with the bearer token found in the HTTP_AUTHORIZATION header, which should be used to look up the correct object or return nil if none is found (resulting in a 401 response).

License

The gem is available as open source under the terms of the MIT License.