hunk ./src/Test/Last.hs 34 -fetchJSON url = do - (_,s) <- curlGetString url [] - eitherToIO (runGetJSON readJSValue s) - -prettyFetchJSON url = print . pp_value =<< fetchJSON url +prettyFetchJSON url = print . pp_value =<< eitherToIO =<< fetchJSON url hunk ./src/Web/Last/Request.hs 72 +fetchJSON :: String -> IO (Either String JSValue) +fetchJSON targetUrl = do + (_,s) <- curlGetString targetUrl [] -- Should test for curl errors here? + return $ case (runGetJSON readJSValue s) of + Left e -> Left (e ++ "\n\nReading json string:\n\n" ++ s ++ "\n\nFrom url: " ++ targetUrl) + Right js -> Right js + hunk ./src/Web/Last/Request.hs 82 - (_,s) <- liftIO $ curlGetString (url m k p op) [] -- Should test for curl errors here? - raiseEither $ apply (errorOrValue marshal) =<< runGetJSON readJSValue s + js <- liftIO $ fetchJSON (url m k p op) + raiseEither $ apply (errorOrValue marshal) =<< js hunk ./src/Test/Last.hs 22 +import qualified Web.Last.Tasteometer as Tasteometer addfile ./src/Web/Last/Tasteometer.hs hunk ./src/Web/Last/Tasteometer.hs 1 - +module Web.Last.Tasteometer where + +import Control.Applicative +import Control.Arrow + +import Web.Last.Types +import Web.Last.Request +import qualified Web.Last.Parsing as P +import Text.JSON.Combinators + +import Data.List (intercalate) + +data TasteArg = + ArgUser String -- username + | ArgArtists [String] -- artist names + | ArgMySpace String -- myspace url (of user?) + +formatArgs :: Int -> TasteArg -> [(String,String)] +formatArgs i (ArgUser userName) = [("type" ++ show i, "user"),("value" ++ show i, userName)] +formatArgs i (ArgArtists artistNames) = [("type" ++ show i, "artists"),("value" ++ show i, intercalate "," artistNames)] +formatArgs i (ArgMySpace url) = [("type" ++ show i, "myspace"),("value" ++ show i, url)] + +-- String is correlation between args +compare :: TasteArg -> TasteArg -> Int -> Last (String,[(Artist,[Image])]) +compare arg1 arg2 limit = anonRequest "tasteometer.compare" (formatArgs 1 arg1 ++ formatArgs 2 arg2 ++ [("limit",show limit)]) [] pa + where pa = objOf $ inObj "comparison" $ inObj "result" $ (ll "score" strJS) &&& sharedArtists + sharedArtists = inObj "artists" $ llArr "artist" (P.artist &&& (objOf $ llArr "image" P.image))