Allow string return type, and URL-encode param (#38)

This commit is contained in:
Patrick Stevens
2023-12-29 18:13:39 +00:00
committed by GitHub
parent 548d863baf
commit dc0f0803b3
11 changed files with 282 additions and 121 deletions

View File

@@ -1,41 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<MyriadSdkGenerator Include="$(MSBuildThisFileDirectory)..\WoofWare.Myriad.Plugins\bin\$(Configuration)\net6.0\WoofWare.Myriad.Plugins.dll" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<MyriadSdkGenerator Include="$(MSBuildThisFileDirectory)..\WoofWare.Myriad.Plugins\bin\$(Configuration)\net6.0\WoofWare.Myriad.Plugins.dll"/>
</ItemGroup>
<ItemGroup>
<None Include="myriad.toml" />
<Compile Include="RecordFile.fs" />
<Compile Include="GeneratedRecord.fs"> <!--1-->
<MyriadFile>RecordFile.fs</MyriadFile> <!--2-->
</Compile>
<Compile Include="JsonRecord.fs" />
<Compile Include="GeneratedJson.fs"> <!--1-->
<MyriadFile>JsonRecord.fs</MyriadFile> <!--2-->
</Compile>
<Compile Include="PureGymDto.fs" />
<Compile Include="GeneratedPureGymDto.fs">
<MyriadFile>PureGymDto.fs</MyriadFile> <!--2-->
</Compile>
<Compile Include="RestApiExample.fs" />
<Compile Include="GeneratedRestClient.fs">
<MyriadFile>RestApiExample.fs</MyriadFile> <!--2-->
</Compile>
<None Include="..\runmyriad.sh">
<Link>runmyriad.sh</Link>
</None>
</ItemGroup>
<ItemGroup>
<None Include="myriad.toml"/>
<Compile Include="RecordFile.fs"/>
<Compile Include="GeneratedRecord.fs"> <!--1-->
<MyriadFile>RecordFile.fs</MyriadFile> <!--2-->
</Compile>
<Compile Include="JsonRecord.fs"/>
<Compile Include="GeneratedJson.fs"> <!--1-->
<MyriadFile>JsonRecord.fs</MyriadFile> <!--2-->
</Compile>
<Compile Include="PureGymDto.fs"/>
<Compile Include="GeneratedPureGymDto.fs">
<MyriadFile>PureGymDto.fs</MyriadFile> <!--2-->
</Compile>
<Compile Include="RestApiExample.fs"/>
<Compile Include="GeneratedRestClient.fs">
<MyriadFile>RestApiExample.fs</MyriadFile> <!--2-->
</Compile>
<None Include="..\runmyriad.sh">
<Link>runmyriad.sh</Link>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="RestEase" Version="1.6.4" />
<ProjectReference Include="..\WoofWare.Myriad.Plugins\WoofWare.Myriad.Plugins.fsproj" />
<PackageReference Include="Myriad.Sdk" Version="0.8.3" />
<PackageReference Include="Myriad.Core" Version="0.8.3" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="RestEase" Version="1.6.4"/>
<ProjectReference Include="..\WoofWare.Myriad.Plugins\WoofWare.Myriad.Plugins.fsproj"/>
<PackageReference Include="Myriad.Sdk" Version="0.8.3"/>
<PackageReference Include="Myriad.Core" Version="0.8.3"/>
</ItemGroup>
</Project>

View File

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

View File

@@ -26,3 +26,6 @@ type IPureGymApi =
[<Get "/v2/gymSessions/member">]
abstract GetSessions :
[<Query>] fromDate : DateOnly * [<Query>] toDate : DateOnly * ?ct : CancellationToken -> Task<Sessions>
[<Get "endpoint/{param}">]
abstract GetPathParam : [<Path "param">] parameter : string * ?ct : CancellationToken -> Task<string>