28 lines
884 B
Forth
28 lines
884 B
Forth
namespace PureGym
|
|
|
|
open System
|
|
open System.Net.Http
|
|
open System.Threading.Tasks
|
|
|
|
/// Methods for interacting with the PureGym REST API.
|
|
[<RequireQualifiedAccess>]
|
|
module Api =
|
|
/// Create a REST client, authenticated as the specified user.
|
|
let make (auth : Auth) : IPureGymApi Task =
|
|
task {
|
|
let! token =
|
|
match auth with
|
|
| Auth.Token t -> Task.FromResult<_> t
|
|
| Auth.User cred -> AuthToken.get cred
|
|
|
|
let client = new HttpClient ()
|
|
client.BaseAddress <- Uri "https://capi.puregym.com/api"
|
|
|
|
client.DefaultRequestHeaders.Authorization <-
|
|
Headers.AuthenticationHeaderValue ("Bearer", token.AccessToken)
|
|
|
|
client.DefaultRequestHeaders.Add ("User-Agent", "PureGym/1523 CFNetwork/1312 Darwin/21.0.0")
|
|
|
|
return PureGymApi.make client
|
|
}
|