Add all-gyms (#11)
Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk> Reviewed-on: #11
This commit is contained in:
@@ -23,21 +23,23 @@ module Api =
|
||||
let cache = new Cache<_> (AuthToken.get cred, _.ExpiryTime)
|
||||
cache :> _, (fun () -> Async.RunSynchronously (cache.GetCurrentValue ()))
|
||||
|
||||
task {
|
||||
async {
|
||||
let client = new HttpClient ()
|
||||
|
||||
return PureGymApi.make (getToken >> _.AccessToken >> sprintf "Bearer %s") client, cache
|
||||
}
|
||||
|> Async.StartAsTask
|
||||
|
||||
/// Create a REST client, authenticated as the specified user. Do not refresh creds.
|
||||
let makeWithoutRefresh (ct : CancellationToken) (auth : Auth) : IPureGymApi Task =
|
||||
task {
|
||||
async {
|
||||
let! token =
|
||||
match auth with
|
||||
| Auth.Token t -> Task.FromResult<_> t
|
||||
| Auth.User cred -> AuthToken.get cred ct
|
||||
| Auth.Token t -> async.Return t
|
||||
| Auth.User cred -> Async.AwaitTask (AuthToken.get cred ct)
|
||||
|
||||
let client = new HttpClient ()
|
||||
|
||||
return PureGymApi.make (fun () -> $"Bearer %s{token.AccessToken}") client
|
||||
}
|
||||
|> Async.StartAsTask
|
||||
|
@@ -21,14 +21,17 @@ module GymSelector =
|
||||
let canonicalId (client : IPureGymApi) (gym : GymSelector) : int Task =
|
||||
match gym with
|
||||
| GymSelector.Home ->
|
||||
task {
|
||||
let! self = client.GetMember ()
|
||||
async {
|
||||
let! ct = Async.CancellationToken
|
||||
let! self = Async.AwaitTask (client.GetMember ct)
|
||||
return self.HomeGymId
|
||||
}
|
||||
|> Async.StartAsTask
|
||||
| GymSelector.Id i -> Task.FromResult<_> i
|
||||
| GymSelector.Name name ->
|
||||
task {
|
||||
let! allGyms = client.GetGyms ()
|
||||
async {
|
||||
let! ct = Async.CancellationToken
|
||||
let! allGyms = Async.AwaitTask (client.GetGyms ct)
|
||||
|
||||
if allGyms.IsEmpty then
|
||||
return failwith "PureGym API returned no gyms!"
|
||||
@@ -46,3 +49,4 @@ module GymSelector =
|
||||
|
||||
return bestGym.Id
|
||||
}
|
||||
|> Async.StartAsTask
|
||||
|
@@ -6,7 +6,7 @@
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<WarnOn>FS3559</WarnOn>
|
||||
|
||||
<WoofWareMyriadPluginVersion>1.4.8</WoofWareMyriadPluginVersion>
|
||||
<WoofWareMyriadPluginVersion>2.0.5</WoofWareMyriadPluginVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -38,6 +38,7 @@
|
||||
<PackageReference Include="Fastenshtein" Version="1.0.0.8" />
|
||||
<PackageReference Include="Myriad.Sdk" Version="0.8.3" PrivateAssets="all" />
|
||||
<PackageReference Include="WoofWare.Myriad.Plugins" Version="$(WoofWareMyriadPluginVersion)" />
|
||||
<PackageReference Include="WoofWare.Myriad.Plugins.Attributes" Version="$(WoofWareMyriadPluginVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Reference in New Issue
Block a user