Fieldbook;像创建电子表格一样轻松创建数据库。
基本上,它是一个免费的云电子表格服务,其 API 通过此 SDK 被相当简单地包装。
我与 Fieldbook 没有联系,只是想打包并分享我的代码!
要运行示例项目,克隆仓库,然后首先从 Example 目录运行 pod install
。
示例项目无意中展示了 SDK 如何工作的示例。应用将从公共(只读)Fieldbook 电子表格(https://fieldbook.com/books/56cb45f67753cf030003e42b)中提取数据,并在列表中显示它。点击一个项目将允许您编辑该项目的数据,您也可以滑动以删除项目。右上角的加号图标允许您添加更多项目。由于数据是所有用户都看到的内容,让我们尽量保持它正常工作吧;)
/// Set the authentication details (key & secret / username & password)
/// Necessary if you wish to add/update/delete items or access a private book
///
/// - parameters:
/// - key: key / username from API-access on Fieldbook website
/// - secret: secret / password from API-access on Fieldbook website
public static func setAuthDetails( key: String, secret: String )
/// Get all the items at the specified path
///
/// - parameters:
/// - query: query path of the form "<book_id>/<sheet_name>"
/// - completion: block called upon completion of the query, with either an array of items or an error
public static func getItems( query: String, completion: (items: NSArray?, error: NSError?) -> Void )
/// Get a subset of the items at the specified path (book_id/sheet_name)
///
/// - parameters:
/// - query: query path of the form "<book_id>/<sheet_name>"
/// - limit: the max number of items to be returned
/// - offset: the number of items to skip, for paging
/// - filters: key/value pairs to filter the results by, of the form "name=amy". Case-sensitive.
/// - include: comma-separated string of fields that should be included in the returned items. Set to nil to get everything
/// - exclude: comma-separated string of fields that should be excluded in the returned items. Set to nil to get everything
/// - completion: block called upon completion of the query, with either an array of items or an error and a flag specifying whethere there are more items that can be requested
public static func getItems( query: String, limit: UInt, offset: UInt, filters: NSArray?, include: String?, exclude: String?, completion: (items: NSArray?, more: Bool, error: NSError?) -> Void )
/// Get a single item with the specified path (book_id/sheet_name) and id
///
/// - parameters:
/// - query: query path of the form "<book_id>/<sheet_name>"
/// - id: the id number of the item to return
/// - completion: block called upon completion of the query, with either the item or an error
public static func getItem( query: String, id: NSNumber, completion: (item: NSDictionary?, error: NSError?) -> Void )
/// Get a single item with the specified path (book_id/sheet_name) and id
///
/// - parameters:
/// - query: query path of the form "<book_id>/<sheet_name>"
/// - id: the id number of the item to return
/// - include: comma-separated string of fields of the item that should be included. Set to nil to get everything
/// - exclude: comma-separated string of fields of the item that should be excluded. Set to nil to get everything
/// - completion: block called upon completion of the query, with either the item or an error
public static func getItem( query: String, id: NSNumber, include: NSString?, exclude: NSString?, completion: (item: NSDictionary?, error: NSError?) -> Void )
/// Add a single item to the specified path (book_id/sheet_name)
/// Do not include an 'id' field in the item as Fieldbook will generate that itself (your sheet should NOT have an 'id' column as it will cause a clash)
///
/// - parameters:
/// - query: query path of the form "<book_id>/<sheet_name>"
/// - item: the fields of the item to be added
/// - completion: block called upon completion of the query, with either the newly added item or an error
public static func addToList( query: String, item: NSDictionary, completion: (item: NSDictionary?, error: NSError?) -> Void )
/// Update an item at the specified path (book_id/sheet_name)
///
/// - parameters:
/// - query: query path of the form "<book_id>/<sheet_name>"
/// - id: the id number of the item to be updated
/// - item: the fields of the item to be updated (don't need to include fileds that don't need to change)
/// - completion: block called upon completion of the query, with either the newly updated item or an error
public static func updateItem( query: String, id: NSNumber, item: NSDictionary, completion: (item: NSDictionary?, error: NSError?) -> Void )
/// Delete an item from the specified path (book_id/sheet_name)
///
/// - parameters:
/// - query: query path of the form "<book_id>/<sheet_name>"
/// - id: the id number of the item to be deleted
/// - completion: block called upon completion of the query, with either nil or an error
public static func deleteItem( query: String, id: NSNumber, completion: (error: NSError?) -> Void )
有关 API 的更多详细信息,您可以在 GitHub 上找到一些文档 GitHub。
Fieldbook-SwiftSDK 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "Fieldbook-SwiftSDK"
当然,您也可以仅仅将 Fieldbook_SwiftSDK.swift 文件复制到您自己的项目中,并在不熟悉 CocoaPods 的情况下引用其方法(尽管我强烈建议您尝试一下!)
与 Webhooks 相关的 API 方法尚未包含在内,否则当前 API 已经完全实现(至少截至 2016 年 2 月)。
Chris Mash,[email protected],@cjmash
Fieldbook-SwiftSDK 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。