urbit/main/app/twit/core.hook
2014-08-11 11:51:48 -07:00

118 lines
4.9 KiB
Plaintext

:: A simple Twitter servant.
::
:::: /hook/core/twit/app
::
/? 314 :: need urbit 314
/+ twitter :: use twitter library
/= front /:/%%/front:/hymn/ :: load front page
::
:::: structures
::
|% :: structures
++ axle ,[%0 axle-a] :: application state
++ axle-a ::
%- unit ::
$: las=@da :: update time
txt=@t :: XX timeline text
jon=json :: timeline json
== ::
++ axle-old :: any historic state
$% [%0 axle-a] ::
== ::
++ gilt :: subscription frame
$% [%json p=json] :: json data
[%html p=@t] :: html text
[%hymn p=manx] :: html tree
== ::
++ gift :: output action
$% [%rust gilt] :: total update
[%nice ~] :: succeed
== ::
++ move ,[p=bone q=(mold note gift)] :: output operation
++ sign :: system response
$% $: %e :: from %eyre
$% [%thou p=httr] :: HTTP response
== == == ::
++ note :: system request
$% $: %e :: through %eyre
$% [%them p=(unit hiss)] :: HTTP request
== == == ::
-- ::
::
:::: constants
::
|%
++ hardcoded-key :: hardcoded keys!
:* :- 'hDDOTPfGHGlsOUbhpy6qc6XbW'
'olCkea6wm3XG4pnVCHuPIozUF2ggH1sHjnBtuT4Ai6rCOeQGzO'
:- '2485712317-R77Lpdu5rAJadRVxTXPpnxvcwS0IfNG7QEzLPty'
'a41d83XId0P7QQbodkPYv3zxoEL0Cq9EsN2eXZBZAwAWA'
==
--
!:
:::: program
::
|_ $: hid=hide :: system state
vat=axle :: custom state
==
++ it :: internals
|%
++ line :: get timeline
=+ (twit `keys`hardcoded-key lat.hid `@`eny.hid)
(stat-home ~ ~)
::
++ lint :: publish timeline
^- (list move)
?~ +.vat ~
%+ turn
(skim (~(tap by sup.hid)) |=([* * pax=path] ?=([%line ~] pax)))
|=([ost=bone *] `move`[ost give/rust/json/[jon.u.vat]])
::
++ post :: post a tweet
|= txt=cord
^- hiss
=+ (twit `keys`hardcoded-key lat.hid `@`eny.hid)
(stat-upda ~[(st ~ txt)] ~)
--
::
++ page front :: build front page
++ prep :: load old state
|= old=(unit (unit axle-old))
[~ +>]
::
++ peer :: accept subscriber
|= [ost=bone you=ship pax=path]
^- [(list move) _+>]
:_ +>.$
?~ pax [ost %give %rust %hymn page]~
?> ?=([%line ~] pax)
?~ +.vat
[ost %pass /line %e [%them (some line:it)]]~
[ost %give %rust %json jon.u.vat]~
::
++ poke-json :: browser message
|= [ost=bone his=ship jon=json]
^- [(list move) _+>]
:_ +>.$
=+ txt=+:(need ((of [%tweet so] ~):jo jon))
:~ [ost %pass /tweet/(scot %ud ost) %e [%them (some (post:it txt))]]
[ost %give %nice ~]
==
::
++ pour :: HTTP response
|= [pax=path sih=sign]
^- [(list move) _+>]
?+ -.pax !!
%line :: timeline response
=+ txt=`@t`q:(need r.p.sih)
=+ jon=(rash txt apex:poja) :: XX check content!!!
=+ old=&(?=(^ +.vat) =(jon jon.u.vat))
=. +.vat `[lat.hid txt jon]
[?:(old ~ lint:it) +>.$]
::
%tweet :: post response
=+ ost=(slav %ud -.+.pax)
[[ost %pass /line %e [%them (some line:it)]]~ +>.$]
==
--