1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-08-06 19:20:48 +00:00
TiddlyWiki5/editions/tw5.com/tiddlers/messages/WidgetMessage_ tm-http-request Example Flickr.tid

100 lines
3.1 KiB
Plaintext
Raw Normal View History

title: WidgetMessage: tm-http-request Example - Flickr
tags: $:/tags/Macro
<!--
Get items from a Flickr album/interestingness/collection etc.
-->
\define flickr-get-items(method:"flickr.photosets.getPhotos",resultPhotoRoot:"photoset")
\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">
<$list filter="[<data>jsonindexes<resultPhotoRoot>,[photo]]" variable="photoIndex">
<$let
photoData={{{ [<data>jsonextract<resultPhotoRoot>,[photo],<photoIndex>] }}}
photoFarm={{{ [<photoData>jsonget[farm]] }}}
photoServer={{{ [<photoData>jsonget[server]] }}}
photoID={{{ [<photoData>jsonget[id]] }}}
photoSecret={{{ [<photoData>jsonget[secret]] }}}
>
<$action-setfield
$tiddler={{{ [<photoID>addprefix[Flickr Photo ]] }}}
tags="$:/tags/GeoMarker $:/tags/FlickrPhoto"
caption={{{ [<photoData>jsonget[title]] }}}
lat={{{ [<photoData>jsonget[latitude]] }}}
long={{{ [<photoData>jsonget[longitude]] }}}
alt="0"
photo-url={{{ [[https://farm]addsuffix<photoFarm>addsuffix[.staticflickr.com/]addsuffix<photoServer>addsuffix[/]addsuffix<photoID>addsuffix[_]addsuffix<photoSecret>addsuffix[_b.jpg]] }}}
icon-url={{{ [[https://farm]addsuffix<photoFarm>addsuffix[.staticflickr.com/]addsuffix<photoServer>addsuffix[/]addsuffix<photoID>addsuffix[_]addsuffix<photoSecret>addsuffix[_s.jpg]] }}}
/>
</$let>
</$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.flickr.com/services/rest/
\end request-url
<$action-sendmessage
$message="tm-http-request"
url=<<request-url>>
method="GET"
query-method=<<__method__>>
query-extras="geo"
query-format="json"
query-nojsoncallback="1"
query-photoset_id={{$:/config/flickr-album}}
header-accept="application/json"
password-query-api_key="flickr-api-key"
bind-status="$:/temp/flickr/status"
bind-progress="$:/temp/flickr/progress"
oncompletion=<<completion>>
onprogress=<<progress>>
var-start=<<__start__>>
var-limit=<<__limit__>>
var-resultPhotoRoot=<<__resultPhotoRoot__>>
/>
\end
\define flickr-get-album-items()
<$macrocall $name="flickr-get-items" method="flickr.photosets.getPhotos" resultPhotoRoot="photoset"/>
\end
\define flickr-get-interesting-items()
<$macrocall $name="flickr-get-items" method="flickr.interestingness.getList" resultPhotoRoot="photos"/>
\end
\define flickr-actions()
<$macrocall $name="flickr-get-album-items"/>
\end
! Map of Flickr Photos
Flickr API Key: <$password name="flickr-api-key"/>
Flickr album ID: <$edit-text tiddler="$:/config/flickr-album" tag="input"/>
<$button>
<$macrocall $name="flickr-get-album-items"/>
Get Flickr album
</$button>
<$button>
<$macrocall $name="flickr-get-interesting-items"/>
Get Flickr interesting items
</$button>
<$geomap
markers="[all[tiddlers+shadows]tag[$:/tags/GeoMarker]tag[$:/tags/FlickrPhoto]]"
/>