urbit/lib/twitter.hoon

506 lines
12 KiB
Plaintext
Raw Normal View History

:: A Twitter API library.
::
:::: /hoon/twitter/lib
::
/? 314
2016-03-08 00:42:23 +03:00
/- twitter
/+ oauth1
=+ oauth1=oauth1
=+ sur-twit:^twitter :: XX
!:
:::: functions
::
|%
++ fass :: rewrite path
2016-03-08 00:42:23 +03:00
|= a/path
%- trip
%^ gsub '-' '_'
%+ reel a
2016-03-08 00:42:23 +03:00
|= {p/@t q/@t}
(cat 3 '/' (cat 3 p q))
::
++ gsub :: replace chars
2016-03-08 00:42:23 +03:00
|= {a/@t b/@t t/@t}
^- @t
2016-03-08 00:42:23 +03:00
?: =('' t) t
%+ mix (lsh 3 1 $(t (rsh 3 1 t)))
=+ c=(end 3 1 t)
?:(=(a c) b c)
::
++ valve :: produce request
2016-03-08 00:42:23 +03:00
|= $: med/meth
{rus/tape quy/quay}
key/keys
est/time
eny/@
==
^- hiss
=+ url="https://api.twitter.com/1.1{rus}.json"
2016-03-08 00:42:23 +03:00
=+ req=|=(a/tape (scan a auri:epur))
=+ ^= help
2016-03-08 00:42:23 +03:00
|= quy/(list {tape tape})
^- (list tape)
%+ turn quy
2016-03-08 00:42:23 +03:00
|= a/{p/tape q/tape}
:(weld (urle p.a) "=" (urle q.a))
2016-03-08 00:42:23 +03:00
=+ tan=(turn quy |=({p/@t q/@t} [(trip p) (trip q)]))
=+ har=(help (turn tan |=(p/{p/tape q/tape} [p.p (urle q.p)])))
=+ hab=(help tan)
2016-03-08 00:42:23 +03:00
=+ lav=(reel har |=({p/tape q/tape} :(weld p "&" q)))
=+ voy=?:(=(0 (lent lav)) ~ (scag (dec (lent lav)) `tape`lav))
2016-03-08 00:42:23 +03:00
=+ vab=(reel hab |=({p/tape q/tape} :(weld p "&" q)))
=+ vur=(crip ?:(=(0 (lent vab)) ~ (scag (dec (lent vab)) `tape`vab)))
=+ ^= head
%- ~(gas by *math)
2016-03-08 00:42:23 +03:00
~! ^twitter
~! oauth1:^twitter
2016-03-07 22:05:37 +03:00
:~ ['authorization' [(oauth1 med url hab key est eny) ~]]
['content-type' ['application/x-www-form-urlencoded' ~]]
==
?: =(%get med)
?~ voy
[(req url) med head ~]
[(req :(weld url "?" voy)) med head ~]
[(req url) med head (some [(met 3 vur) vur])]
--
!:
:::: library
::
|%
++ twip :: response printers
|%
++ mean
|= [msg=@t num=@ud] ^- tank
rose/[": " `~]^~[leaf/"Error {<num>}" leaf/(trip msg)]
--
++ twir :: response parsers
|%
2016-03-08 00:42:23 +03:00
++ fasp |*({a/@tas b/*} [(gsub '-' '_' a) b])
++ user (cook crip (plus ;~(pose aln cab)))
2016-03-08 00:42:23 +03:00
++ mean (ot errors+(ar (ot message+so code+ni ~)) ~):jo
++ stat
=+ jo
2016-03-08 00:42:23 +03:00
^- $-(json (unit {id+@u who+@ta now+@da txt+@t}))
%- ot
2016-03-08 00:42:23 +03:00
:~ id+ni
user+(ot (fasp screen-name+(su user)) ~)
(fasp created-at+da)
text+so
==
++ usel
=+ jo
2016-03-08 00:42:23 +03:00
^- $-(json (unit (list who/@ta)))
=- (ot users+(ar -) ~)
(ot (fasp screen-name+(su user)) ~)
--
2016-03-07 22:05:37 +03:00
++ main
=> |% :: request structures
2016-03-08 00:42:23 +03:00
++ dev @t :: device name
++ gat @t :: grant type
++ lat @t :: latitude
++ lid (list tid)
2016-03-08 00:42:23 +03:00
++ lon @t :: longitude
++ lsc (list scr)
2016-03-08 00:42:23 +03:00
++ lst (list @t)
++ nam @t :: location name
++ pla @t :: place-id
++ scr @t :: screen name
++ slu @t :: category name
++ tid @u
++ tok @t :: oauth token
++ url @t :: callback url
::
2016-03-08 00:42:23 +03:00
++ at {$access-token p/tok}
++ de {$device p/dev}
++ fo {$follow p/lid}
++ gr {$grant-type p/gat}
++ id {$id p/tid}
++ ii {$'!inline' p/@t}
++ is {$id p/lid}
++ la {$lat p/lat}
++ lo {$long p/lon}
++ na {$name p/lid}
++ oa {$oauth-callback p/url}
++ os {$source-screen-name p/scr}
++ pl {$place-id p/pla}
++ qq {$q p/@t}
++ sc {$screen-name p/scr}
++ sd ?(ui sc)
2016-03-08 00:42:23 +03:00
++ ss {$screen-name p/lsc}
++ sl {$slug p/slu}
++ si {$source-id p/tid}
++ st {$status p/@t}
++ te {$text p/@t}
++ ti {$target-id p/tid}
++ ts {$target-screen-name p/scr}
++ tr {$track p/lst}
++ ur {$url p/url}
++ ui {$user-id p/tid}
++ us {$user-id p/lid}
--
2016-03-08 00:42:23 +03:00
|_ {key/keys est/time eny/@uw}
++ lutt |=(@ `@t`(rsh 3 2 (scot %ui +<)))
++ llsc
|= (list scr)
2016-03-08 00:42:23 +03:00
(roll +< |=({p/scr q/@t} (cat 3 (cat 3 q ',') p)))
::
++ llst
2016-03-08 00:42:23 +03:00
|= (list @t)
(roll +< |=({p/@t q/@t} (cat 3 (cat 3 q ',') p)))
::
++ llid
|= (list tid)
2016-03-08 00:42:23 +03:00
(roll +< |=({p/tid q/@t} (cat 3 (cat 3 q ',') (lutt p))))
::
++ mold :: construct request
2016-03-08 00:42:23 +03:00
|* {med/meth pax/path a/$-(* *)}
|= {args/a quy/quay}
(valve med (cowl pax args quy) key est eny)
::
++ cowl :: handle parameters
2016-03-08 00:42:23 +03:00
|= $: pax/path
ban/(list {p/@t q/?(@ (list @))})
quy/quay
==
^- [path quay]
?~ ban
[(fass pax) quy]
?: =('!inline' p.i.ban)
?@ q.i.ban
[(fass (welp pax /[`@t`q.i.ban])) quy]
!!
:- (fass pax)
%+ welp quy
2016-03-08 00:42:23 +03:00
%+ turn `(list {p/@t q/?(@ (list @))})`ban
|= {p/@t q/?(@ (list @))}
^- [@t @t]
:- (gsub '-' '_' p)
?@ q
?- p
2016-03-08 00:42:23 +03:00
?($id $source-id $target-id $user-id) (lutt q)
@ `@t`q
==
?- p
2016-03-08 00:42:23 +03:00
?($follow $id $name $user-id) (llid q)
$track (llst q)
$screen-name (llsc q)
* !!
==
::
++ stat-ment
2016-03-08 00:42:23 +03:00
(mold %get /statuses/mentions-timeline $~)
::
++ stat-user
2016-03-08 00:42:23 +03:00
(mold %get /statuses/user-timeline {sd $~})
::
++ stat-home
2016-03-08 00:42:23 +03:00
(mold %get /statuses/home-timeline $~)
::
++ stat-retw
2016-03-08 00:42:23 +03:00
(mold %get /statuses/retweets-of-me $~)
::
++ stat-rets-iddd
2016-03-08 00:42:23 +03:00
(mold %get /statuses/retweets {ii $~})
::
++ stat-show
2016-03-08 00:42:23 +03:00
(mold %get /statuses/show {id $~})
::
++ stat-dest-iddd
2016-03-08 00:42:23 +03:00
(mold %post /statuses/destroy {ii $~})
::
++ stat-upda
2016-03-08 00:42:23 +03:00
(mold %post /statuses/update {st $~})
::
++ stat-retw-iddd
2016-03-08 00:42:23 +03:00
(mold %post /statuses/retweet {ii $~})
::
++ stat-oemb-iddd
2016-03-08 00:42:23 +03:00
(mold %get /statuses/oembed {id $~})
::
++ stat-oemb-urll
2016-03-08 00:42:23 +03:00
(mold %get /statuses/oembed {ur $~})
::
++ stat-retw-idss
2016-03-08 00:42:23 +03:00
(mold %get /statuses/retweeters/ids {id $~})
::
++ sear-twee
2016-03-08 00:42:23 +03:00
(mold %get /search/tweets {qq $~})
::
++ stat-filt-foll
2016-03-08 00:42:23 +03:00
(mold %post /statuses/filter {?(fo tr) $~})
::
++ stat-samp
2016-03-08 00:42:23 +03:00
(mold %get /statuses/sample $~)
::
++ stat-fire
2016-03-08 00:42:23 +03:00
(mold %get /statuses/firehose $~)
::
++ user
2016-03-08 00:42:23 +03:00
(mold %get /user $~)
::
++ site
2016-03-08 00:42:23 +03:00
(mold %get /site {fo $~})
::
++ dire
2016-03-08 00:42:23 +03:00
(mold %get /direct-messages $~)
::
++ dire-sent
2016-03-08 00:42:23 +03:00
(mold %get /direct-messages/sent $~)
::
++ dire-show
2016-03-08 00:42:23 +03:00
(mold %get /direct-messages/show {id $~})
::
++ dire-dest
2016-03-08 00:42:23 +03:00
(mold %post /direct-messages/destroy {id $~})
::
++ dire-neww
2016-03-08 00:42:23 +03:00
(mold %post /direct-messages/new {sd te $~})
::
++ frie-nore-idss
2016-03-08 00:42:23 +03:00
(mold %get /friendships/no-retweets/ids $~)
::
++ frie-idss
2016-03-08 00:42:23 +03:00
(mold %get /friends/ids {sd $~})
::
++ foll-idss
2016-03-08 00:42:23 +03:00
(mold %get /followers/ids {sd $~})
::
++ frie-inco
2016-03-08 00:42:23 +03:00
(mold %get /friendships/incoming $~)
::
++ frie-outg
2016-03-08 00:42:23 +03:00
(mold %get /friendships/outgoing $~)
::
++ frie-crea
2016-03-08 00:42:23 +03:00
(mold %post /friendships/create {sd $~})
::
++ frie-dest
2016-03-08 00:42:23 +03:00
(mold %post /friendships/destroy {sd $~})
::
++ frie-upda
2016-03-08 00:42:23 +03:00
(mold %post /friendships/update {sd $~})
::
++ frie-show
2016-03-08 00:42:23 +03:00
(mold %get /friendships/show {?(si os) ?(ti ts) $~})
::
++ frie-list
2016-03-08 00:42:23 +03:00
(mold %get /friends/list {sd $~})
::
++ foll-list
2016-03-08 00:42:23 +03:00
(mold %get /followers/list {sd $~})
::
++ frie-look
2016-03-08 00:42:23 +03:00
(mold %get /friendships/lookup {?(us ss) $~})
::
++ acco-sett-gett
2016-03-08 00:42:23 +03:00
(mold %get /account/settings $~)
::
++ acco-veri
2016-03-08 00:42:23 +03:00
(mold %get /account/verify-credentials $~)
::
++ acco-sett-post
2016-03-08 00:42:23 +03:00
(mold %post /account/settings $~)
::
++ acco-upda-deli
2016-03-08 00:42:23 +03:00
(mold %post /account/update-delivery-device {de $~})
::
++ acco-upda-prof
2016-03-08 00:42:23 +03:00
(mold %post /account/update-profile $~)
::
++ acco-upda-prof-back
2016-03-08 00:42:23 +03:00
(mold %post /account/update-profile-background-image $~)
::
++ acco-upda-prof-colo
2016-03-08 00:42:23 +03:00
(mold %post /account/update-profile-colors $~)
::
++ bloc-list
2016-03-08 00:42:23 +03:00
(mold %get /blocks/list $~)
::
++ bloc-idss
2016-03-08 00:42:23 +03:00
(mold %get /blocks/ids $~)
::
++ bloc-crea
2016-03-08 00:42:23 +03:00
(mold %post /blocks/create {sd $~})
::
++ bloc-dest
2016-03-08 00:42:23 +03:00
(mold %post /blocks/destroy {sd $~})
::
++ user-look
2016-03-08 00:42:23 +03:00
(mold %get /users/lookup {?(us ss) $~})
::
++ user-show
2016-03-08 00:42:23 +03:00
(mold %get /users/show {sd $~})
::
++ user-sear
2016-03-08 00:42:23 +03:00
(mold %get /users/search {qq $~})
::
++ user-cont-tees
2016-03-08 00:42:23 +03:00
(mold %get /users/contributees {sd $~})
::
++ user-cont-tors
2016-03-08 00:42:23 +03:00
(mold %get /users/contributors {sd $~})
::
++ acco-remo
2016-03-08 00:42:23 +03:00
(mold %post /account/remove-profile-banner $~)
::
++ user-prof
2016-03-08 00:42:23 +03:00
(mold %get /users/profile-banner {sd $~})
::
++ mute-user-crea
2016-03-08 00:42:23 +03:00
(mold %post /mutes/users/create {sd $~})
::
++ mute-user-dest
2016-03-08 00:42:23 +03:00
(mold %post /mutes/users/destroy {sd $~})
::
++ mute-user-idss
2016-03-08 00:42:23 +03:00
(mold %get /mutes/users/ids $~)
::
++ mute-user-list
2016-03-08 00:42:23 +03:00
(mold %get /mutes/users/list $~)
::
++ user-sugg-slug
2016-03-08 00:42:23 +03:00
(mold %get /users/suggestions {sl $~})
::
++ user-sugg
2016-03-08 00:42:23 +03:00
(mold %get /users/suggestions $~)
::
++ favo-list
2016-03-08 00:42:23 +03:00
(mold %get /favorites/list $~)
::
++ favo-dest
2016-03-08 00:42:23 +03:00
(mold %post /favorites/destroy {id $~})
::
++ favo-crea
2016-03-08 00:42:23 +03:00
(mold %post /favorites/create {id $~})
::
++ list-list
2016-03-08 00:42:23 +03:00
(mold %get /lists/list $~)
::
++ list-stat
2016-03-08 00:42:23 +03:00
(mold %get /lists/statuses $~)
::
++ list-memb-dest
2016-03-08 00:42:23 +03:00
(mold %post /lists/members/destroy $~)
::
++ list-memb-hips
2016-03-08 00:42:23 +03:00
(mold %get /lists/memberships {sd $~})
::
++ list-subs-bers
2016-03-08 00:42:23 +03:00
(mold %get /lists/subscribers $~)
::
++ list-subs-crea
2016-03-08 00:42:23 +03:00
(mold %post /lists/subscribers/create $~)
::
++ list-subs-show
2016-03-08 00:42:23 +03:00
(mold %get /lists/subscribers/show {sd $~})
::
++ list-subs-dest
2016-03-08 00:42:23 +03:00
(mold %post /lists/subscribers/destroy $~)
::
++ list-memb-crea-alll
2016-03-08 00:42:23 +03:00
(mold %post /lists/members/create-all {?(us ss) $~})
::
++ list-memb-show
2016-03-08 00:42:23 +03:00
(mold %get /lists/members/show {sd $~})
::
++ list-memb-bers
2016-03-08 00:42:23 +03:00
(mold %get /lists/members $~)
::
++ list-memb-crea
2016-03-08 00:42:23 +03:00
(mold %post /lists/members/create {sd $~})
::
++ list-dest
2016-03-08 00:42:23 +03:00
(mold %post /lists/destroy $~)
::
++ list-upda
2016-03-08 00:42:23 +03:00
(mold %post /lists/update $~)
::
++ list-crea
2016-03-08 00:42:23 +03:00
(mold %post /lists/create {na $~})
::
++ list-show
2016-03-08 00:42:23 +03:00
(mold %get /lists/show $~)
::
++ list-subs-ions
2016-03-08 00:42:23 +03:00
(mold %get /lists/subscriptions {sd $~})
::
++ list-memb-dest-alll
2016-03-08 00:42:23 +03:00
(mold %post /lists/members/destroy-all {?(us ss) $~})
::
++ list-owne
2016-03-08 00:42:23 +03:00
(mold %get /lists/ownerships {sd $~})
::
++ save-list
2016-03-08 00:42:23 +03:00
(mold %get /saved-searches/list $~)
::
++ save-show-iddd
2016-03-08 00:42:23 +03:00
(mold %get /saved-searches/show {ii $~})
::
++ save-crea
2016-03-08 00:42:23 +03:00
(mold %post /saved-searches/create {qq $~})
::
++ save-dest-iddd
2016-03-08 00:42:23 +03:00
(mold %post /saved-searches/destroy {ii $~})
::
++ geoo-iddd-plac
2016-03-08 00:42:23 +03:00
(mold %get /geo/id {ii $~})
::
++ geoo-reve
2016-03-08 00:42:23 +03:00
(mold %get /geo/reverse-geocode {la lo $~})
::
++ geoo-sear
2016-03-08 00:42:23 +03:00
(mold %get /geo/search $~)
::
++ geoo-simi
2016-03-08 00:42:23 +03:00
(mold %get /geo/similar-places {la lo na $~})
::
++ tren-plac
2016-03-08 00:42:23 +03:00
(mold %get /trends/place {id $~})
::
++ tren-avai
2016-03-08 00:42:23 +03:00
(mold %get /trends/available $~)
::
++ tren-clos
2016-03-08 00:42:23 +03:00
(mold %get /trends/closest {la lo $~})
::
++ user-repo
2016-03-08 00:42:23 +03:00
(mold %post /users/report-spam {sd $~})
::
++ oaut-auth-cate
2016-03-08 00:42:23 +03:00
(mold %get /oauth/authenticate $~)
::
++ oaut-auth-rize
2016-03-08 00:42:23 +03:00
(mold %get /oauth/authorize $~)
::
++ oaut-acce
2016-03-08 00:42:23 +03:00
(mold %post /oauth/access-token $~)
::
++ oaut-requ
2016-03-08 00:42:23 +03:00
(mold %post /oauth/request-token {oa $~})
::
++ oaut-toke
2016-03-08 00:42:23 +03:00
(mold %post /oauth2/token {gr $~})
::
++ oaut-inva
2016-03-08 00:42:23 +03:00
(mold %post /oauth2/invalidate-token {at $~})
::
++ help-conf
2016-03-08 00:42:23 +03:00
(mold %get /help/configuration $~)
::
++ help-lang
2016-03-08 00:42:23 +03:00
(mold %get /help/languages $~)
::
++ help-priv
2016-03-08 00:42:23 +03:00
(mold %get /help/privacy $~)
::
++ help-toss
2016-03-08 00:42:23 +03:00
(mold %get /help/tos $~)
::
++ appl-rate
2016-03-08 00:42:23 +03:00
(mold %get /application/rate-limit-status $~)
::
++ stat-look
2016-03-08 00:42:23 +03:00
(mold %get /statuses/lookup {us $~})
--
--