# Youseful Software - FileMaker sample script
# Script name: Youseful - Measure a transfer
# Plug-in: YsflCurl.fmx64 (Windows x64)
# Setup: Replace https://api.example.com/demo.json with a read-only HTTP endpoint you control or are allowed to call.
# Expected: A dialog shows HTTP status, negotiated protocol, and elapsed milliseconds. Values depend on the endpoint and network.
# Format: UTF-8 Script Workspace step listing. Add the steps manually; this is not an importable FileMaker file.
# Lines beginning with # are notes; optionally add them as Comment steps.
# Preserve calculation quotes, backslashes, and paragraph symbols exactly.

Set Variable [ $url ; Value: "https://api.example.com/demo.json" ]
Set Variable [ $body ; Value: YsflCu_Get ( $url ; "http2 timeout=15 connecttimeout=10" ) ]
Set Variable [ $transportError ; Value: YsflCu_LastError ]
Set Variable [ $transportMessage ; Value: YsflCu_LastErrorText ]
If [ $transportError <> 0 ]
    Show Custom Dialog [ "Transfer failed" ; $transportMessage ]
    Exit Script [ Text Result: $body ]
End If
Set Variable [ $status ; Value: YsflCu_Status ]
Set Variable [ $protocol ; Value: YsflCu_Info ( "httpversion" ) ]
Set Variable [ $seconds ; Value: YsflCu_Info ( "totaltime" ) ]
Set Variable [ $report ; Value:
    "HTTP status: " & $status & "¶Protocol: " & $protocol &
    "¶Elapsed milliseconds: " & Round ( GetAsNumber ( $seconds ) * 1000 ; 1 )
]
If [ $status < 200 or $status >= 300 ]
    Show Custom Dialog [ "Server returned an error" ; $report & "¶" & $body ]
Else
    Show Custom Dialog [ "Transfer complete" ; $report ]
End If
