Swift Reactive GitLab API v4 client using RxSwift
This library currently supports these endpoint groups:
The HTML documentation generated using Jazzy can be found on GitHub pages here.
Before running the demo app or the tests, download the dependencies using:
$ carthage update
Using a private/ OAuth token or login using username
and password
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
}
)
Some endpoints return a Paginator
which handles the pagination of the objects. The paginator uses subscripts for loading the desired pages.
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
Tested with pod --version
: 1.5.3
# Podfile
use_frameworks!
target 'YOUR_TARGET_NAME' do
pod 'RxGitLabKit'
end
\end{minted}
Replace YOUR_TARGET_NAME
and then run this command:
$ pod install
Tested with carthage version
: 0.31.2
Add this to Cartfile
git "https://github.com/Qase/RxGitLabKit.git"
and run:
$ carthage update
Then link the built RxGitLabKit.framework
it the "Linked Frameworks and Libraries" section of the target.
Tested with swift build --version
: Apple Swift Package Manager - Swift 4.2.0 (swiftpm-14460.2)
Create a Package.swift
file.
// 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")
]
)
replace YOUR_PROJECT_NAME
and SOURCE_PATH
and run
$ swift build
and then
$ swift package generate-xcodeproj