-USING: tools.test yahoo kernel io.files xml sequences accessors ;
+USING: tools.test yahoo kernel io.files xml sequences accessors urls ;
[ T{
result
"Official site with news, tour dates, discography, store, community, and more."
} ] [ "resource:extra/yahoo/test-results.xml" file>xml parse-yahoo first ] unit-test
-[ "http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=Factor-search&query=hi&results=2&similar_ok=1" ] [ "hi" <search> "Factor-search" >>appid 2 >>results t >>similar-ok query ] unit-test
+[ URL" http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=Factor-search&query=hi&results=2&similar_ok=1" ] [ "hi" <search> "Factor-search" >>appid 2 >>results t >>similar-ok query ] unit-test
! Copyright (C) 2006 Daniel Ehrenberg, Walton Chan
! See http://factorcode.org/license.txt for BSD license.
USING: http.client xml xml.utilities kernel sequences
-namespaces http math.parser help math.order locals
-urls accessors ;
+math.parser urls accessors locals ;
IN: yahoo
TUPLE: result title url summary ;
C: <result> result
-
+
TUPLE: search query results adult-ok start appid region type
format similar-ok language country site subscription license ;
] map ;
: yahoo-url ( -- str )
- "http://search.yahooapis.com/WebSearchService/V1/webSearch" ;
+ URL" http://search.yahooapis.com/WebSearchService/V1/webSearch" ;
-: param ( search str quot -- search )
- >r over r> call [ url-encode [ % ] bi@ ] [ drop ] if* ;
- inline
+:: param ( search url name quot -- search url )
+ search url search quot call
+ [ name set-query-param ] when* ; inline
: num-param ( search str quot -- search )
[ dup [ number>string ] when ] compose param ; inline
[ "1" and ] compose param ; inline
: query ( search -- url )
- [
- yahoo-url %
- "?appid=" [ appid>> ] param
- "&query=" [ query>> ] param
- "®ion=" [ region>> ] param
- "&type=" [ type>> ] param
- "&format=" [ format>> ] param
- "&language=" [ language>> ] param
- "&country=" [ country>> ] param
- "&site=" [ site>> ] param
- "&subscription=" [ subscription>> ] param
- "&license=" [ license>> ] param
- "&results=" [ results>> ] num-param
- "&start=" [ start>> ] num-param
- "&adult_ok=" [ adult-ok>> ] bool-param
- "&similar_ok=" [ similar-ok>> ] bool-param
- drop
- ] "" make ;
+ yahoo-url clone
+ "appid" [ appid>> ] param
+ "query" [ query>> ] param
+ "region" [ region>> ] param
+ "type" [ type>> ] param
+ "format" [ format>> ] param
+ "language" [ language>> ] param
+ "country" [ country>> ] param
+ "site" [ site>> ] param
+ "subscription" [ subscription>> ] param
+ "license" [ license>> ] param
+ "results" [ results>> ] num-param
+ "start" [ start>> ] num-param
+ "adult_ok" [ adult-ok>> ] bool-param
+ "similar_ok" [ similar-ok>> ] bool-param
+ nip ;
: factor-id
"fRrVAKzV34GDyeRw6bUHDhEWHRedwfOC7e61wwXZLgGF80E67spxdQXuugBe2pgIevMmKwA-" ;