GitHubAPI
GitHub REST api v3的Swift实现。库支持Swift 4.2。工作正在进行中。
当前支持
- 问题API.
- 活动API(动态、通知).
- 仓库API.
- 搜索API.
- 用户API.
待办事项
- 活动API(事件、收藏、观看).
- 组织API.
- 项目API.
- Pull Requests API.
- 反应API.
- 仓库API.
- 用户API(电子邮件、关注者、公钥、GPG密钥、阻止其他用户).
- 文档。
示例用法
身份验证
基本身份验证
此库支持使用用户名和密码进行基本身份验证。
let authentication = BasicAuthentication(username: "username", password: "password")
UserAPI(authentication: authentication).getUser { (response, error) in
if let response = response {
print(response)
} else {
print(error ?? "")
}
}
OAuth2 令牌(在头部发送)
如果您生成了个人访问令牌或从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 令牌(作为参数发送)
如果您生成了个人访问令牌或从OAuth2接收访问令牌,可以按照以下方式使用它。
let authentication = TokenAuthentication(token: "token")
UserAPI(authentication: authentication).getAllUsers(since: "1") { (reposne, error) in
if let response = response {
print(response)
} else {
print(error ?? "")
}
}
问题 API
创建问题
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 ?? "")
}
}
更新问题
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 ?? "")
}
}
仓储 API
获取用户所有仓库列表
RepositoriesAPI(authentication: AccessTokenAuthentication(access_token: "access_token")).repositories(user: "user", type: .all) { (response, error) in
if let response = response {
} else {
print(error ?? "")
}
}
搜索API
搜索包含“qwer”名称的所有仓库
SearchAPI().searchRepositories(q: "qwer", page: 1, per_page: 100) { (response, error) in
if let response = response {
} else {
print(error ?? "")
}
}
示例应用
要运行示例项目,请先Clone仓库,然后从示例目录运行 pod install
。
示例项目包含包含所有用户GitHub通知列表的示例应用。
需求
- Xcode 9或更高版本
- iOS 9.0或更高版本
- macOS 10.12或更高版本
- Ubuntu 16.04或更高版本
- Swift 4.0或更高版本
安装
GitHubAPI通过CocoaPods提供。要安装,只需将以下行添加到您的Podfile中。
pod 'GithubAPI'
作者
Serhii Londar, [email protected]
许可
GitHub API 在 MIT 许可下可用。更多信息请参见 LICENSE 文件。