aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2015-11-01 19:46:30 +0300
committerIgor Pashev <pashev.igor@gmail.com>2015-11-01 19:47:46 +0300
commiteeb60821c73596fb3b1c2426bc26dbcd59eb7bb3 (patch)
treeb96990170dd19fb492c19d2e8e78e61e5520d2fc /src
parentb09ba749840c0f7c363c1e831a2f6d60ec267b93 (diff)
downloadzerobin-eeb60821c73596fb3b1c2426bc26dbcd59eb7bb3.tar.gz
Support different bins
Diffstat (limited to 'src')
-rw-r--r--src/ZeroBin.hs29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/ZeroBin.hs b/src/ZeroBin.hs
index 13c229e..fac93a5 100644
--- a/src/ZeroBin.hs
+++ b/src/ZeroBin.hs
@@ -2,7 +2,6 @@
module ZeroBin (
Expiration(..),
- pasteEc,
share
) where
@@ -17,9 +16,6 @@ import qualified Data.ByteString.Char8 as C
import qualified Data.ByteString.Lazy as L
import qualified Network.HTTP.Conduit as HTTP
-pasteEc :: String
-pasteEc = "https://paste.ec"
-
data Response = Response {
status :: String
, message :: Maybe String
@@ -41,25 +37,28 @@ instance Show Expiration where
show Month = "1_month"
show Never = "never"
-post :: Expiration -> Content -> IO Response
-post ex ct = do
- req' <- HTTP.parseUrl $ pasteEc ++ "/paste/create"
+post :: String -> Expiration -> Content -> IO (Either String String)
+post bin ex ct = do
+ req' <- HTTP.parseUrl $ bin ++ "/paste/create"
let req = HTTP.urlEncodedBody
[ (C.pack "expiration" , C.pack $ show ex)
, (C.pack "content" , L.toStrict $ JSON.encode ct)
] req'
manager <- HTTP.newManager HTTP.tlsManagerSettings
response <- HTTP.httpLbs req manager
- return . fromJust . JSON.decode $ HTTP.responseBody response
-
-share :: Expiration -> ByteString -> IO (Either String String)
-share ex txt = do
- pwd <- makePassword 33
- c <- encrypt pwd (encode txt)
- resp <- post ex c
+ let resp = fromJust . JSON.decode $ HTTP.responseBody response
case status resp of
"ok" -> return . Right $
- pasteEc ++ "/paste/" ++ (fromJust . paste) resp ++ "#" ++ pwd
+ bin ++ "/paste/" ++ (fromJust . paste) resp
_ -> return . Left $
(fromJust . message) resp
+share :: String -> Expiration -> ByteString -> IO (Either String String)
+share bin ex txt = do
+ pwd <- makePassword 33
+ c <- encrypt pwd (encode txt)
+ append pwd `fmap` post bin ex c
+ where
+ append _ (Left e) = Left e
+ append p (Right u) = Right $ u ++ "#" ++ p
+