urbit/main/app/twit/core.hook
2014-08-11 01:42:23 -07:00

160 lines
5.5 KiB
Plaintext

:: A simple Twitter proxy.
::
:::: /hook/core/twit/app
::
/? 314 :: need urbit 314
/+ twitter :: use twitter library
/= resource :: resource tree
/. /= urbit /:/===/lib/urb:/hymn/ :: urbit library (js)
/= style /:/%%/style:/hymn/ :: stylesheet (css)
/= application /:/%%/app:/hymn/ :: application (js)
== ::
::
:::: structures
::
|% :: structures
++ axle :: application state
,@t
:: $: %0 :: revision 0
:: tul=(unit json) ::
:: ==
++ 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
[%mean (unit (pair term (list tank)))] :: terminate
[%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 :: standard state
vat=axle :: custom state
==
++ me :: internals
|%
++ post :: post request
|= txt=cord
^- hiss
=+ (twit `keys`hardcoded-key lat.hid `@`eny.hid)
(stat-upda ~[(st ~ txt)] ~)
::
++ line :: timeline request
~& %request-timeline
=+ (twit `keys`hardcoded-key lat.hid `@`eny.hid)
(stat-home ~ ~)
--
::
++ page :: build front page
^- manx
;html
;head
;title: Urbit - Twitter Test
;+ style.resource
;script
=type "text/javascript"
=src "//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"
;
==
==
;body
;div#c
;div#d
;div#twet
;div.author: @urbit_test
;div.date;
;textarea#tweetr(placeholder "What would you like to tweet?");
;input#submit(type "button", value "Send");
;input#length(type "button", value "0/140");
==
;div#time;
==
==
;+ urbit.resource
;+ application.resource
==
==
::
++ prep :: load old state
|= old=(unit)
~& %hose-state
[~ +>]
::
++ peer :: accept subscriber
|= [ost=bone you=ship pax=path]
^- [(list move) _+>]
:_ +>.$
~& [%peer ost pax]
?~ pax
[ost %give %rust %hymn page]~
?>(?=([%line ~] pax) ~)
::
++ poke-json :: client message
|= [ost=bone his=ship jon=json]
^- [(list move) _+>]
:_ +>.$
~& [%poke-json jon]
=+ txt=+:(need ((of [%tweet so] ~):jo jon))
~& [%poke-tweet txt]
:~ [ost %pass /tweet/(scot %ud ost) %e [%them (some (post:me txt))]]
[ost %give %nice ~]
==
::
++ pour :: API response
|= [pax=path sih=sign]
^- [(list move) _+>]
?: ?=([%line ~] pax)
(pour-line pax sih)
?> ?=([%tweet *] pax)
(pour-tweet pax sih)
::
++ pour-line :: timeline response
|= [pax=path sih=sign]
^- [(list move) _+>]
:_ +>.$
=. vat `@t`q:(need r.p.sih)
%+ turn
%+ skim (~(tap by sup.hid))
|= [ost=bone his=ship pax=path]
?=([%line ~] pax)
|= [ost=bone his=ship pax=path]
^- move
~& [%pour-line-give ost his pax]
=- [ost give/rust/json/-]
(rash vat apex:poja)
::
++ pour-tweet :: tweet response
|= [pax=path sih=sign]
^- [(list move) _+>]
~& %pour-tweet
=+ ost=(slav %ud -.+.pax)
:_ +>.$
:~ [ost %give %nice ~]
[ost %pass /line %e [%them (some line:me)]]
==
--