-
-
Save zoffixznet/e565ee330e249112ef93c9047461b1e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub EXPORT (*@subs-to-export where *.all ∈ <jget jpost get post>) { | |
# note Map.new: |%( | |
Map.new: | |
'&jget' => &WWW::jget, | |
'&jpost' => &WWW::jpost, | |
'&get' => &WWW::get, | |
'&post' => &WWW::post, | |
# ){ |@subs-to-export.map: '&'~* } | |
} | |
module WWW { | |
use JSON::Fast; | |
use HTTP::UserAgent; | |
sub jget (|c) { from-json get |c } | |
sub jpost (|c) { from-json post |c } | |
sub get ($url) is export { | |
with HTTP::UserAgent.new.get: $url { | |
.is-success or fail .&err; | |
.decoded-content | |
} | |
} | |
multi sub post($, %?, *%) {*} | |
multi sub post ($url, *%form) is export { | |
post: $url, %, |%form; | |
} | |
multi sub post ($url, %headers, *%form) is export { | |
with HTTP::UserAgent.new.post($url, %form, |%headers) { | |
.is-success or fail .&err; | |
.decoded-content | |
} | |
} | |
sub err ($_) { "Error {.code}: {.status-line}" } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment