FatSecretKit 0.0.3

FatSecretKit 0.0.3

测试已测试
语言语言 Obj-CObjective C
许可证 BSD
发布上次发布2016年3月

Adam KirkParker Wightman维护。



  • Parker Wightman

FatSecret API的iOS客户端。

安装

通过CocoaPods安装,在您的Podfile中添加以下内容

pod 'FatSecretKit'

然后根据需要导入

#import <FatSecretKit/FSClient.h>

用法

创建自己的客户端中最困难的部分是OAuth协商,因此这应该能节省您宝贵的时间。您需要的只是您的OAuth消费者密钥和密钥。推荐使用sharedClient

[FSClient sharedClient].oauthConsumerKey = @"12345";
[FSClient sharedClient].oauthConsumerSecret = @"67890";

您应该将其放入AppDelegate.m或类似的文件中,这样它只会运行一次。您始终可以使用[[FSClient alloc] init]创建自己的客户端。

现在您可以开始使用API了。

食物搜索

[[FSClient sharedClient] searchFoods:term
                          completion:^(NSArray *foods, NSInteger maxResults, NSInteger totalResults, NSInteger pageNumber) {
    // Use data as you will.
    self.foods = foods;
    [self.tableView reloadData];
}];

// A more verbose version of the above, if you want to utilize the full paramters of the API
[[FSClient sharedClient] searchFoods:term
                          pageNumber:0
                          maxResults:50
                          completion:^(NSArray *foods, NSInteger maxResults, NSInteger totalResults, NSInteger pageNumber) {
    // Use data as you will.
    self.foods = foods;
    [self.tableView reloadData];
}];

获取食物

[[FSClient sharedClient] getFood:item.identifier
                      completion:^(FSFood *food) {
                          NSLog(@"Name: %@", food.name)
                      }];

还有一个本地对象表示API返回的资源,包括FSFood,表示食物资源,以及FSServing,它表示每种食物的分量,由food.get API方法(以及其他方法)返回。

限制(和待办事项列表)

  • 仅支持非特定于用户请求。换句话说,它目前不支持受委托请求
  • 并非所有API方法都已实现,仅实现Mysterious Trousers需要的几个特定方法。添加对其他API的支持是受欢迎的,并且应该相对简单。参见贡献部分。

贡献

应将用于获取资源的新方法添加到FSClient类中,并在必要时创建新的本地对象。客户端方法的命名约定应遵循相同的约定

API: foods.search,iOS: searchFoods

API: food.get,iOS: getFood

等等。

本地对象上新的方法/属性应遵循类似的约定

API: trans_fat,iOS: transFat

API: saturated_fat,iOS: saturatedFat

等等。

为支持新的API方法,需要在FSClient中创建一个适当命名的函数,并且应该支持所有必要和可选参数,尽管方便的函数也很受欢迎(可参考searchFoods方法。)您始终可以通过Twitter或通过问题(issues)提出疑问,我们都是好人。

过程

  1. 分支出来
  2. 创建您的功能分支(git checkout -b my-new-feature
  3. 提交您的更改(git commit -am '添加了一些功能'
  4. 将更改推送到分支(git push origin my-new-feature
  5. 创建新的拉取请求

贡献者

Parker Wightman (@parkerwightman)

致谢

感谢atebits提供的OAuthCore库,使这项任务简化了很多。也感谢Sam Vermette提供的出色的SVHTTPRequest库。