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 接收到访问令牌,则可以使用 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 接收到访问令牌,则可以按以下方式使用它
let authentication = TokenAuthentication(token: "token")
UserAPI(authentication: authentication).getAllUsers(since: "1") { (reposne, error) in
if let response = response {
print(response)
} else {
print(error ?? "")
}
}
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 ?? "")
}
}
RepositoriesAPI(authentication: AccessTokenAuthentication(access_token: "access_token")).repositories(user: "user", type: .all) { (response, error) in
if let response = response {
} else {
print(error ?? "")
}
}
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 文件。