shrub/lib/twitter.hoon

510 lines
13 KiB
Plaintext
Raw Normal View History

:: A Twitter API library.
::
:::: /hoon/twitter/lib
::
/? 314
2016-03-08 00:42:23 +03:00
/- twitter
/+ oauth1
=+ sur-twit:^twitter :: XX
!:
:::: functions
::
|%
++ fass :: rewrite path
2016-03-08 00:42:23 +03:00
|= a/path
2016-03-09 06:49:58 +03:00
%+ turn a
|=(b/@t (gsub '-' '_' b))
::
++ 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)
::
2016-03-09 07:25:44 +03:00
++ join
|= {a/char b/(list @t)} ^- @t
%+ rap 3
?~ b ~
|-(?~(t.b b [i.b a $(b t.b)]))
::
2016-03-09 05:44:43 +03:00
++ interpolate-some :: [/a/:b/c [d+'bar' b+'foo']~] -> [/a/foo/c [d+'bar']~]
|= {pax/path quy/quay} ^- {path quay}
=+ ^= inline :: required names
%- ~(gas in *(set term))
(murn pax replacable:interpolate-path)
=^ inter quy
(skid quy |=({a/knot @} (~(has in inline) a)))
[(interpolate-path pax inter) quy]
::
++ interpolate-path :: [/a/:b/c [%b 'foo']~] -> /a/foo/c
=+ replacable=|=(a/knot `(unit term)`(rush a ;~(pfix col sym)))
|= {a/path b/(list (pair term knot))} ^- path
?~ a ?~(b ~ ~|(unused-values+b !!))
=+ (replacable i.a)
?~ - [i.a $(a t.a)] :: literal value
?~ b ~|(no-value+u !!)
?. =(u p.i.b) ~|(mismatch+[u p.i.b] !!)
[q.i.b $(a t.a, b t.b)]
::
++ auth
%^ oauth1
'https://api.twitter.com/oauth/request_token'
'https://api.twitter.com/oauth/authorize'
'https://api.twitter.com/oauth/access_token'
::
++ valve :: produce request
2016-03-09 06:49:58 +03:00
|= $: med/?($get $post)
{pax/path quy/quay}
2016-03-08 00:42:23 +03:00
key/keys
bal/(bale keys:oauth1)
==
^- hiss
2016-03-09 23:52:57 +03:00
=+ url=(scan "https://api.twitter.com/1.1/.json" auri:epur) :: base path
2016-03-09 06:49:58 +03:00
=. q.q.url (welp q.q.url pax)
2016-03-09 23:52:57 +03:00
=. r.url quy
%^ ~(add-auth auth bal) sec.acc.key
[oauth-token+tok.acc.key]~
^- hiss
2016-03-09 06:49:58 +03:00
?- med
2016-03-09 23:52:57 +03:00
$get [url med *math ~]
2016-03-09 06:49:58 +03:00
$post
2016-03-09 23:52:57 +03:00
=+ hed=(~(add ja *math) %content-type 'application/x-www-form-urlencoded')
[url(r ~) med hed (some (tact +:(tail:earn r.url)))]
2016-03-09 06:49:58 +03:00
==
--
!:
:::: library
::
|%
2016-03-09 07:32:45 +03:00
++ render :: response printers
|%
++ mean
2016-03-08 04:38:01 +03:00
|= {msg/@t num/@ud} ^- tank
rose+[": " `~]^~[leaf+"Error {<num>}" leaf+(trip msg)]
--
2016-03-09 07:32:45 +03:00
++ parse :: json reparsers
|%
2016-03-08 04:38:01 +03:00
++ fasp |*(a/{@tas *} [(gsub '-' '_' -.a) +.a]) :: XX usable electroplating
++ 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
==
2016-03-08 04:38:01 +03:00
++ 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}
++ 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-09 07:25:44 +03:00
++ param :: (any) required param
$? at de fo gr id is la lo na oa os pl qq
sc sd ss sl si st te ti ts tr ur ui us
==
--
|_ {key/keys bal/(bale @)}
2016-03-09 07:25:44 +03:00
++ lutt |=(@u `@t`(rsh 3 2 (scot %ui +<)))
++ llsc
2016-03-09 07:25:44 +03:00
|= a/$@(scr (list scr)) ^- @t
?@(a `@t`a (join ',' a))
::
++ llst
2016-03-09 07:25:44 +03:00
|= a/$@(@t (list @t)) ^- @t
?@(a `@t`a (join ',' a))
::
++ llid
2016-03-09 07:25:44 +03:00
|= a/$@(tid (list tid)) ^- @t
?~ a ~|(%nil-id !!)
?@(a (lutt a) (join ',' (turn `(list tid)`a lutt)))
::
++ 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 bal)
::
++ cowl :: handle parameters
2016-03-08 00:42:23 +03:00
|= $: pax/path
2016-03-09 07:25:44 +03:00
ban/(list param)
2016-03-08 00:42:23 +03:00
quy/quay
==
2016-03-09 07:25:44 +03:00
^- {path quay}
%+ interpolate-some (fass pax)
=- (weld - quy)
%+ turn ban
|= p/param
2016-03-08 04:38:01 +03:00
^- {@t @t}
2016-03-09 07:25:44 +03:00
:- (gsub '-' '_' -.p)
?+ -.p p.p :: usually plain text
?($source-id $target-id) (lutt p.p)
?($follow $id $name $user-id) (llid p.p)
$track (llst p.p)
$screen-name (llsc p.p)
==
::
++ 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-09 07:25:44 +03:00
(mold %get /statuses/retweets/':id' {id $~})
::
++ stat-show
2016-03-08 00:42:23 +03:00
(mold %get /statuses/show {id $~})
::
++ stat-dest-iddd
2016-03-09 07:25:44 +03:00
(mold %post /statuses/destroy/':id' {id $~})
::
++ stat-upda
2016-03-08 00:42:23 +03:00
(mold %post /statuses/update {st $~})
::
++ stat-retw-iddd
2016-03-09 07:25:44 +03:00
(mold %post /statuses/retweet/':id' {id $~})
::
++ 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-09 07:25:44 +03:00
(mold %get /saved-searches/show/':id' {id $~})
::
++ save-crea
2016-03-08 00:42:23 +03:00
(mold %post /saved-searches/create {qq $~})
::
++ save-dest-iddd
2016-03-09 07:25:44 +03:00
(mold %post /saved-searches/destroy/':id' {id $~})
::
++ geoo-iddd-plac
2016-03-09 07:25:44 +03:00
(mold %get /geo/id/':id' {id $~})
::
++ 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 $~})
--
--