ExAirtable.Airtable.Record (ExAirtable v0.2.8) View Source

Struct for an Airtable Record.

This should directly match the results returned from any Airtable REST API endpoint that returns records.

Link to this section Summary

Functions

Convert a typical Airtable JSON response into a %Record{}

Given a table module, and a map of attributes that has been generated by to_schema/2, convert back into a valid %Record{}.

Retrieve a field from within a record's fields

Convert a record to an internal schema, mapping Airtable field names to local field names based on a %{"Schema" => "map"}.

Link to this section Types

Specs

t() :: %ExAirtable.Airtable.Record{
  createdTime: String.t(),
  fields: %{},
  id: String.t()
}

Link to this section Functions

Convert a typical Airtable JSON response into a %Record{}

Link to this function

from_schema(table_module, attrs)

View Source

Given a table module, and a map of attributes that has been generated by to_schema/2, convert back into a valid %Record{}.

This is essentially the reverse of to_schema/2.

Link to this function

get(record, field, default \\ nil)

View Source

Retrieve a field from within a record's fields

Returns nil by default if no field matches.

Link to this function

to_schema(record, schema_map)

View Source

Convert a record to an internal schema, mapping Airtable field names to local field names based on a %{"Schema" => "map"}.

Returns a plain map, suitable for eg. Ecto casting + conversion.

Note that fields not included in the schema() map (which is empty by default) will not be added to the final schema. This is by design, since we don't always care to deal with every field that's returned by Airtable in our local systems. However, it does mean that you will want to take care to include every field that you wish to convert into your local schema.

If no schema map is given, the record fields are returned unmodified as a map.

Examples

iex> record = %ExAirtable.Airtable.Record{id: "1", fields: %{"AirtableField" => "value"}}

iex> to_schema(record, %{"AirtableField" => "localfield"})
%{"airtable_id" => "1", "localfield" => "value"}

iex> to_schema(record, nil)
%{"airtable_id" => "1", "AirtableField" => "value"}