Add all-gyms (#11)
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful

Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk>
Reviewed-on: #11
This commit is contained in:
2024-02-12 22:08:02 +00:00
parent f182c6ebad
commit 419f27053f
7 changed files with 81 additions and 71 deletions

53
PureGym.App/AllGyms.fs Normal file
View File

@@ -0,0 +1,53 @@
namespace PureGym.App
open System.Threading
open Argu
open PureGym
type AllGymsArgsFragment =
| [<Unique ; EqualsAssignmentOrSpaced>] Terse of bool
interface IArgParserTemplate with
member s.Usage =
match s with
| Terse _ -> "print only 'id,gym-name'"
type AllGymsArgs =
{
Creds : Auth
Terse : bool
}
static member Parse
(auth : Auth)
(args : AllGymsArgsFragment ParseResults)
: Result<AllGymsArgs, ArguParseException>
=
let terse =
match args.TryGetResult AllGymsArgsFragment.Terse with
| None -> false
| Some x -> x
{
Creds = auth
Terse = terse
}
|> Ok
[<RequireQualifiedAccess>]
module AllGyms =
let run (args : AllGymsArgs) =
task {
let! client = Api.makeWithoutRefresh CancellationToken.None args.Creds
let! s = client.GetGyms ()
if args.Terse then
for gym in s do
System.Console.WriteLine $"%i{gym.Id},%s{gym.Name}"
else
for gym in s do
System.Console.WriteLine (string<Gym> gym)
return 0
}

View File

@@ -16,6 +16,10 @@ module Program =
("Get information about the physical instantiation of a gym",
RequiresAuth (fun auth -> ArgsCrate.make (LookupGymArgs.Parse auth) LookupGym.run))
"all-gyms",
("List information about all gyms",
RequiresAuth (fun auth -> ArgsCrate.make (AllGymsArgs.Parse auth) AllGyms.run))
"fullness",
("Determine how full a gym is",
RequiresAuth (fun auth -> ArgsCrate.make (FullnessArgs.Parse auth) Fullness.run))

View File

@@ -13,6 +13,7 @@
<Compile Include="Authenticate.fs" />
<Compile Include="Fullness.fs" />
<Compile Include="LookupGym.fs" />
<Compile Include="AllGyms.fs" />
<Compile Include="MemberActivity.fs" />
<Compile Include="Sessions.fs" />
<Compile Include="Program.fs" />

View File

@@ -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

View File

@@ -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

View File

@@ -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>

View File

@@ -21,16 +21,6 @@
version = "3.2.0";
sha256 = "1qxpv8v10p5wn162lzdm193gdl6c5f81zadj8h889dprlnj3g8yr";
})
(fetchNuGet {
pname = "Fantomas.Core";
version = "6.1.1";
sha256 = "1h2wsiy4fzwsg9vrlpk6w7zsvx6bc4wg4x25zqc48akg04fwpi0m";
})
(fetchNuGet {
pname = "Fantomas.FCS";
version = "6.1.1";
sha256 = "0733dm5zjdp8w5wwalqlv1q52pghfr04863i9wy807f4qfd7rrin";
})
(fetchNuGet {
pname = "Fastenshtein";
version = "1.0.0.8";
@@ -226,21 +216,11 @@
version = "1.1.0";
sha256 = "08vh1r12g6ykjygq5d3vq09zylgb84l63k49jc4v8faw9g93iqqm";
})
(fetchNuGet {
pname = "Microsoft.NETCore.Platforms";
version = "1.1.1";
sha256 = "164wycgng4mi9zqi2pnsf1pq6gccbqvw6ib916mqizgjmd8f44pj";
})
(fetchNuGet {
pname = "Microsoft.NETCore.Platforms";
version = "2.0.0";
sha256 = "1fk2fk2639i7nzy58m9dvpdnzql4vb8yl8vr19r2fp8lmj9w2jr0";
})
(fetchNuGet {
pname = "Microsoft.NETCore.Targets";
version = "1.1.3";
sha256 = "05smkcyxir59rgrmp7d6327vvrlacdgldfxhmyr1azclvga1zfsq";
})
(fetchNuGet {
pname = "Microsoft.TestPlatform.ObjectModel";
version = "17.6.0";
@@ -251,11 +231,6 @@
version = "17.6.0";
sha256 = "16vpicp4q2kbpgr3qwpsxg7srabxqszx23x6smjvvrvz7qmr5v8i";
})
(fetchNuGet {
pname = "Myriad.Core";
version = "0.8.3";
sha256 = "0s5pdckjw4x0qrbd4i3cz9iili5cppg5qnjbr7zjbbhhmxzb24xw";
})
(fetchNuGet {
pname = "Myriad.Sdk";
version = "0.8.3";
@@ -326,31 +301,11 @@
version = "1.6.4";
sha256 = "1mvi3nbrr450g3fgd1y4wg3bwl9k1agyjfd9wdkqk12714bsln8l";
})
(fetchNuGet {
pname = "runtime.any.System.Runtime";
version = "4.3.0";
sha256 = "1cqh1sv3h5j7ixyb7axxbdkqx6cxy00p4np4j91kpm492rf4s25b";
})
(fetchNuGet {
pname = "runtime.native.System";
version = "4.3.0";
sha256 = "15hgf6zaq9b8br2wi1i3x0zvmk410nlmsmva9p0bbg73v6hml5k4";
})
(fetchNuGet {
pname = "runtime.unix.System.Private.Uri";
version = "4.3.0";
sha256 = "1jx02q6kiwlvfksq1q9qr17fj78y5v6mwsszav4qcz9z25d5g6vk";
})
(fetchNuGet {
pname = "System.Configuration.ConfigurationManager";
version = "4.4.0";
sha256 = "1hjgmz47v5229cbzd2pwz2h0dkq78lb2wp9grx8qr72pb5i0dk7v";
})
(fetchNuGet {
pname = "System.Diagnostics.DiagnosticSource";
version = "7.0.0";
sha256 = "1jxhvsh5mzdf0sgb4dfmbys1b12ylyr5pcfyj1map354fiq3qsgm";
})
(fetchNuGet {
pname = "System.Formats.Asn1";
version = "5.0.0";
@@ -366,26 +321,11 @@
version = "4.5.0";
sha256 = "1gq4s8w7ds1sp8f9wqzf8nrzal40q5cd2w4pkf4fscrl2ih3hkkj";
})
(fetchNuGet {
pname = "System.Memory";
version = "4.5.5";
sha256 = "08jsfwimcarfzrhlyvjjid61j02irx6xsklf32rv57x2aaikvx0h";
})
(fetchNuGet {
pname = "System.Private.Uri";
version = "4.3.0";
sha256 = "04r1lkdnsznin0fj4ya1zikxiqr0h6r6a1ww2dsm60gqhdrf0mvx";
})
(fetchNuGet {
pname = "System.Reflection.Metadata";
version = "1.6.0";
sha256 = "1wdbavrrkajy7qbdblpbpbalbdl48q3h34cchz24gvdgyrlf15r4";
})
(fetchNuGet {
pname = "System.Runtime";
version = "4.3.1";
sha256 = "03ch4d2acf6q037a4njxpll2kkx3dwzlg07yxr4z5m6j1kqgmm27";
})
(fetchNuGet {
pname = "System.Runtime.CompilerServices.Unsafe";
version = "6.0.0";
@@ -438,7 +378,12 @@
})
(fetchNuGet {
pname = "WoofWare.Myriad.Plugins";
version = "1.4.8";
sha256 = "sha256-HdqiXz4pSQ+pPkj82RsWR7zn3JePQm5/IFl4dlR2O5Y=";
version = "2.0.5";
sha256 = "09r52lr11y4b5l6h6c270gl61asn39bnk4xbqvbw3cshfksg8q6s";
})
(fetchNuGet {
pname = "WoofWare.Myriad.Plugins.Attributes";
version = "2.0.5";
sha256 = "15mv2cy77fl1zc1mq2bfj326ys54490iwzm7lkjlnz5aazs32dq0";
})
]