sirupsen / airrecord

Ruby wrapper for Airtable, your personal database
MIT License
295 stars 58 forks source link

Add Airrecord.base to the ad-hoc API #41

Open chrisfrank opened 5 years ago

chrisfrank commented 5 years ago

Airtable's node client lets you quickly instantiate a base and interact with its tables. We can do likewise.

Node reference:

var Airtable = require('airtable');
var base = new Airtable({apiKey: 'YOUR_API_KEY'}).base('appYOUR_APP_ID');

base('pages').find('recRECID', function(err, record) {
    if (err) { console.error(err); return; }
    console.log(record);
});

Proposed ruby style:

@base = Airrecord::Base.new("YOUR_API_KEY", "appYOUR_APP_ID")
@base.table("pages") #=> <Anonymous Airrecord::Table>
@base.table("pages").records(view: "Grid view") #=> [<Page>, <Page>]
sirupsen commented 5 years ago

The ad-hoc API already lets you do this:

Tea = Airrecord.table("api_key", "app_key", "Teas")

Should we change it, you think?

chrisfrank commented 5 years ago

No, you're right. It should follow the existing format, which more closely mimics the node syntax anyway.

@base = Airrecord.base("api_key", "app_key") #=> <Airrecord::Base>
@base.table("Tea") #=> <Anonymous Airrecord::Table @api_key="api_key" @app_key="app_key">
Coffee = Airrecord.table("api_key", "some_other_app_key", "Coffee")

Airrecord.base would make it a bit more convenient to instantiate many tables from the same base with the same credentials. And Airrecord.table should remain available as a convenient way of accessing tables from different bases, etc.

sirupsen commented 5 years ago

Sounds good to me. This wouldn't be a breaking change, so we can do this in 1.1.