flickr 0.2.1 → 0.2.2
raw patch · 5 files changed
+103/−2 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Flickr.Monad: eiArg :: String -> String -> Either String String -> [(String, String)] -> [(String, String)]
+ Flickr.Places: getChildrenWithPhotosPublic :: Either PlaceID WhereOnEarthID -> FM (PlaceQuery, [Place])
+ Flickr.Places: getInfo :: Either PlaceID WhereOnEarthID -> FM LocationPlace
+ Flickr.Places: getInfoByUrl :: URLString -> FM LocationPlace
+ Flickr.Test: echo :: [(String, String)] -> FM [(String, String)]
+ Flickr.Test: login :: FM User
+ Flickr.Test: nullTest :: FM ()
Files
- Flickr/Monad.hs +8/−0
- Flickr/Places.hs +22/−0
- Flickr/Test.hs +48/−0
- Util/Fetch.hs +23/−1
- flickr.cabal +2/−1
Flickr/Monad.hs view
@@ -157,6 +157,14 @@ mbArg _ Nothing xs = xs mbArg t (Just a) xs = (t,a):xs +eiArg :: String + -> String + -> Either String String + -> [(String,String)] + -> [(String,String)] +eiArg t _ (Left x) xs = (t,x):xs +eiArg _ t (Right x) xs = (t,x):xs + lsArg :: String -> [String] -> [(String,String)] -> [(String,String)] lsArg _ [] xs = xs lsArg t ls xs = (t,intercalate "," ls):xs
Flickr/Places.hs view
@@ -51,6 +51,28 @@ (mbArg "accuracy" (fmap show acc) $ [("lat", la),("lon", lon)]) +-- | Return a list of locations with public photos that are parented by a Where on Earth (WOE) or Places ID.+getChildrenWithPhotosPublic :: Either PlaceID WhereOnEarthID+ -> FM (PlaceQuery, [Place])+getChildrenWithPhotosPublic pw = + flickTranslate toPlaces $+ flickrCall "flickr.places.getChildrenWithPhotosPublic"+ (eiArg "place_id" "woe_id" pw [])++-- | Lookup information about a place, by its flickr.com/places URL.+getInfoByUrl :: URLString -> FM LocationPlace+getInfoByUrl url = + flickTranslate toLocationPlace $+ flickrCall "flickr.places.getInfoByUrl"+ [ ("url", url) ]++-- | Get informations about a place.+getInfo :: Either PlaceID WhereOnEarthID -> FM LocationPlace+getInfo pw = + flickTranslate toLocationPlace $+ flickrCall "flickr.places.getInfo"+ (eiArg "place_id" "woe_id" pw [])+ -- | Return a list of the top 100 unique places clustered by a given placetype for a user. placesForUser :: PlaceType -> Maybe WhereOnEarthID
+ Flickr/Test.hs view
@@ -0,0 +1,48 @@+-------------------------------------------------------------------- +-- | +-- Module : Flickr.Test +-- Description : flickr.test - testing auth and method calls. +-- Copyright : (c) Sigbjorn Finne, 2008 +-- License : BSD3 +-- +-- Maintainer : Sigbjorn Finne <sof@forkIO.com> +-- Stability : provisional +-- Portability : portable +-- +-- flickr.test API, kicking the tires for method calls and auth +-- of these. +-------------------------------------------------------------------- +module Flickr.Test where + +import Flickr.Monad +import Flickr.Types +import Flickr.Types.Import +import Flickr.Utils + +import Text.XML.Light +import Text.XML.Light.Proc + +-- | A testing method which echo's all parameters back in the response. +echo :: [(String,String)] -> FM [(String,String)] +echo args = + flickTranslate toRes $ + flickrCall "flickr.test.echo" args + where + toRes s = parseDoc eltRes s + + eltRes e = do + let es = children e + return (map (\ x -> (qName (elName x), strContent x)) es) + + +-- | A testing method which checks if the caller is logged in then returns their username. +login :: FM User +login = withReadPerm $ + flickTranslate toUser $ + flickrCall "flickr.test.login" [] + +-- | Null test +nullTest :: FM () +nullTest = withReadPerm $ postMethod $ + flickCall_ "flickr.test.null" [] +
Util/Fetch.hs view
@@ -55,7 +55,29 @@ -} readUserContentsURL :: User -> URLString -> IO String-readUserContentsURL _ u = readContentsURL u+readUserContentsURL usr us = do -- readContentsURL u+ req <- + case parseURI us of+ Nothing -> fail ("ill-formed URL: " ++ us)+ Just ur -> return (defaultGETRequest ur)+ -- don't like doing this, but HTTP is awfully chatty re: cookie handling..+ let nullHandler _ = return ()+ (u, resp) <- browse $ do + setOutHandler nullHandler+ setAllowBasicAuth True+ setAuthorityGen (\ _ _ -> return (Just (userName usr,userPass usr)))+{-+ addAuthority AuthBasic{ auUsername = userName usr+ , auPassword = userPass usr+ , auRealm = ""+ , auSite = nullURI{uriPath="/"}+ }+-}+ request req+ case rspCode resp of+ (2,_,_) -> return (rspBody resp)+ _ -> fail ("Failed reading URL " ++ show u ++ " code: " ++ show (rspCode resp))+ postContentsURL :: URLString -> [(String,String)] -> String -> IO String postContentsURL u hdrs body = do
flickr.cabal view
@@ -1,5 +1,5 @@ name: flickr -version: 0.2.1 +version: 0.2.2 Synopsis: Haskell binding to the Flickr API Description: The flickr API binding lets you access flickr.com's @@ -49,6 +49,7 @@ Flickr.Photosets.Comments, Flickr.Places, Flickr.Tags, + Flickr.Test, Flickr.URLs, Flickr.Utils, Util.Fetch,