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) ⇒ Base

Returns a new instance of Base.



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

def initialize(token, id)
  @token = token
  @id = id
  self.class.headers({ 'Authorization': "Bearer #{@token}", 'Content-Type': 'application/json' })
end

Instance Method Details

#base_urlObject (protected)

Instantiate table in base



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

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

#create_table(table_data) ⇒ Airtable::Table

Expects name:,description:,fields:[]



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, @id, response
end

#table(table_id) ⇒ Airtable::Table

Instantiate table in base

Returns:



35
36
37
# File 'lib/airtable/base.rb', line 35

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

#tablesArray

Returns <Airtable::Table>.

Returns:

  • (Array)

    <Airtable::Table>

See Also:



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

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

  check_and_raise_error(response)

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