Objective-C的 GitHub API 客户端

jopen 8年前

octokit.objc 是 Objective-CGitHub API 客户端。

OctoKit 是  Cocoa and Cocoa Touch 框架,用来与 GitHub API, 进行交互,可使用 AFNetworking,Mantle 和 ReactiveCocoa

发出请求:

为了与API进行交互,您必须实例化一个 OCTClient. 这里有两种可创建无需验证客户端的方法。

  1. -initWithServer:这是实例化一个客户端的最基本的方法. 它可以接收一个 OCTServer, 用来判断是否要连接到 GitHub.com 或者GitHub Enterprise 接口。

  2. +unauthenticatedClientWithUser:这种方法和上面的相似, 但是它允许你设置一个 active 用户, 这需要有特定的请求。

采用第二种方法,我们可以获得更多操作。创建一个连接到 GitHub.com 的客户端。

OCTUser *user = [OCTUser userWithRawLogin:username server:OCTServer.dotComServer];  OCTClient *client = [OCTClient unauthenticatedClientWithUser:user];

获得客户端后,我们便可以开始抓取数据。在OCTClient 的每个请求方法会返回一个ReactiveCocoa信号这类似于一个future or promise

// Prepares a request that will load all of the user's repositories, represented  // by `OCTRepository` objects.  // Note that the request is not actually _sent_ until you use one of the  // -subscribe… methods below.  RACSignal *request = [client fetchUserRepositories];

官方网站:http://www.open-open.com/lib/view/home/1452311323995