haskheap 0.1.0 → 0.1.1
raw patch · 2 files changed
+29/−4 lines, 2 filesdep +textdep +unordered-containersPVP ok
version bump matches the API change (PVP)
Dependencies added: text, unordered-containers
API changes (from Hackage documentation)
+ Network.Haskheap: Line :: String -> Success
+ Network.Haskheap: editPaste :: PasteID -> Contents -> Bool -> Language -> Auth -> IO (Either Error Success)
+ Network.Haskheap: getHighlightedPaste :: PasteID -> IO (Either Error Success)
Files
- haskheap.cabal +3/−2
- src/Network/Haskheap.hs +26/−2
haskheap.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: haskheap-version: 0.1.0+version: 0.1.1 synopsis: Haskell bindings to refheap. -- description: homepage: https://github.com/Raynes/haskheap@@ -20,6 +20,7 @@ -- other-modules: build-depends: base >= 4.5 && < 4.7, bytestring >=0.9.2, network >=2.3.1, http-types >= 0.7.3, http-conduit >=1.8.2, aeson >=0.6.0,- old-locale >= 1.0.0, time >= 1.4+ old-locale >= 1.0.0, time >= 1.4, text >=0.11.2,+ unordered-containers >= 0.2.2 hs-source-dirs: src
src/Network/Haskheap.hs view
@@ -6,6 +6,8 @@ , createPaste , deletePaste , forkPaste+ , editPaste+ , getHighlightedPaste ) where @@ -16,10 +18,12 @@ import System.Locale (defaultTimeLocale) import Network.URI (URI, parseURI) import Data.Aeson ((.:), (.:?), (.!=), decode, FromJSON(..), Value(..))-import Network.HTTP.Conduit+import Network.HTTP.Conduit (parseUrl, urlEncodedBody, Response(..), Request(..), withManager, httpLbs) import Network.HTTP.Types (renderSimpleQuery, SimpleQuery, Method, methodGet, methodPost, methodDelete) import Network (withSocketsDo) import Control.Arrow ((***))+import qualified Data.HashMap.Strict as HM+import qualified Data.Text as T import qualified Data.ByteString.Lazy.Char8 as B import qualified Data.ByteString.Char8 as SB @@ -54,6 +58,7 @@ , getUser :: Maybe String -- ^ User who created the paste. Nothing indicates anonymous. , getBody :: Contents -- ^ Body of the paste. }+ | Line String -- ^ A string was returned by the API that can't be represented as a paste. | Empty -- ^ Operation was successful, but response is empty. deriving (Show) @@ -99,6 +104,10 @@ Nothing -> req' responseBody <$> withManager (httpLbs req'') +toList :: Maybe Value -> Maybe [(T.Text, Value)]+toList (Just (Object hm)) = Just $ HM.toList hm+toList Nothing = Nothing+ -- | Decode a paste to either a Maybe Error or a Paste. It works by first -- trying to decode the JSON as a Paste and if that fails, it tries to decode -- it as an Error.@@ -108,7 +117,9 @@ (Just x) -> Right x Nothing -> case decode s of (Just x) -> Left x- Nothing -> Right Empty+ Nothing -> case toList (decode s :: Maybe Value) of+ Just [("content", String x)] -> Right $ Line $ T.unpack x+ _ -> Right Empty -- | Get a paste from refheap. Will return IO Nothing if the paste doesn't exist. getPaste :: PasteID -> IO (Either Error Success)@@ -135,3 +146,16 @@ forkPaste id auth = liftM decodePaste $ refheapReq methodPost ("/paste/" ++ id ++ "/fork") (Just $ composeAuth auth) Nothing++-- | Edit a paste.+editPaste :: PasteID -> Contents -> Bool -> Language -> Auth -> IO (Either Error Success)+editPaste id body private language auth =+ liftM decodePaste $ refheapReq methodPost ("/paste/" ++ id) (Just $ composeAuth auth) form+ where form = Just [("contents", body)+ ,("private", show private)+ ,("language", language)]++-- | Get the highlighted body of a paste. This does not include theme css, just raw HTML.+getHighlightedPaste :: PasteID -> IO (Either Error Success)+getHighlightedPaste id =+ liftM decodePaste $ refheapReq methodGet ("/paste/" ++ id ++ "/highlight") Nothing Nothing