-
Notifications
You must be signed in to change notification settings - Fork 76
/
Web.Curl.pq
23 lines (20 loc) · 919 Bytes
/
Web.Curl.pq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
//Get a curl command string for a given url and options (as used in Web.Contents()) for debugging purposes.
//Usage:
Web.Curl = Load("Web.Curl"),
Web.Curl("http://item.taobao.com/item.htm", [Query=[id="16390081398"]])
//Result: 'curl "http://item.taobao.com/item.htm?id=16390081398" -v'
*/
(url as text, optional options as record) as text =>
let
//url = "http://item.taobao.com/item.htm?id=16390081398",
//options = [Query=null],
query = options[Query],
headers = options[Headers],
qList = List.Transform(Record.FieldNames(query), each _ & "=" & Record.Field(query, _)),
hList = List.Transform(Record.FieldNames(headers), each " -H """ & _ & ": " & Record.Field(headers, _) & """"),
qJoined = try "?" & Text.Combine(qList, "&") otherwise "",
hJoined = try Text.Combine(hList, "") otherwise "",
Return = "curl """ & url & qJoined & """" & hJoined & " -v"
in
Return