minor refactoring

This commit is contained in:
Anton Dyudin 2016-03-07 11:05:37 -08:00
parent 5f44ec53b3
commit 27aa5392e6
4 changed files with 67 additions and 71 deletions

View File

@ -2,12 +2,10 @@
::
:::: /hook/core/twit/app
::
/- twitter
/+ twitter, talk
::
:::: ~fyr
::
[twitter .]
|%
++ twit-path :: valid peer path
$% :: [%home ~] :: home timeline
@ -17,7 +15,7 @@
::
++ axle :: app state
$: %0
kes=(map span keys:twit-do) :: auth
kes=(map span keys:twittter) :: auth
out=(map ,@uvI (each ,[span cord] stat)) :: sent tweets
ran=(map path ,[p=@ud q=@da]) :: polls active
fed=(jar path stat) :: feed cache
@ -46,7 +44,8 @@
[%t %wake ~] :: timeout ping
==
::
++ stat twit-stat :: recieved tweet
++ stat stat:twitter :: recieved tweet
++ twit main:twitter :: api interface
--
!:
::::
@ -86,19 +85,19 @@
mof
::
++ poke-twit-do :: recieve request
|= act=twit-do
|= [usr=span act=command:twitter]
^+ [*(list move) +>]
?- -.q.act
?- -.act
%auth
:- [(print "authed @{(trip p.act)}")]~
+>.$(kes (~(put by kes) p.act p.q.act)) :: XX verify key
:- [(print "authed @{(trip usr)}")]~
+>.$(kes (~(put by kes) usr p.act)) :: XX verify key
%post
=: out (~(put by out) p.q.act %& p.act q.q.act)
=: out (~(put by out) p.act %& usr q.act)
ran (~(del by ran) /peer/home)
==
%+ wait /peer/home
=+ mez=(stat-upda:(auth p.act) [%status q.q.act]~ ~)
[ost %them /post/(scot %uv p.q.act) ~ mez]~
=+ mez=(stat-upda:(auth usr) [%status q.act]~ ~)
[ost %them /post/(scot %uv p.act) ~ mez]~
==
::
++ wake-peer

42
lib/oauth1.hoon Normal file
View File

@ -0,0 +1,42 @@
++ oauth :: OAuth 1.0 header
|= $: med=meth
url=tape
pas=(list tape)
key=keys
zet=@
ken=@
==
^- @t
=+ non=(turn (rip 2 (shaw zet 128 ken)) |=(a=@ ~(x ne a)))
=+ tim=(slag 2 (scow %ui (unt zet)))
=+ sky=(crip :(weld (urle (trip sec.con.key)) "&" (urle (trip sec.acc.key))))
=+ ^= bas
^- tape
=+ ^= hds
%- reel :_ |=([p=tape q=tape] :(weld p "&" q))
%- sort :_ aor
%- weld :- pas
^- (list tape)
:~ :(weld "oauth_consumer_key=" (trip tok.con.key))
:(weld "oauth_nonce=" non)
:(weld "oauth_signature_method=HMAC-SHA1")
:(weld "oauth_timestamp=" tim)
:(weld "oauth_token=" (trip tok.acc.key))
:(weld "oauth_version=1.0")
==
;: weld
(trip (cuss (trip `@t`med))) "&"
(urle url) "&"
(urle (scag (dec (lent hds)) `tape`hds))
==
=+ sig=`tape`(sifo (swap 3 (hmac (swap 3 sky) (crip bas))))
%- crip
;: weld "OAuth "
"oauth_consumer_key=" "\"" (trip tok.con.key) "\", "
"oauth_nonce=" "\"" non "\", "
"oauth_signature=" "\"" (urle sig) "\", "
"oauth_signature_method=\"HMAC-SHA1\", "
"oauth_timestamp=" "\"" tim "\", "
"oauth_token=" "\"" (trip tok.acc.key) "\", "
"oauth_version=1.0"
==

View File

@ -4,7 +4,8 @@
::
/? 314
/- twitter
=+ twit:twitter
/+ oauth1
=+ sur-twit:^twitter :: XX
!:
:::: functions
::
@ -25,49 +26,6 @@
=+ c=(mod t (bex 8))
?:(=(a c) b c)
::
++ oauth :: OAuth 1.0 header
|= $: med=meth
url=tape
pas=(list tape)
key=keys
zet=@
ken=@
==
^- @t
=+ non=(turn (rip 2 (shaw zet 128 ken)) |=(a=@ ~(x ne a)))
=+ tim=(slag 2 (scow %ui (unt zet)))
=+ sky=(crip :(weld (urle (trip sec.con.key)) "&" (urle (trip sec.acc.key))))
=+ ^= bas
^- tape
=+ ^= hds
%- reel :_ |=([p=tape q=tape] :(weld p "&" q))
%- sort :_ aor
%- weld :- pas
^- (list tape)
:~ :(weld "oauth_consumer_key=" (trip tok.con.key))
:(weld "oauth_nonce=" non)
:(weld "oauth_signature_method=HMAC-SHA1")
:(weld "oauth_timestamp=" tim)
:(weld "oauth_token=" (trip tok.acc.key))
:(weld "oauth_version=1.0")
==
;: weld
(trip (cuss (trip `@t`med))) "&"
(urle url) "&"
(urle (scag (dec (lent hds)) `tape`hds))
==
=+ sig=`tape`(sifo (swap 3 (hmac (swap 3 sky) (crip bas))))
%- crip
;: weld "OAuth "
"oauth_consumer_key=" "\"" (trip tok.con.key) "\", "
"oauth_nonce=" "\"" non "\", "
"oauth_signature=" "\"" (urle sig) "\", "
"oauth_signature_method=\"HMAC-SHA1\", "
"oauth_timestamp=" "\"" tim "\", "
"oauth_token=" "\"" (trip tok.acc.key) "\", "
"oauth_version=1.0"
==
::
++ valve :: produce request
|= $: med=meth
[rus=tape quy=quay]
@ -93,7 +51,7 @@
=+ vur=(crip ?:(=(0 (lent vab)) ~ (scag (dec (lent vab)) `tape`vab)))
=+ ^= head
%- ~(gas by *math)
:~ ['authorization' [(oauth med url hab key est eny) ~]]
:~ ['authorization' [(oauth1 med url hab key est eny) ~]]
['content-type' ['application/x-www-form-urlencoded' ~]]
==
?: =(%get med)
@ -132,7 +90,7 @@
=- (ot users/(ar -) ~)
(ot (fasp screen-name/(su user)) ~)
--
++ twit
++ main
=> |% :: request structures
++ dev ,@t :: device name
++ gat ,@t :: grant type

View File

@ -1,16 +1,13 @@
|%
++ twit-do => twit ,[p=span q=command] :: user and action
++ twit-stat ,[id=@u who=@ta now=@da txt=@t] :: recieved tweet
++ twit
|%
++ keys :: twitter-key type
$: con=[tok=@t sec=@t] :: user key pair
acc=[tok=@t sec=@t] :: app key pair
==
::
++ command :: poke action
$% [%auth p=keys] :: set API keys
[%post p=@uvI q=cord] :: post a tweet
==
--
++ stat ,[id=@u who=@ta now=@da txt=@t] :: recieved tweet
++ keys :: twitter-key type
$: con=[tok=@t sec=@t] :: user key pair
acc=[tok=@t sec=@t] :: app key pair
==
::
++ command :: poke action
$% [%auth p=keys] :: set API keys
[%post p=@uvI q=cord] :: post a tweet
==
++ sur-twit . :: XX
--