packages feed

Bitly 0.0.5 → 0.0.6

raw patch · 4 files changed

+14/−109 lines, 4 filesdep −directorydep −filepathdep −regexprdep ~HaXmlPVP ok

version bump matches the API change (PVP)

Dependencies removed: directory, filepath, regexpr

Dependency ranges changed: HaXml

API changes (from Hackage documentation)

Files

Bitly.cabal view
@@ -1,5 +1,5 @@ Name:          Bitly-Version:       0.0.5+Version:       0.0.6 Cabal-version: >= 1.2 Build-type:    Simple @@ -9,7 +9,7 @@ License-file:  LICENSE Maintainer:    Sergey Astanin <s.astanin@gmail.com> -Synopsis: A library and a command line tool to access bit.ly URL shortener.+Synopsis: A library to access bit.ly URL shortener. Description:   This package allows to use bit.ly and j.mp URL   shortening service from Haskell. Currently it supports@@ -22,14 +22,7 @@   > login = your_bit.ly_login   > apikey = your_API_key   .-  Examples (command line utility):-  .-  > $ echo "Text with an URL: http://example.com/" | bitly-  > Text with an URL: http://bit.ly/2eSq1z-  > $ bitly shorten http://example.com-  > http://bit.ly/2eSq1z-  > $ bitly expand http://bit.ly/2eSq1z-  > http://example.com/+  For command line utility see `bitly-cli` package.  Homepage:      http://bitbucket.org/jetxee/hs-bitly/ Bug-reports:   http://bitbucket.org/jetxee/hs-bitly/issues/@@ -39,13 +32,5 @@   Build-depends:                  base >= 3 && < 5                , HTTP >= 4000-               , HaXml < 1.14+               , HaXml >= 1.20 && < 1.21   Exposed-modules: Network.Bitly--Executable bitly-  Main-is:     bitly.hs-  Build-depends:-                 filepath >= 1.1-               , directory >= 1.0 && < 1.1-               , regexpr >= 0.5-
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2009, Sergey Astanin+Copyright (c) 2009-2011, Sergey Astanin All rights reserved.  Redistribution and use in source and binary forms, with or without
Network/Bitly.hs view
@@ -7,6 +7,8 @@  import Network.HTTP import Text.XML.HaXml+import Text.XML.HaXml.Util (docContent)+import Text.XML.HaXml.Posn (noPos, Posn) import Text.XML.HaXml.Pretty (element, content)  -- | Service credentials.@@ -67,8 +69,8 @@   case resp of     Left _ -> return $ Left "Network error"     Right resp' -> do-      let Document _ _ xmlroot _ = xmlParse "" . rspBody $ resp'-      return $ errorOrResult (CElem xmlroot) xmlpath+      let doc = xmlParse "" . rspBody $ resp'+      return $ errorOrResult doc xmlpath   where     loginParams =              [ ("login", login acc)@@ -78,14 +80,15 @@              ]  -- | Analyze XML response-errorOrResult :: Content  -- ^ XML root element-              -> [String] -- ^ Path to the node with the result+errorOrResult :: Document Posn -- ^ Parsed XML document+              -> [String]   -- ^ Path to the node with the result               -> Result-errorOrResult root xmlpath = do+errorOrResult rootelement xmlpath = do+  let root = docContent noPos rootelement   let cs = tag "bitly" /> tag "statusCode" /> txt $ root   case cs of     [] -> Left "No statusCode in response"-    (CString _ code:_) ->+    ((CString _ code _):_) ->           if code /= "OK"             then               let err = concatMap (render . content) $
− bitly.hs
@@ -1,83 +0,0 @@-module Main where--import Network.Bitly--import Control.Applicative ((<$>))-import Data.Char (isSpace)-import Data.Maybe (fromJust, fromMaybe, isJust, isNothing)-import System.Directory (getHomeDirectory)-import System.Environment (getArgs)-import System.Exit (exitFailure, exitSuccess)-import System.FilePath (makeValid, combine)-import System.IO (hPutStrLn, stderr)-import Text.RegexPR--confFileName :: IO String-confFileName = makeValid <$> flip combine ".bitly" <$> getHomeDirectory--readConfig :: IO (Maybe Account)-readConfig = do-  file <- confFileName-  conf <- map (brk '=') . lines <$> readFile file `catch` (\_ -> return "")-  let l = lookup "login" conf-  let k = lookup "apikey" conf-  if isJust l && isJust k-    then return $ Just bitlyAccount { login = fromJust l, apikey = fromJust k }-    else return Nothing--brk d str =-  let (a,b) = break (== d) str-  in  (trim a, trim . dropWhile (== d) $ b)--trim = dropWhile isSpace . reverse . dropWhile isSpace . reverse--errorExit s = hPutStrLn stderr s >> exitFailure--modifyUrl :: (String -> IO Result) -> String -> IO String-modifyUrl op url = do-  r <- op url-  case r of-    -- don't replace URL on error-    Left _ -> return url-    Right url' -> return url'--urlRE = "(http|ftp|https)://\\w+(\\.\\w+)+(:[0-9]+)?(/\\S+)?/?"--passThrough :: (String -> IO Result) -> String -> IO String-passThrough op txt =-  let m = matchRegexPR urlRE txt-  in case m of-    Nothing -> return txt-    Just ((url,(b,a)),_) -> do-      url' <- modifyUrl op url-      return . ((b ++ url') ++) =<< passThrough op a---- process all given urls or read stdin and pass it through-runOp :: (String -> IO Result) -> [String] -> IO ()-runOp op [] = putStr =<< passThrough op =<< getContents-runOp op urls = mapM_ putStrLn =<< mapM (modifyUrl op) urls--usage = "Usage: bitly [ help | [shorten] [url ...] | expand [url ...] ]\n\n\-\If no url is given, bitly acts as a filter and replaces all found URLs.\n\-\Bitly shortens URLs by default.\n\n\-\Configuration file format (~/.bitly):\n\-\  login = your_bit.ly_login\n\-\  apikey = your_API_key"--main = do-  args <- getArgs-  if "help" `elem` args || "--help" `elem` args-    then putStrLn usage >> exitSuccess-    else do--  conf <- readConfig-  case conf of-    Nothing -> do-      f <- confFileName-      errorExit $ "Configuration file is incomplete or not found (" ++ f ++ ")"-    Just acc ->-      case args of-        ("expand":urls) -> runOp (expand acc) urls-        ("shorten":urls) -> runOp (shorten acc) urls-        _  -> runOp (shorten acc) args -- shorten by default-