Class: Airtable::Base

Inherits:
Resource show all
Defined in:
lib/airtable/base.rb

Overview

Object corresponding to an Airtable Base

Instance Attribute Summary

Attributes inherited from Resource

#id, #token

Instance Method Summary collapse

Methods inherited from Resource

#check_and_raise_error

Constructor Details

#initialize(token, id, tables = nil) ⇒ Base

Returns a new instance of Base.



5
6
7
8
9
# File 'lib/airtable/base.rb', line 5

def initialize(token, id, tables = nil)
  super(token)
  @id = id
  @tables = tables
end

Instance Method Details

#base_urlObject (protected)

Endpoint for bases



45
# File 'lib/airtable/base.rb', line 45

def base_url = "/v0/meta/bases/#{@id}"

#create_table(table_data) ⇒ Airtable::Table

Parameters:

  • table_data (Hash)

    Payload for table creation. Expects name:,description:,fields:[]

Returns:

See Also:



14
15
16
17
18
19
20
21
# File 'lib/airtable/base.rb', line 14

def create_table(table_data)
  response = self.class.post("#{base_url}/tables",
                             body: table_data.to_json).parsed_response

  check_and_raise_error(response)

  Airtable::Table.new @token, self, response['id'], response
end

#table(table_id) ⇒ Airtable::Table

Instantiate table in base

Parameters:

  • table_id (String)

    ID of table

Returns:



38
39
40
# File 'lib/airtable/base.rb', line 38

def table(table_id)
  Airtable::Table.new(@token, @id, table_id)
end

#tablesArray<Airtable::Table>



25
26
27
28
29
30
31
32
33
# File 'lib/airtable/base.rb', line 25

def tables
  @tables ||= begin
    response = self.class.get("#{base_url}/tables")

    check_and_raise_error(response)

    response['tables'].map { Airtable::Table.new(@token, self, _1['id'], _1) }
  end
end