packages feed

hlongurl 0.9.1 → 0.9.3

raw patch · 3 files changed

+35/−12 lines, 3 filesdep ~curlPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: curl

API changes (from Hackage documentation)

+ Network.LongURL: instance ShowSC QueryParam
+ Network.LongURL: instance ShowSC [QueryParam]

Files

Hlongurl.hs view
@@ -28,7 +28,7 @@ main = do   curl_global_init 2  -- Initialise just win32sock (if applicable)   curl' <- initialize-  let ci = CurlInstance { curl = curl', userAgent = "hlongurl 0.9.1; Haskell" }+  let ci = CurlInstance { curl = curl', userAgent = "hlongurl 0.9.3; Haskell" }   supportedDomains <- (domains =<<) <$> supportedSites ci   urlRegex <- (makeRegexM                $ "http://(" ++ intercalate "|" (replace "." "\\." <$> supportedDomains)
Network/LongURL.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE FlexibleInstances #-} module Network.LongURL      ( CurlInstance(..)     , longURL@@ -6,7 +7,7 @@     , URLInfo(..)     ) where -import Network.Curl (Curl, CurlResponse(..), do_curl, method_GET)+import Network.Curl (Curl, CurlResponse, CurlResponse_(..), do_curl_, method_GET) import Network.Curl.Code (CurlCode(..)) import Network.Curl.Opts (CurlOption(..)) import Network.Curl.Types (URLString)@@ -15,11 +16,30 @@ import Util.Codec.Percent (getEncodedString)  import Control.Applicative ((<$>))+import Data.List (intersperse)  data CurlInstance = CurlInstance { curl :: Curl                                  , userAgent :: String                                  } +data QueryParam = QueryParam { paramName :: String+                             , paramValue :: String+                             }++class ShowSC a where+    showS :: a -> ShowS++{-+instance Show a => ShowSC a where+    showS = shows+-}++instance ShowSC QueryParam where+    showS (QueryParam { paramName = n, paramValue = v }) = ((getEncodedString n ++ ('=' : getEncodedString v)) ++)++instance ShowSC [QueryParam] where+    showS = foldr1 (.) . (('?' :) :) . intersperse ('&' :) . (showS <$>)+ data SupportedSite = SupportedSite { siteName :: String                                    , domains :: [String]                                    }@@ -29,7 +49,7 @@                        }  simple_get :: CurlInstance -> URLString -> IO String-simple_get ci url = handleResponse =<< do_curl (curl ci) url+simple_get ci url = handleResponse =<< do_curl_ (curl ci) url                     (CurlUserAgent (userAgent ci) : CurlVerbose False : CurlNoProgress True : method_GET)     where       handleResponse :: CurlResponse -> IO String@@ -47,20 +67,23 @@ apiVersion :: String apiVersion = "v1" +jsonFormat :: QueryParam+jsonFormat = QueryParam { paramName = "format", paramValue = "json" }+ -- | Makes a call to the JSON web API-apiCall :: CurlInstance -> String -> IO [(String, JSValue)]-apiCall ci query = do+apiCall :: CurlInstance -> String -> [QueryParam] -> IO [(String, JSValue)]+apiCall ci path ps = do   (Right (JSObject jso)) <- (runGetJSON readJSObject <$>) . simple_get ci-                            $ apiSite ++ "/" ++ apiVersion ++ "/" ++ query+                            $ apiSite ++ ('/' : apiVersion ++ ('/' : path ++ showS (jsonFormat : ps) ""))   return $ fromJSObject jso  supportedSites :: CurlInstance -> IO [SupportedSite] supportedSites ci =-    mapM (\(n, ds) -> SupportedSite n <$> (mapM getJSString =<< getJSArray ds)) =<< apiCall ci "services?format=json"+    mapM (\(n, ds) -> SupportedSite n <$> (mapM getJSString =<< getJSArray ds)) =<< apiCall ci "services" []  longURL :: CurlInstance -> String -> IO URLInfo longURL ci url = do-  rec <- apiCall ci $ "expand?url=" ++ getEncodedString url ++ "&format=json"+  rec <- apiCall ci "expand" [QueryParam { paramName = "url", paramValue = url }]   (Just jsURL) <- return $ lookup "long_url" rec   url' <- getJSString jsURL   title <- maybe (return Nothing) ((return <$>) . getJSString) $ lookup "title" rec
hlongurl.cabal view
@@ -1,6 +1,6 @@ name:                hlongurl-version:             0.9.1-Cabal-Version:	     >= 1.2+version:             0.9.3+Cabal-Version:	     >= 1.6 synopsis:            Library and utility interfacing to longurl.org description:         The library provides a Haskell binding to the longurl.org API. 		     The utility finds all URLs in its input that longurl says it can expand,@@ -22,12 +22,12 @@   location: http://code.haskell.org/hlongurl/  Library-  build-Depends:	base, curl, json+  build-Depends:	base, curl >= 1.3.4, json   exposed-modules:      Network.LongURL, Util.Codec.Percent   ghc-options:          -Wall  Executable hlongurl-  build-Depends:	base, bytestring, curl, regex-base >= 0.93.1, regex-posix >= 0.93.2+  build-Depends:	base, bytestring, curl >= 1.3.4, regex-base >= 0.93.1, regex-posix >= 0.93.2   main-is:	Hlongurl.hs   Other-Modules:	Network.LongURL, Util.Codec.Percent, Data.List.Replace   ghc-options:          -Wall