2022-09-08 21:40:48 +02:00
|
|
|
import Constants from "../Models/Constants"
|
2022-07-13 10:03:09 +02:00
|
|
|
|
|
|
|
export default class Maproulette {
|
2022-09-08 21:40:48 +02:00
|
|
|
/**
|
|
|
|
* The API endpoint to use
|
|
|
|
*/
|
|
|
|
endpoint: string
|
2022-07-13 10:03:09 +02:00
|
|
|
|
2022-09-08 21:40:48 +02:00
|
|
|
/**
|
|
|
|
* The API key to use for all requests
|
|
|
|
*/
|
|
|
|
private apiKey: string
|
2022-07-13 10:03:09 +02:00
|
|
|
|
2022-09-08 21:40:48 +02:00
|
|
|
/**
|
|
|
|
* Creates a new Maproulette instance
|
|
|
|
* @param endpoint The API endpoint to use
|
|
|
|
*/
|
|
|
|
constructor(endpoint: string = "https://maproulette.org/api/v2") {
|
|
|
|
this.endpoint = endpoint
|
|
|
|
this.apiKey = Constants.MaprouletteApiKey
|
|
|
|
}
|
2022-07-13 10:03:09 +02:00
|
|
|
|
2022-09-08 21:40:48 +02:00
|
|
|
/**
|
|
|
|
* Close a task
|
|
|
|
* @param taskId The task to close
|
|
|
|
*/
|
|
|
|
async closeTask(taskId: number): Promise<void> {
|
|
|
|
const response = await fetch(`${this.endpoint}/task/${taskId}/1`, {
|
|
|
|
method: "PUT",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
apiKey: this.apiKey,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if (response.status !== 304) {
|
|
|
|
console.log(`Failed to close task: ${response.status}`)
|
|
|
|
}
|
2022-07-13 10:03:09 +02:00
|
|
|
}
|
|
|
|
}
|