]> gitweb.factorcode.org Git - factor.git/commitdiff
Yahoo updates
authorDaniel Ehrenberg <littledan@pool-226-177.res.carleton.edu>
Sun, 1 Jun 2008 06:23:11 +0000 (01:23 -0500)
committerDaniel Ehrenberg <littledan@pool-226-177.res.carleton.edu>
Sun, 1 Jun 2008 06:23:11 +0000 (01:23 -0500)
extra/yahoo/authors.txt
extra/yahoo/summary.txt
extra/yahoo/yahoo-tests.factor
extra/yahoo/yahoo.factor

index f990dd0ed29ff1ada6887e18c53cbca2d40a2481..382fc3fc0970e6c2c62345a8470a1000771d662f 100644 (file)
@@ -1 +1,2 @@
 Daniel Ehrenberg
+Walton Chan
index 662369d96e92dfa6d724799018c1f9f95239bc31..98287365af5eebd5839b756f82e9e6913e766277 100644 (file)
@@ -1 +1 @@
-Yahoo! search example using XML-RPC
+Yahoo! search example using XML
index dc684af726c83d374c9c87aac46c8f964149eca3..3776715c7b67801f393162a0614aaf3b492cfe63 100644 (file)
@@ -1,4 +1,4 @@
-USING: tools.test yahoo kernel io.files xml sequences ;
+USING: tools.test yahoo kernel io.files xml sequences accessors ;
 
 [ T{
     result
@@ -8,4 +8,4 @@ USING: tools.test yahoo kernel io.files xml sequences ;
     "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=1" ] [ "hi" 1 "Factor-search" query ] 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
index 214ad04979e0c667a58824870a2cbb043b217bea..dd7ce962c23888071392aae0e7ada08f0f8da1fd 100755 (executable)
@@ -1,12 +1,15 @@
-! Copyright (C) 2006 Daniel Ehrenberg
+! 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 ;
+namespaces http math.parser help math.order locals accessors ;
 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 ;
 
 : parse-yahoo ( xml -- seq )
     "Result" deep-tags-named [
@@ -18,19 +21,44 @@ C: <result> result
 : yahoo-url ( -- str )
     "http://search.yahooapis.com/WebSearchService/V1/webSearch" ;
 
-:: query ( search num appid -- url )
+: param ( search str quot -- search )
+    >r over r> call [ url-encode [ % ] bi@ ] [ drop ] if* ;
+    inline
+
+: num-param ( search str quot -- search )
+    [ dup [ number>string ] when ] compose param ; inline
+
+: bool-param ( search str quot -- search )
+    [ "1" and ] compose param ; inline
+
+: query ( search -- url )
     [
-        yahoo-url %
-        "?appid=" % appid %
-        "&query=" % search url-encode %
-        "&results=" % num #
+        yahoo-url %     
+        "?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
+        drop
     ] "" make ;
 
 : factor-id
     "fRrVAKzV34GDyeRw6bUHDhEWHRedwfOC7e61wwXZLgGF80E67spxdQXuugBe2pgIevMmKwA-" ;
 
-: search-yahoo/id ( search num id -- seq )
-    query http-get string>xml parse-yahoo ;
+: <search> ( query -- search )
+    search new
+        factor-id >>appid
+        10 >>results
+        swap >>query ;
 
-: search-yahoo ( search num -- seq )
-    factor-id search-yahoo/id ;
+: search-yahoo ( search -- seq )
+    query http-get string>xml parse-yahoo ;