CoursesClient

class CoursesClient(val cs: <Error class: unknown class>)

A utility class with methods for getting resources from a remote. For most use cases, the CoursesClient.fetch methods are sufficient. The CoursesClient.fetchAndMap and CoursesClient.fetchAndConsume methods can be used when direct access to the input stream of the response is needed.

Constructors

Link copied to clipboard
constructor(cs: <Error class: unknown class>)

Types

Link copied to clipboard
fun interface HttpAuthentication

A functional interface for adding authentication to an HTTP request.

Link copied to clipboard
fun interface ResponseConsumer

A functional interface for functions that consume a HttpResponse and use it for side-effects.

Link copied to clipboard
fun interface ResponseMapper<T>

A functional interface for functions that map a HttpResponse to a desired result. // * See EntityUtils for useful methods for working with HttpEntity instances.

Properties

Link copied to clipboard
var client: <Error class: unknown class>
Link copied to clipboard
val cs: <Error class: unknown class>

Functions

Link copied to clipboard
suspend fun fetch(url: URL): ByteArrayInputStream

Makes a GET request to the given URL and returns the response body in a ByteArrayInputStream.

suspend fun fetch(url: URL, file: File)

Downloads a file from the given URL into the given file.

Link copied to clipboard

Makes a GET request to the given URL and consumes the response.

Link copied to clipboard
suspend fun <T> fetchAndMap(url: URL, mapper: CoursesClient.ResponseMapper<T>): T

Makes a GET request to the given URL and returns the mapped response.

Link copied to clipboard
suspend fun get(url: String): <Error class: unknown class>
Link copied to clipboard
inline suspend fun <Resource : Any, Body : Any> getBody(resource: Resource): Body
inline suspend fun <Body : Any> getBody(url: String, snake: Boolean): Body
Link copied to clipboard
suspend fun getFileSize(url: URL): Long?
Link copied to clipboard
fun json(snake: Boolean = true): <Error class: unknown class>
Link copied to clipboard
suspend fun <T> post(url: URL, data: Map<String, Any>?, mapper: CoursesClient.ResponseMapper<T>): T?

Sends a POST request to the given URL and returns the value created by the mapper.

Link copied to clipboard
fun requireSuccessStatusCode(response: <Error class: unknown class>)

Throws a UnexpectedResponseException if the response status code isn't 2xx. If the response body includes JSON with an array for the key "errors" or a string for the key "detail", then those messages are included in the exception message.

Link copied to clipboard