GitHub API

CI Status Version License Platform

GitHub REST api v3 的 Swift 实现。 该库支持 Swift 4.2。 工作正在进行中。

目前支持

待办事项

使用示例

身份验证

基本身份验证

此库支持使用登录名/密码进行基本身份验证

let authentication = BasicAuthentication(username: "username", password: "password")
UserAPI(authentication: authentication).getUser { (response, error) in
	if let response = response {
		print(response)
	} else {
		print(error ?? "")
	}
}

OAuth2 Token (在标头中发送)

如果您生成了个人访问令牌或从 OAuth2 接收到访问令牌,则可以使用 AccessTokenAuthentication 来使用它

let authentication = AccessTokenAuthentication(access_token: "token")
UserAPI(authentication: authentication).getUser(username: "serhii-londar") { (response, error) in
	if let response = response {
		print(response)
	} else {
		print(error ?? "")
	}
}

OAuth2 Token (作为参数发送)

如果您生成了个人访问令牌或从 OAuth2 接收到访问令牌,则可以按以下方式使用它

let authentication = TokenAuthentication(token: "token")
UserAPI(authentication: authentication).getAllUsers(since: "1") { (reposne, error) in
	if let response = response {
		print(response)
	} else {
		print(error ?? "")
	}
}

Issues API (议题 API)

创建 Issue (创建议题)

let issue = Issue(title: "New Issue")
IssuesAPI(authentication: AccessTokenAuthentication(access_token: "access_token")).createIssue(owner: "owner", repository: "repository", issue: issue) { (response, error) in
	if let response = response {

	} else {
		print(error ?? "")
	}
}

更新 Issue (更新议题)

let issue = Issue(title: "Updated Issue")
        IssuesAPI(authentication: AccessTokenAuthentication(access_token: "access_token")).updateIssue(owner: "owner", repository: "repository", number: number, issue: issue) { (response, error) in
	if let response = response {

	} else {
		print(error ?? "")
	}
}

Repositories API (仓库 API)

获取用户的所有仓库列表

RepositoriesAPI(authentication: AccessTokenAuthentication(access_token: "access_token")).repositories(user: "user", type: .all) { (response, error) in
	if let response = response {

	} else {
		print(error ?? "")
	}
}

Search API (搜索 API)

搜索名称中包含 qwer 的所有仓库

SearchAPI().searchRepositories(q: "qwer", page: 1, per_page: 100) { (response, error) in
	if let response = response {

	} else {
		print(error ?? "")
	}
}

示例应用程序

要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install

示例项目包含一个示例应用程序,其中包含所有用户 GitHub 通知的列表。

要求

安装

GitHubAPI 可通过 CocoaPods 获得。 要安装它,只需将以下行添加到您的 Podfile 中

pod 'GithubAPI'

作者

Serhii Londar, serhii.londar@gmail.com

许可证

GitHubAPI 在 MIT 许可证下可用。 有关更多信息,请参见 LICENSE 文件。