! Copyright (C) 2010 Gertm. ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs http.client io json.reader kernel sequences ; IN: twitsearch : makejson ( response data -- x ) drop body>> json> ; : get-tweet-hsh ( x -- x ) "results" swap at ; : search ( string -- x ) "http://search.twitter.com/search.json?q=" swap append http-get makejson get-tweet-hsh ; : print-with-prefix ( prefix string -- ) append print ; : twt-print-field ( hsh field prefix -- ) -rot swap at 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 ;