From dc0f0803b3c66c6fd0d9549d3a3f29db0ce0fbd6 Mon Sep 17 00:00:00 2001
From: Patrick Stevens <3138005+Smaug123@users.noreply.github.com>
Date: Fri, 29 Dec 2023 18:13:39 +0000
Subject: [PATCH] Allow string return type, and URL-encode param (#38)
---
ConsumePlugin/ConsumePlugin.fsproj | 70 +++++++--------
ConsumePlugin/GeneratedRestClient.fs | 33 ++++++-
ConsumePlugin/RestApiExample.fs | 3 +
Directory.Build.props | 6 +-
MyriadPlugin.Test/MyriadPlugin.Test.fsproj | 58 ++++++------
MyriadPlugin.Test/TestPathParam.fs | 36 ++++++++
.../{TestRestApi.fs => TestPureGymRestApi.fs} | 2 +-
README.md | 76 ++++++++++++++--
WoofWare.Myriad.Plugins/AstHelper.fs | 11 +++
.../HttpClientGenerator.fs | 88 ++++++++++++-------
.../WoofWare.Myriad.Plugins.fsproj | 20 ++---
11 files changed, 282 insertions(+), 121 deletions(-)
create mode 100644 MyriadPlugin.Test/TestPathParam.fs
rename MyriadPlugin.Test/{TestRestApi.fs => TestPureGymRestApi.fs} (99%)
diff --git a/ConsumePlugin/ConsumePlugin.fsproj b/ConsumePlugin/ConsumePlugin.fsproj
index 6e9c951..808c436 100644
--- a/ConsumePlugin/ConsumePlugin.fsproj
+++ b/ConsumePlugin/ConsumePlugin.fsproj
@@ -1,41 +1,41 @@
-
- net8.0
- false
-
-
-
-
+
+ net8.0
+ false
+
+
+
+
-
-
-
-
- RecordFile.fs
-
-
-
- JsonRecord.fs
-
-
-
- PureGymDto.fs
-
-
-
- RestApiExample.fs
-
-
- runmyriad.sh
-
-
+
+
+
+
+ RecordFile.fs
+
+
+
+ JsonRecord.fs
+
+
+
+ PureGymDto.fs
+
+
+
+ RestApiExample.fs
+
+
+ runmyriad.sh
+
+
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/ConsumePlugin/GeneratedRestClient.fs b/ConsumePlugin/GeneratedRestClient.fs
index 6c44f90..7e8facb 100644
--- a/ConsumePlugin/GeneratedRestClient.fs
+++ b/ConsumePlugin/GeneratedRestClient.fs
@@ -51,7 +51,8 @@ module PureGymApi =
System.Uri (
client.BaseAddress,
System.Uri (
- "v1/gyms/{gym_id}/attendance".Replace ("{gym_id}", gymId.ToString ()),
+ "v1/gyms/{gym_id}/attendance"
+ .Replace ("{gym_id}", gymId.ToString () |> System.Web.HttpUtility.UrlEncode),
System.UriKind.Relative
)
)
@@ -107,7 +108,8 @@ module PureGymApi =
System.Uri (
client.BaseAddress,
System.Uri (
- "v1/gyms/{gym_id}".Replace ("{gym_id}", gymId.ToString ()),
+ "v1/gyms/{gym_id}"
+ .Replace ("{gym_id}", gymId.ToString () |> System.Web.HttpUtility.UrlEncode),
System.UriKind.Relative
)
)
@@ -189,4 +191,31 @@ module PureGymApi =
return Sessions.jsonParse node
}
|> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
+
+ member _.GetPathParam (parameter : string, ct : CancellationToken option) =
+ async {
+ let! ct = Async.CancellationToken
+
+ let uri =
+ System.Uri (
+ client.BaseAddress,
+ System.Uri (
+ "endpoint/{param}"
+ .Replace ("{param}", parameter.ToString () |> System.Web.HttpUtility.UrlEncode),
+ System.UriKind.Relative
+ )
+ )
+
+ let httpMessage =
+ new System.Net.Http.HttpRequestMessage (
+ Method = System.Net.Http.HttpMethod.Get,
+ RequestUri = uri
+ )
+
+ let! response = client.SendAsync (httpMessage, ct) |> Async.AwaitTask
+ let response = response.EnsureSuccessStatusCode ()
+ let! node = response.Content.ReadAsStringAsync ct |> Async.AwaitTask
+ return node
+ }
+ |> (fun a -> Async.StartAsTask (a, ?cancellationToken = ct))
}
diff --git a/ConsumePlugin/RestApiExample.fs b/ConsumePlugin/RestApiExample.fs
index c1ccc68..df33809 100644
--- a/ConsumePlugin/RestApiExample.fs
+++ b/ConsumePlugin/RestApiExample.fs
@@ -26,3 +26,6 @@ type IPureGymApi =
[]
abstract GetSessions :
[] fromDate : DateOnly * [] toDate : DateOnly * ?ct : CancellationToken -> Task
+
+ []
+ abstract GetPathParam : [] parameter : string * ?ct : CancellationToken -> Task
diff --git a/Directory.Build.props b/Directory.Build.props
index a77d3a7..8a619c2 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -10,9 +10,9 @@
embedded
-
-
-
+
+
+
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
True
\