LebJe / ArcGISKit

A Swift library for the ArcGIS REST API.

Home Page:https://lebje.github.io/ArcGISKit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ArcGISKit

Under Construction! DO NOT USE!

A Swift library for the ArcGIS REST API.

Swift 5.3 SPM Compatible https://img.shields.io/badge/Platforms-MacOS%20%7C%20Linux-lightgrey Build and Test

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.

About

A Swift library for the ArcGIS REST API.

https://lebje.github.io/ArcGISKit/


Languages

Language:Swift 99.8%Language:Shell 0.2%Language:Ruby 0.1%