mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-16 06:44:50 +00:00
070327cb57
This avoids breaking existing code that expects to be able to import the core macros with just $:/tags/Macro @pmario - I suggest that future updates use the same approach Thanks to @ericshulman for reporting the problem
91 lines
2.4 KiB
Plaintext
91 lines
2.4 KiB
Plaintext
title: WidgetMessage: tm-http-request Example - Random Dog
|
|
tags: $:/tags/Macro $:/tags/Global
|
|
|
|
\procedure download-dog(url)
|
|
|
|
\procedure completion-download-dog()
|
|
\import [subfilter{$:/core/config/GlobalImportFilter}]
|
|
<$action-log msg="In completion-download-dog"/>
|
|
<$action-log/>
|
|
<!-- Success -->
|
|
<$list filter="[<status>compare:number:gteq[200]compare:number:lteq[299]]" variable="ignore">
|
|
<!-- Create the dog tiddler -->
|
|
<$action-createtiddler
|
|
$basetitle=`$:/RandomDog/$(title)$`
|
|
text=<<data>>
|
|
tags="$:/tags/RandomDog"
|
|
type={{{ [<headers>jsonget[content-type]] }}}
|
|
credits="https://random.dog/"
|
|
>
|
|
<$action-log msg="Created tiddler" title=<<createTiddler-title>>/>
|
|
</$createtiddler>
|
|
</$list>
|
|
\end completion-download-dog
|
|
|
|
<$action-sendmessage
|
|
$message="tm-http-request"
|
|
url=<<url>>
|
|
method="GET"
|
|
binary="yes"
|
|
oncompletion=<<completion-download-dog>>
|
|
var-title=<<url>>
|
|
/>
|
|
\end download-dog
|
|
|
|
\procedure get-random-dog()
|
|
|
|
\procedure completion-get-json()
|
|
\import [subfilter{$:/core/config/GlobalImportFilter}]
|
|
<$action-log msg="In completion-get-json"/>
|
|
<$action-log/>
|
|
<!-- Success -->
|
|
<$list filter="[<status>compare:number:gteq[200]compare:number:lteq[299]]" variable="ignore">
|
|
<!-- Download the dog -->
|
|
<$macrocall $name="download-dog" url={{{ [<data>jsonget[url]] }}}/>
|
|
</$list>
|
|
\end completion-get-json
|
|
|
|
<$action-sendmessage
|
|
$message="tm-http-request"
|
|
url="https://random.dog/woof.json"
|
|
method="GET"
|
|
oncompletion=<<completion-get-json>>
|
|
/>
|
|
\end get-random-dog
|
|
|
|
!! Random Dogs
|
|
|
|
This demo uses the API of the website https://random.dog/ to import a random dog image or video.
|
|
|
|
//Note that the images and videos can be quite large, so this demo is not recommended to be used over mobile data connections.//
|
|
|
|
<$button actions=<<get-random-dog>>>
|
|
Import a random dog image or video
|
|
</$button>
|
|
|
|
<$list filter="[tag[$:/tags/RandomDog]limit[1]]" variable="ignore">
|
|
|
|
!! Imported Tiddlers
|
|
|
|
<$button>
|
|
<$action-deletetiddler $filter="[tag[$:/tags/RandomDog]]"/>
|
|
Delete all imported random dogs
|
|
</$button>
|
|
|
|
Export all imported random dogs: <$macrocall $name="exportButton" exportFilter="[tag[$:/tags/RandomDog]]" lingoBase="$:/language/Buttons/ExportTiddlers/"/>
|
|
|
|
</$list>
|
|
|
|
<ol>
|
|
<$list filter="[tag[$:/tags/RandomDog]!sort[modified]]">
|
|
<li>
|
|
<$link>
|
|
<$text text=<<currentTiddler>>/>
|
|
</$link>
|
|
<div style="width:300px;">
|
|
<$transclude $tiddler=<<currentTiddler>>/>
|
|
</div>
|
|
</li>
|
|
</$list>
|
|
</ol>
|