! Copyright (C) 2010 Gertm. ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs http.client io json.reader kernel prettyprint sequences ; IN: twitsearch CONSTANT: searchurl "http://search.twitter.com/search.json?q=" : make-json ( response data -- x ) nip json> ; : get-tweet-hsh ( x -- x ) "results" swap at ; : search ( string -- x ) searchurl prepend http-get make-json get-tweet-hsh ; : print-with-prefix ( prefix string -- ) append print ; : twt-print-field ( hsh field prefix -- ) [ swap at ] dip print-with-prefix ; : twt-print-from ( x -- ) "from_user" "From: " twt-print-field ; : twt-print-text ( x -- ) "text" ">> " twt-print-field ; : tweet ( x -- ) [ twt-print-from ] [ twt-print-text ] bi ; : results ( x -- ) search [ tweet ] each ;