RxGitLabKit 1.0.1

RxGitLabKit 1.0.1

Dagy Tran 维护。



 
依赖项
RxSwift~> 4.0
RxCocoa~> 4.0
 

  • 作者
  • Dagy Tran

RxGitLabKit

Build Status Platform pod Carthage Swift Package Manager

描述

使用 RxSwift 的 Swift 反应式 GitLab API v4 客户端

此库目前支持以下端点组

使用 Jazzy 生成的 HTML 文档可以在 GitHub 页面上找到,链接在此

在运行演示应用程序或测试之前,使用以下方式下载依赖关系

$ carthage update

用法

授权

使用私有/OAuth令牌或通过输入 usernamepassword 来登录

import RxGitLabKit

// Host URL
let hostURL = URL(string: "http://example.gitlab.server.com")!
// Using private token
let client = RxGitLabAPIClient(with: hostURL, privateToken: "PRIVATE_TOKEN")

// Using an OAuth token
let client = RxGitLabAPIClient(with: hostURL, oAuthToken: "OAUTH_TOKEN")

// Authorize using username and password
let client = RxGitLabAPIClient(with: hostURL)
client.logIn(username: "USERNAME", password: "PASSWORD")

基本用法

import RxGitLabKit

let hostURL = URL(string: "http://example.gitlab.server.com")!

let client = RxGitLabAPIClient(with: hostURL, privateToken: "PRIVATE_TOKEN")

// Get projects
let projects: Observable<[Project]> = client.users
  .getProjects(parameters: ["order_by" : "id", "sort" : "asc"],
    page: 2,
    perPage: 20)
projects.subscribe(onNext: { projects in
    // do something with projects
  },
  onError: { error in
    // Do something with the error
  }
)

分页器

某些端点返回一个 分页器,用于处理对象的分页。分页器使用下标来加载所需的页面。

import RxGitLabKit

// Get the paginator
let projectsPaginator: Paginator<Project> = client.users
  .getProjects(parameters: ["order_by" : "id", "sort" : "asc"])

// Load page 2
projectsPaginator[2].subscribe(onNext: { projects in
    // do something with projects
  },
  onError: { error in
    // Do something with the error
  }
)

// Load page 2 to 5
projectsPaginator[2...5].subscribe(onNext: { projects in
    // do something with projects
  },
  onError: { error in
    // Do something with the error
  }
)

// Load all pages
projectsPaginator.loadAll().subscribe(onNext: { projects in
    // do something with projects
  },
  onError: { error in
    // Do something with the error
  }
)

要求

  • Xcode 10.0
  • Swift 4.2

集成

CocoaPods

使用 pod --version 测试: 1.5.3

# Podfile
use_frameworks!

target 'YOUR_TARGET_NAME' do
  pod 'RxGitLabKit'
end
\end{minted}

替换 YOUR_TARGET_NAME 然后运行这个命令

$ pod install

Carthage

使用 carthage version 测试: 0.31.2

添加到 Cartfile

  git "https://github.com/Qase/RxGitLabKit.git"

然后运行

$ carthage update

然后将其构建的 RxGitLabKit.framework 链接到目标的“已链接框架和库”部分。

Swift 坚果包管理器

使用 swift build --version 测试: Apple Swift 坚果包管理器 - Swift 4.2.0 (swiftpm-14460.2)

创建一个 Package.swift 文件。

// swift-tools-version:4.2
import PackageDescription

let package = Package(
  name: "YOUR_PROJECT_NAME",
  dependencies: [
    .package(url: "https://github.com/Qase/RxGitLabKit.git", from: "1.0.0")
  ],
  targets: [
    .target(name: "YOUR_PROJECT_NAME", dependencies: ["RxGitLabKit"], path: "SOURCE_PATH")
  ]
)

替换 YOUR_PROJECT_NAMESOURCE_PATH 并运行

$ swift build

然后

$ swift package generate-xcodeproj

许可

MIT