Skip to content

Fork to add support for paginated results from the Airtable API

License

Notifications You must be signed in to change notification settings

mron/AirtableKit

 
 

Repository files navigation

AirtableKit

Supported platforms: iOS & macOS Language: Swift MIT License

Follow us Follow us

AirtableKit is a 100% Swift framework to wrap the REST API provided by Airtable. The implementation fully leverages Combine to handle asynchronous operations.

Features

  • Standard CRUD operations;
  • Operation batching;
  • API Error forwarding.

Instalation

AirtableKit only supports Swift Package Manager at the moment.

.package(url: "http://github.com/appledeveloperacademypucrs/AirtableKit.git", .upToNextMajor(from: "1.0.0"))

To install AirtableKit using Swift Package Manager look for http://github.com/appledeveloperacademypucrs/AirtableKit.git in Xcode (File/Swift Packages/Add Package Dependency...).

See Adding Package Dependencies to Your App for details.

Usage

To use AirtableKit, create an Airtable with your API Key and Base ID:

let airtable = Airtable(baseID: apiBaseId, apiKey: apiKey)

Listing records

Then, you can list items in any table in your base:

let publisher = airtable.list(tableName: tableName)

// to get only some fields
let publisher = airtable.list(tableName: tableName,
                              fields: ["name", "age", "isCool"])
        

or get an individual record, providing its ID:

let publisher = airtable.get(tableName: tableName, 
                             recordID: "YOUR_AIRTABLE_RECORD_ID")
        

Creating records

You can also create a new record:

let fields: [String: Any] = [
  "name" : "Nicolas",
  "isCool" : true
  "age" : 25,
  "updatedTime" : Date()
]

let record = Record(fields: fields)

let publisher = airtable.create(tableName: tableName, record: record)

or multiple records:

let fields: [[String: Any]] = [
  [
    "name" : "Nicolas",
    "isCool" : true
    "age" : 25,
    "updatedTime" : Date()
  ],
  [
    "name" : "Rafael",
    "isCool" : true
    "age" : 22,
    "updatedTime" : Date()
  ]
]

let records = fields.map { Record(fields: $0) }

let publisher = airtable.create(tableName: tableName, records: records)

Updating records

You can also update an existing record:

let fields: [String: Any] = [
  "name" : "Nicolas",
  "isCool" : true
  "age" : 25,
  "updatedTime" : Date()
]

let record = Record(fields: fields, id: "YOUR_AIRTABLE_RECORD_ID")

let publisher = airtable.update(tableName: tableName, record: record)

or multiple records:

let records = [
  Record(fields: [
    "name" : "Nicolas",
    "isCool" : true
    "age" : 25,
    "updatedTime" : Date()
  ], id: "YOUR_AIRTABLE_RECORD_ID_1"),
  
  Record(fields: [
    "name" : "Rafael",
    "isCool" : true
    "age" : 22,
    "updatedTime" : Date()
  ], id: "YOUR_AIRTABLE_RECORD_ID_2")
]
  
let publisher = airtable.update(tableName: tableName, records: records)

Deleting records

And finally, you can also delete an existing record:

let publisher = airtable.delete(tableName: tableName, recordID: "YOUR_AIRTABLE_RECORD_ID")

or multiple records:

let publisher = airtable.delete(tableName: tableName, recordsIDs: ["YOUR_AIRTABLE_RECORD_ID_1", "YOUR_AIRTABLE_RECORD_ID_2"])

Documentation

Full documentation of the types and methods is available on the wiki pages.

License

MIT License.

About

Fork to add support for paginated results from the Airtable API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%