From 9a182b34a077c3bcd93af0b05ac8264e2a316ed7 Mon Sep 17 00:00:00 2001 From: Smaug123 Date: Fri, 29 Dec 2023 12:02:39 +0000 Subject: [PATCH 1/2] Bump source gen --- PureGym/GeneratedClient.fs | 68 ++-- PureGym/GeneratedDto.fs | 709 ++++++++++++++++++++++++++++++++++--- PureGym/PureGym.fsproj | 4 +- 3 files changed, 700 insertions(+), 81 deletions(-) diff --git a/PureGym/GeneratedClient.fs b/PureGym/GeneratedClient.fs index 4eb0939..307f846 100644 --- a/PureGym/GeneratedClient.fs +++ b/PureGym/GeneratedClient.fs @@ -23,10 +23,13 @@ module PureGymApi = async { let! ct = Async.CancellationToken + let uri = + System.Uri (client.BaseAddress, System.Uri ("v1/gyms/", System.UriKind.Relative)) + let httpMessage = new System.Net.Http.HttpRequestMessage ( Method = System.Net.Http.HttpMethod.Get, - RequestUri = System.Uri (client.BaseAddress.ToString () + "/v1/gyms/") + RequestUri = uri ) let! response = client.SendAsync (httpMessage, ct) |> Async.AwaitTask @@ -45,10 +48,13 @@ module PureGymApi = async { let! ct = Async.CancellationToken + let uri = + System.Uri (client.BaseAddress, System.Uri ("v1/member", System.UriKind.Relative)) + let httpMessage = new System.Net.Http.HttpRequestMessage ( Method = System.Net.Http.HttpMethod.Get, - RequestUri = System.Uri (client.BaseAddress.ToString () + "/v1/member") + RequestUri = uri ) let! response = client.SendAsync (httpMessage, ct) |> Async.AwaitTask @@ -67,14 +73,19 @@ module PureGymApi = async { let! ct = Async.CancellationToken + let uri = + System.Uri ( + client.BaseAddress, + System.Uri ( + "v1/gyms/{gym_id}/attendance".Replace ("{gym_id}", gymId.ToString ()), + System.UriKind.Relative + ) + ) + let httpMessage = new System.Net.Http.HttpRequestMessage ( Method = System.Net.Http.HttpMethod.Get, - RequestUri = - System.Uri ( - client.BaseAddress.ToString () - + "/v1/gyms/{gym_id}/attendance".Replace ("{gym_id}", gymId.ToString ()) - ) + RequestUri = uri ) let! response = client.SendAsync (httpMessage, ct) |> Async.AwaitTask @@ -93,14 +104,19 @@ module PureGymApi = async { let! ct = Async.CancellationToken + let uri = + System.Uri ( + client.BaseAddress, + System.Uri ( + "v1/gyms/{gym_id}".Replace ("{gym_id}", gymId.ToString ()), + System.UriKind.Relative + ) + ) + let httpMessage = new System.Net.Http.HttpRequestMessage ( Method = System.Net.Http.HttpMethod.Get, - RequestUri = - System.Uri ( - client.BaseAddress.ToString () - + "/v1/gyms/{gym_id}".Replace ("{gym_id}", gymId.ToString ()) - ) + RequestUri = uri ) let! response = client.SendAsync (httpMessage, ct) |> Async.AwaitTask @@ -119,10 +135,13 @@ module PureGymApi = async { let! ct = Async.CancellationToken + let uri = + System.Uri (client.BaseAddress, System.Uri ("v1/member/activity", System.UriKind.Relative)) + let httpMessage = new System.Net.Http.HttpRequestMessage ( Method = System.Net.Http.HttpMethod.Get, - RequestUri = System.Uri (client.BaseAddress.ToString () + "/v1/member/activity") + RequestUri = uri ) let! response = client.SendAsync (httpMessage, ct) |> Async.AwaitTask @@ -141,18 +160,23 @@ module PureGymApi = async { let! ct = Async.CancellationToken + let uri = + System.Uri ( + client.BaseAddress, + System.Uri ( + ("v2/gymSessions/member" + + "?fromDate=" + + ((fromDate.ToString "yyyy-MM-dd") |> System.Web.HttpUtility.UrlEncode) + + "&toDate=" + + ((toDate.ToString "yyyy-MM-dd") |> System.Web.HttpUtility.UrlEncode)), + System.UriKind.Relative + ) + ) + let httpMessage = new System.Net.Http.HttpRequestMessage ( Method = System.Net.Http.HttpMethod.Get, - RequestUri = - System.Uri ( - client.BaseAddress.ToString () - + ("/v2/gymSessions/member" - + "?fromDate=" - + ((fromDate.ToString "yyyy-MM-dd") |> System.Web.HttpUtility.UrlEncode) - + "&toDate=" - + ((toDate.ToString "yyyy-MM-dd") |> System.Web.HttpUtility.UrlEncode)) - ) + RequestUri = uri ) let! response = client.SendAsync (httpMessage, ct) |> Async.AwaitTask diff --git a/PureGym/GeneratedDto.fs b/PureGym/GeneratedDto.fs index 411a9c5..d97aa14 100644 --- a/PureGym/GeneratedDto.fs +++ b/PureGym/GeneratedDto.fs @@ -12,11 +12,29 @@ module GymOpeningHours = /// Parse from a JSON node. let jsonParse (node : System.Text.Json.Nodes.JsonNode) : GymOpeningHours = let OpeningHours = - node.["openingHours"].AsArray () + (match node.["openingHours"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("openingHours") + ) + ) + | v -> v) + .AsArray () |> Seq.map (fun elt -> elt.AsValue().GetValue ()) |> List.ofSeq - let IsAlwaysOpen = node.["isAlwaysOpen"].AsValue().GetValue () + let IsAlwaysOpen = + (match node.["isAlwaysOpen"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("isAlwaysOpen") + ) + ) + | v -> v) + .AsValue() + .GetValue () { IsAlwaysOpen = IsAlwaysOpen @@ -30,8 +48,29 @@ namespace PureGym module GymAccessOptions = /// Parse from a JSON node. let jsonParse (node : System.Text.Json.Nodes.JsonNode) : GymAccessOptions = - let QrCodeAccess = node.["qrCodeAccess"].AsValue().GetValue () - let PinAccess = node.["pinAccess"].AsValue().GetValue () + let QrCodeAccess = + (match node.["qrCodeAccess"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("qrCodeAccess") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let PinAccess = + (match node.["pinAccess"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("pinAccess") + ) + ) + | v -> v) + .AsValue() + .GetValue () { PinAccess = PinAccess @@ -47,13 +86,32 @@ module GymLocation = let jsonParse (node : System.Text.Json.Nodes.JsonNode) : GymLocation = let Latitude = try - node.["latitude"].AsValue().GetValue () + (match node.["latitude"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("latitude") + ) + ) + | v -> v) + .AsValue() + .GetValue () with :? System.InvalidOperationException as exc -> if exc.Message.Contains "cannot be converted to" then if System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString then - node.["latitude"].AsValue().GetValue () |> System.Double.Parse + (match node.["latitude"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("latitude") + ) + ) + | v -> v) + .AsValue() + .GetValue () + |> System.Double.Parse else reraise () else @@ -61,13 +119,32 @@ module GymLocation = let Longitude = try - node.["longitude"].AsValue().GetValue () + (match node.["longitude"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("longitude") + ) + ) + | v -> v) + .AsValue() + .GetValue () with :? System.InvalidOperationException as exc -> if exc.Message.Contains "cannot be converted to" then if System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString then - node.["longitude"].AsValue().GetValue () |> System.Double.Parse + (match node.["longitude"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("longitude") + ) + ) + | v -> v) + .AsValue() + .GetValue () + |> System.Double.Parse else reraise () else @@ -85,14 +162,34 @@ namespace PureGym module GymAddress = /// Parse from a JSON node. let jsonParse (node : System.Text.Json.Nodes.JsonNode) : GymAddress = - let Postcode = node.["postcode"].AsValue().GetValue () + let Postcode = + (match node.["postcode"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("postcode") + ) + ) + | v -> v) + .AsValue() + .GetValue () let County = match node.["county"] with | null -> None | v -> v.AsValue().GetValue () |> Some - let Town = node.["town"].AsValue().GetValue () + let Town = + (match node.["town"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("town") + ) + ) + | v -> v) + .AsValue() + .GetValue () let AddressLine3 = match node.["addressLine3"] with @@ -104,7 +201,17 @@ module GymAddress = | null -> None | v -> v.AsValue().GetValue () |> Some - let AddressLine1 = node.["addressLine1"].AsValue().GetValue () + let AddressLine1 = + (match node.["addressLine1"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("addressLine1") + ) + ) + | v -> v) + .AsValue() + .GetValue () { AddressLine1 = AddressLine1 @@ -122,17 +229,95 @@ namespace PureGym module Gym = /// Parse from a JSON node. let jsonParse (node : System.Text.Json.Nodes.JsonNode) : Gym = - let ReopenDate = node.["reopenDate"].AsValue().GetValue () - let TimeZone = node.["timeZone"].AsValue().GetValue () + let ReopenDate = + (match node.["reopenDate"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("reopenDate") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let TimeZone = + (match node.["timeZone"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("timeZone") + ) + ) + | v -> v) + .AsValue() + .GetValue () + let Location = GymLocation.jsonParse node.["location"] let AccessOptions = GymAccessOptions.jsonParse node.["accessOptions"] let GymOpeningHours = GymOpeningHours.jsonParse node.["gymOpeningHours"] - let EmailAddress = node.["emailAddress"].AsValue().GetValue () - let PhoneNumber = node.["phoneNumber"].AsValue().GetValue () + + let EmailAddress = + (match node.["emailAddress"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("emailAddress") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let PhoneNumber = + (match node.["phoneNumber"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("phoneNumber") + ) + ) + | v -> v) + .AsValue() + .GetValue () + let Address = GymAddress.jsonParse node.["address"] - let Status = node.["status"].AsValue().GetValue () - let Id = node.["id"].AsValue().GetValue () - let Name = node.["name"].AsValue().GetValue () + + let Status = + (match node.["status"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("status") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let Id = + (match node.["id"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("id") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let Name = + (match node.["name"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("name") + ) + ) + | v -> v) + .AsValue() + .GetValue () { Name = Name @@ -155,24 +340,186 @@ namespace PureGym module Member = /// Parse from a JSON node. let jsonParse (node : System.Text.Json.Nodes.JsonNode) : Member = - let MemberStatus = node.["memberStatus"].AsValue().GetValue () - let SuspendedReason = node.["suspendedReason"].AsValue().GetValue () - let MembershipLevel = node.["membershipLevel"].AsValue().GetValue () - let MembershipName = node.["membershipName"].AsValue().GetValue () - let Postcode = node.["postCode"].AsValue().GetValue () - let MobileNumber = node.["mobileNumber"].AsValue().GetValue () + let MemberStatus = + (match node.["memberStatus"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("memberStatus") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let SuspendedReason = + (match node.["suspendedReason"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("suspendedReason") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let MembershipLevel = + (match node.["membershipLevel"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("membershipLevel") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let MembershipName = + (match node.["membershipName"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("membershipName") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let Postcode = + (match node.["postCode"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("postCode") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let MobileNumber = + (match node.["mobileNumber"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("mobileNumber") + ) + ) + | v -> v) + .AsValue() + .GetValue () let DateOfBirth = - node.["dateofBirth"].AsValue().GetValue () |> System.DateOnly.Parse + (match node.["dateofBirth"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("dateofBirth") + ) + ) + | v -> v) + .AsValue() + .GetValue () + |> System.DateOnly.Parse - let GymAccessPin = node.["gymAccessPin"].AsValue().GetValue () - let EmailAddress = node.["emailAddress"].AsValue().GetValue () - let HomeGymName = node.["homeGymName"].AsValue().GetValue () - let HomeGymId = node.["homeGymId"].AsValue().GetValue () - let LastName = node.["lastName"].AsValue().GetValue () - let FirstName = node.["firstName"].AsValue().GetValue () - let CompoundMemberId = node.["compoundMemberId"].AsValue().GetValue () - let Id = node.["id"].AsValue().GetValue () + let GymAccessPin = + (match node.["gymAccessPin"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("gymAccessPin") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let EmailAddress = + (match node.["emailAddress"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("emailAddress") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let HomeGymName = + (match node.["homeGymName"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("homeGymName") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let HomeGymId = + (match node.["homeGymId"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("homeGymId") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let LastName = + (match node.["lastName"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("lastName") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let FirstName = + (match node.["firstName"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("firstName") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let CompoundMemberId = + (match node.["compoundMemberId"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("compoundMemberId") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let Id = + (match node.["id"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("id") + ) + ) + | v -> v) + .AsValue() + .GetValue () { Id = Id @@ -199,28 +546,109 @@ namespace PureGym module GymAttendance = /// Parse from a JSON node. let jsonParse (node : System.Text.Json.Nodes.JsonNode) : GymAttendance = - let MaximumCapacity = node.["maximumCapacity"].AsValue().GetValue () + let MaximumCapacity = + (match node.["maximumCapacity"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("maximumCapacity") + ) + ) + | v -> v) + .AsValue() + .GetValue () let LastRefreshedPeopleInClasses = - node.["lastRefreshedPeopleInClasses"].AsValue().GetValue () + (match node.["lastRefreshedPeopleInClasses"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("lastRefreshedPeopleInClasses") + ) + ) + | v -> v) + .AsValue() + .GetValue () |> System.DateTime.Parse let LastRefreshed = - node.["lastRefreshed"].AsValue().GetValue () |> System.DateTime.Parse + (match node.["lastRefreshed"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("lastRefreshed") + ) + ) + | v -> v) + .AsValue() + .GetValue () + |> System.DateTime.Parse let AttendanceTime = - node.["attendanceTime"].AsValue().GetValue () |> System.DateTime.Parse + (match node.["attendanceTime"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("attendanceTime") + ) + ) + | v -> v) + .AsValue() + .GetValue () + |> System.DateTime.Parse - let IsApproximate = node.["isApproximate"].AsValue().GetValue () + let IsApproximate = + (match node.["isApproximate"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("isApproximate") + ) + ) + | v -> v) + .AsValue() + .GetValue () let TotalPeopleSuffix = match node.["totalPeopleSuffix"] with | null -> None | v -> v.AsValue().GetValue () |> Some - let TotalPeopleInClasses = node.["totalPeopleInClasses"].AsValue().GetValue () - let TotalPeopleInGym = node.["totalPeopleInGym"].AsValue().GetValue () - let Description = node.["description"].AsValue().GetValue () + let TotalPeopleInClasses = + (match node.["totalPeopleInClasses"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("totalPeopleInClasses") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let TotalPeopleInGym = + (match node.["totalPeopleInGym"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("totalPeopleInGym") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let Description = + (match node.["description"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("description") + ) + ) + | v -> v) + .AsValue() + .GetValue () { Description = Description @@ -242,13 +670,77 @@ module MemberActivityDto = /// Parse from a JSON node. let jsonParse (node : System.Text.Json.Nodes.JsonNode) : MemberActivityDto = let LastRefreshed = - node.["lastRefreshed"].AsValue().GetValue () |> System.DateTime.Parse + (match node.["lastRefreshed"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("lastRefreshed") + ) + ) + | v -> v) + .AsValue() + .GetValue () + |> System.DateTime.Parse - let IsEstimated = node.["isEstimated"].AsValue().GetValue () - let TotalClasses = node.["totalClasses"].AsValue().GetValue () - let TotalVisits = node.["totalVisits"].AsValue().GetValue () - let AverageDuration = node.["averageDuration"].AsValue().GetValue () - let TotalDuration = node.["totalDuration"].AsValue().GetValue () + let IsEstimated = + (match node.["isEstimated"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("isEstimated") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let TotalClasses = + (match node.["totalClasses"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("totalClasses") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let TotalVisits = + (match node.["totalVisits"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("totalVisits") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let AverageDuration = + (match node.["averageDuration"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("averageDuration") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let TotalDuration = + (match node.["totalDuration"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("totalDuration") + ) + ) + | v -> v) + .AsValue() + .GetValue () { TotalDuration = TotalDuration @@ -266,9 +758,41 @@ namespace PureGym module SessionsAggregate = /// Parse from a JSON node. let jsonParse (node : System.Text.Json.Nodes.JsonNode) : SessionsAggregate = - let Duration = node.["Duration"].AsValue().GetValue () - let Visits = node.["Visits"].AsValue().GetValue () - let Activities = node.["Activities"].AsValue().GetValue () + let Duration = + (match node.["Duration"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("Duration") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let Visits = + (match node.["Visits"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("Visits") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let Activities = + (match node.["Activities"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("Activities") + ) + ) + | v -> v) + .AsValue() + .GetValue () { Activities = Activities @@ -283,9 +807,41 @@ namespace PureGym module VisitGym = /// Parse from a JSON node. let jsonParse (node : System.Text.Json.Nodes.JsonNode) : VisitGym = - let Status = node.["Status"].AsValue().GetValue () - let Name = node.["Name"].AsValue().GetValue () - let Id = node.["Id"].AsValue().GetValue () + let Status = + (match node.["Status"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("Status") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let Name = + (match node.["Name"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("Name") + ) + ) + | v -> v) + .AsValue() + .GetValue () + + let Id = + (match node.["Id"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("Id") + ) + ) + | v -> v) + .AsValue() + .GetValue () { Id = Id @@ -301,12 +857,43 @@ module Visit = /// Parse from a JSON node. let jsonParse (node : System.Text.Json.Nodes.JsonNode) : Visit = let Gym = VisitGym.jsonParse node.["Gym"] - let Duration = node.["Duration"].AsValue().GetValue () + + let Duration = + (match node.["Duration"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("Duration") + ) + ) + | v -> v) + .AsValue() + .GetValue () let StartTime = - node.["StartTime"].AsValue().GetValue () |> System.DateTime.Parse + (match node.["StartTime"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("StartTime") + ) + ) + | v -> v) + .AsValue() + .GetValue () + |> System.DateTime.Parse - let IsDurationEstimated = node.["IsDurationEstimated"].AsValue().GetValue () + let IsDurationEstimated = + (match node.["IsDurationEstimated"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("IsDurationEstimated") + ) + ) + | v -> v) + .AsValue() + .GetValue () { IsDurationEstimated = IsDurationEstimated @@ -338,7 +925,15 @@ module Sessions = /// Parse from a JSON node. let jsonParse (node : System.Text.Json.Nodes.JsonNode) : Sessions = let Visits = - node.["Visits"].AsArray () + (match node.["Visits"] with + | null -> + raise ( + System.Collections.Generic.KeyNotFoundException ( + sprintf "Required key '%s' not found on JSON object" ("Visits") + ) + ) + | v -> v) + .AsArray () |> Seq.map (fun elt -> Visit.jsonParse elt) |> List.ofSeq diff --git a/PureGym/PureGym.fsproj b/PureGym/PureGym.fsproj index dad0e62..d547fce 100644 --- a/PureGym/PureGym.fsproj +++ b/PureGym/PureGym.fsproj @@ -1,4 +1,4 @@ - + net6.0 @@ -6,7 +6,7 @@ true FS3559 - 1.1.1 + 1.1.5 -- 2.51.0 From 7bb66610c9fee6c5ae6bf4f4a5ce4397a4f1dd6a Mon Sep 17 00:00:00 2001 From: Smaug123 Date: Fri, 29 Dec 2023 12:18:53 +0000 Subject: [PATCH 2/2] Bump deps --- nix/deps.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nix/deps.nix b/nix/deps.nix index 72339e6..f2d1868 100644 --- a/nix/deps.nix +++ b/nix/deps.nix @@ -438,7 +438,7 @@ }) (fetchNuGet { pname = "WoofWare.Myriad.Plugins"; - version = "1.1.1"; - sha256 = "1maj1p93cg8c22l9ldq310n21cbhg5rpjkkrm6cjh7dm4rpvr9mg"; + version = "1.1.5"; + sha256 = "05syw1v7yp9pl9gzbf3sc7spjhs7yb4vpx0d34ylr14gkiywgqsg"; }) ] -- 2.51.0