urbit/main/app/twit/core.hook

166 lines
5.7 KiB
Plaintext
Raw Normal View History

2014-08-11 11:47:46 +04:00
:: A simple Twitter proxy.
2014-08-11 08:43:43 +04:00
::
:::: /hook/core/twit/app
::
/? 314 :: need urbit 314
/+ twitter :: use twitter library
2014-08-11 11:47:46 +04:00
/= resource :: resource tree
/. /= style /:/%%/style:/hymn/ :: stylesheet (css)
/= application /:/%%/app:/hymn/ :: application (js)
/= library /:/===/lib/urb:/hymn/ :: library (js)
== ::
2014-08-11 08:43:43 +04:00
::
:::: structures
::
|% :: structures
2014-08-11 11:47:46 +04:00
++ axle :: application state
,@t
:: $: %0 :: revision 0
:: tul=(unit json) ::
:: ==
2014-08-11 08:43:43 +04:00
++ gilt :: subscription frame
$% [%json p=json] :: json data
[%html p=@t] :: html text
[%hymn p=manx] :: html tree
== ::
++ gift :: output action
2014-08-11 12:17:21 +04:00
$% [%rust gilt] :: total update
2014-08-11 08:43:43 +04:00
[%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
== == == ::
-- ::
::
2014-08-11 12:17:21 +04:00
:::: constants
2014-08-11 08:43:43 +04:00
::
|%
2014-08-11 12:17:21 +04:00
++ hardcoded-key :: hardcoded keys!
2014-08-11 08:43:43 +04:00
:* :- 'hDDOTPfGHGlsOUbhpy6qc6XbW'
'olCkea6wm3XG4pnVCHuPIozUF2ggH1sHjnBtuT4Ai6rCOeQGzO'
:- '2485712317-R77Lpdu5rAJadRVxTXPpnxvcwS0IfNG7QEzLPty'
'a41d83XId0P7QQbodkPYv3zxoEL0Cq9EsN2eXZBZAwAWA'
==
--
2014-08-08 11:41:54 +04:00
!:
2014-08-11 08:43:43 +04:00
:::: program
::
|_ $: hid=hide :: standard state
vat=axle :: custom state
2014-08-08 11:41:54 +04:00
==
2014-08-11 12:17:21 +04:00
++ me :: internals
|%
++ post :: post request
|= jon=json
^- hiss
~& [%request-post jon]
=+ txt=`(unit ,[%tweet p=cord])`((of:jo [%tweet so:jo] ~) jon)
~& [%request-post-txt txt]
^- hiss
=+ (twit `keys`hardcoded-key lat.hid `@`eny.hid)
(stat-upda ~[(st ~ p:(need txt))] ~)
2014-08-11 09:28:10 +04:00
::
2014-08-11 12:17:21 +04:00
++ line :: timeline request
~& %request-timeline
=+ (twit `keys`hardcoded-key lat.hid `@`eny.hid)
(stat-home ~ ~)
--
2014-08-08 11:41:54 +04:00
::
2014-08-11 08:43:43 +04:00
++ page :: build front page
2014-08-08 11:41:54 +04:00
^- manx
;html
;head
2014-08-09 08:00:44 +04:00
;title: Urbit - Twitter Test
2014-08-11 11:47:46 +04:00
;+ style.resource
;script
=type "text/javascript"
=src "//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"
;
==
2014-08-08 11:41:54 +04:00
==
;body
;div#c
;div#d
;div#twet
2014-08-09 08:00:44 +04:00
;div.author: @urbit_test
;div.date;
;textarea#tweetr(placeholder "What would you like to tweet?");
2014-08-08 11:41:54 +04:00
;input#submit(type "button", value "Send");
;input#length(type "button", value "0/140");
==
;div#time;
==
==
2014-08-11 11:47:46 +04:00
;+ library.resource
;+ application.resource
2014-08-08 11:41:54 +04:00
==
==
2014-08-11 12:17:21 +04:00
::
++ prep :: load old state
|= old=(unit)
~& %hose-state
[~ +>]
2014-08-11 07:49:56 +04:00
::
2014-08-11 12:17:21 +04:00
++ 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) _+>]
:_ +>.$
=+ jop=(need ((of [%tweet sa] ~):jo jon))
?- -.jop
%tweet
~& [%poke-tweet /tweet/(scot %ud ost)]
:~ [ost %pass /tweet/(scot %ud ost) %e [%them (some (post:me jon))]]
[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
2014-08-11 07:49:56 +04:00
|= [pax=path sih=sign]
2014-08-08 11:41:54 +04:00
^- [(list move) _+>]
:_ +>.$
2014-08-11 07:49:56 +04:00
=. vat `@t`q:(need r.p.sih)
%+ turn
%+ skim (~(tap by sup.hid))
|= [ost=bone his=ship pax=path]
2014-08-11 12:17:21 +04:00
?=([%line ~] pax)
2014-08-11 07:49:56 +04:00
|= [ost=bone his=ship pax=path]
2014-08-11 12:17:21 +04:00
^- move
~& [%pour-line-give ost his pax]
=- [ost give/rust/json/-]
2014-08-11 07:49:56 +04:00
(rash vat apex:poja)
::
2014-08-11 08:43:43 +04:00
++ pour-tweet :: tweet response
2014-08-11 07:49:56 +04:00
|= [pax=path sih=sign]
^- [(list move) _+>]
2014-08-11 08:43:43 +04:00
~& %pour-tweet
2014-08-11 07:49:56 +04:00
=+ ost=(slav %ud -.+.pax)
:_ +>.$
:~ [ost %give %nice ~]
2014-08-11 12:17:21 +04:00
[ost %pass /line %e [%them (some line:me)]]
2014-08-11 07:49:56 +04:00
==
2014-08-08 11:41:54 +04:00
--