Class: Airtable::Record

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

Overview

Object corresponding to an Airtable Record

Instance Attribute Summary collapse

Attributes inherited from Resource

#id, #token

Instance Method Summary collapse

Methods inherited from Resource

#check_and_raise_error

Constructor Details

#initialize(token, table, id, data = nil) ⇒ Record

Returns a new instance of Record.



7
8
9
10
11
12
13
# File 'lib/airtable/record.rb', line 7

def initialize(token, table, id, data = nil)
  super(token)
  @table = table
  @base = @table.base
  @id = id
  @data = data
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



5
6
7
# File 'lib/airtable/record.rb', line 5

def base
  @base
end

#tableObject (readonly)

Returns the value of attribute table.



5
6
7
# File 'lib/airtable/record.rb', line 5

def table
  @table
end

Instance Method Details

#dataHash

Return record data, retrieve if not present



18
19
20
21
22
23
24
25
26
# File 'lib/airtable/record.rb', line 18

def data
  @data ||= begin
    response = self.class.get(record_url).parsed_response

    check_and_raise_error(response)

    response
  end
end

#record_urlObject (protected)

Endpoint for records



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

def record_url = "/v0/#{@base.id}/#{@table.id}/#{@id}"

#update(record_data) ⇒ Airtable::Record



30
31
32
33
34
35
36
37
# File 'lib/airtable/record.rb', line 30

def update(record_data)
  response = self.class.patch(record_url,
                              body: { fields: record_data }.to_json).parsed_response

  check_and_raise_error(response)

  Airtable::Record.new @token, @base.id, @table.id, response['id'], response
end