mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-19 00:04:51 +00:00
4b9a6b5757
An initial experiment for handling paginated APIs. This isn't perfect; it isn't possible to interrupt things, for example.
79 lines
2.4 KiB
Plaintext
79 lines
2.4 KiB
Plaintext
title: WidgetMessage: tm-http-request Example - Zotero
|
|
tags: $:/tags/Macro
|
|
|
|
\define zotero-save-item(item)
|
|
<$action-createtiddler
|
|
$basetitle={{{ =[[_zotero_import ]] =[<item>jsonget[key]] =[[ ]] =[<item>jsonget[title]] +[join[]] }}}
|
|
text={{{ [<item>jsonget[title]] }}}
|
|
tags="$:/tags/ZoteroImport"
|
|
>
|
|
<$action-setmultiplefields $tiddler=<<createTiddler-title>> $fields="[<item>jsonindexes[]addprefix[zotero-]]" $values="[<item>jsonindexes[]] :map[<item>jsonget<currentTiddler>else[.XXXXX.]]"/>
|
|
</$action-createtiddler>
|
|
\end zotero-save-item
|
|
|
|
\define zotero-save-items(data)
|
|
<$list filter="[<data>jsonindexes[]] :map[<data>jsonextract<currentTiddler>,[data]]" variable="item">
|
|
<$macrocall $name="zotero-save-item" item=<<item>>/>
|
|
</$list>
|
|
\end zotero-save-items
|
|
|
|
\define zotero-get-items(start:"0",limit:"25")
|
|
|
|
\define completion()
|
|
\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]
|
|
<$action-log msg="In completion"/>
|
|
<$action-log/>
|
|
<!-- Success -->
|
|
<$list filter="[<status>compare:number:gteq[200]compare:number:lteq[299]]" variable="ignore">
|
|
<!-- Import these items -->
|
|
<$macrocall $name="zotero-save-items" data=<<data>>/>
|
|
<!-- Check if there are any more items to download -->
|
|
<$list filter="[<headers>jsonget[total-results]subtract<start>subtract<limit>compare:number:gt[0]]" variable="ignore">
|
|
<$macrocall $name="zotero-get-items" start={{{ [<start>add<limit>] }}} limit=<<limit>>/>
|
|
</$list>
|
|
</$list>
|
|
\end completion
|
|
|
|
\define progress()
|
|
\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]
|
|
<$action-log message="In progress-actions"/>
|
|
\end progress
|
|
|
|
\define request-url()
|
|
https://api.zotero.org/groups/27508/items/?format=json&sort=title
|
|
\end request-url
|
|
|
|
<$action-sendmessage
|
|
$message="tm-http-request"
|
|
url={{{ [<request-url>setquerystring[start],<__start__>setquerystring[limit],<__limit__>] }}}
|
|
method="GET"
|
|
header-accept="application/json"
|
|
bind-status="$:/temp/zotero/status"
|
|
bind-progress="$:/temp/zotero/progress"
|
|
oncompletion=<<completion>>
|
|
onprogress=<<progress>>
|
|
var-start=<<__start__>>
|
|
var-limit=<<__limit__>>
|
|
/>
|
|
\end
|
|
|
|
\define zotero-actions()
|
|
<$macrocall $name="zotero-get-items" start="0" limit="5"/>
|
|
\end
|
|
|
|
<$button actions=<<zotero-actions>>>
|
|
Call Zotero
|
|
</$button>
|
|
|
|
Tiddlers:
|
|
|
|
<ol>
|
|
<$list filter="[tag[$:/tags/ZoteroImport]]">
|
|
<li>
|
|
<$link>
|
|
<$view field="title"/>
|
|
</$link>
|
|
</li>
|
|
</$list>
|
|
</ol>
|