ArcGISKit
Under Construction! DO NOT USE!
A Swift library for the ArcGIS REST API.
Documentation comments are taken from the ArcGIS REST API.
View the documentation on Github Pages.
Table of Contents
Created by gh-md-toc
Under Construction! DO NOT READ!
Install
Swift Package Manager
Add this to the dependencies
array in Package.swift
:
.package(url: "https://github.com/LebJe/ArcGISKit", from: "1.0.0")
And add this to the targets
array in the aforementioned file:
.product(name: "ArcGISKit", package: "ArcGISKit")
Usage
You first need to get a GIS
:
import ArcGISKit
import NIO
// Setup a group for the `HTTPClient`.
let group = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
// Login using a username and password.
let authenticatedGIS = GIS(
authType: .credentials(username: "username", password: "password"),
eventLoopGroup: group,
url: URL(string: "https://my-organization.maps.arcgis.com")!
)
// Login anonymously.
// There is no user available since we logged in anonymously.
let anonymousGIS = GIS(authType: .anonymous, eventLoopGroup: group)
// Login using a client ID and client secret.
let idAndSecretGIS = GIS(
authType: .idAndSecret(clientID: "id", clientSecret: "secret", username: "username"),
eventLoopGroup: group,
url: URL(string: "https://my-organization.maps.arcgis.com")!
)
Vapor
If you are using Vapor, initialize your GIS
like this:
func routes(_ app: Application) throws {
// Initialize your GIS` using `app.eventLoopGroup`.
let gis = GIS(..., eventLoopGroup: app.eventLoopGroup, ...)
...
}
Once you have a GIS
you can fetch a User
:
var gis: GIS = ...
if !gis.isAnonymous {
// Fetch synchronously.
let user = try gis.fetchUser().wait()
// Fetch asynchronously.
try gis.fetchUser().whenComplete({ res in
switch res {
case .failure(let error):
// something went wrong...
break
case .success(let user):
// Use `user` here.
print(user)
}
})
}
Contributing
Before committing, please install pre-commit, and swift-format and install the pre-commit hook:
$ brew bundle # install the packages specified in Brewfile
$ pre-commit install
# Commit your changes.
To install pre-commit on other platforms, refer to the documentation.