packages feed

clit 0.1.0.0 → 0.1.0.1

raw patch · 2 files changed

+23/−11 lines, 2 files

Files

clit.cabal view
@@ -1,7 +1,7 @@ name:                clit-version:             0.1.0.0-synopsis:            Post tweets that you pipe to stdin-description:         Please see README.md+version:             0.1.0.1+synopsis:            Post tweets from stdin+description:         a Command Line Interface Tweeter homepage:            https://github.com/vmchale/command-line-tweeter#readme license:             BSD3 license-file:        LICENSE@@ -10,6 +10,7 @@ copyright:           2016 Vanessa McHale category:            Web build-type:          Simple+stability:           stable cabal-version:       >=1.10  library@@ -30,7 +31,7 @@ executable tweet   hs-source-dirs:      app   main-is:             Main.hs-  ghc-options:         -threaded -rtsopts -with-rtsopts=-N -O2+  ghc-options:         -threaded -rtsopts -with-rtsopts=-N   build-depends:       base                      , clit   default-language:    Haskell2010
src/Web/Tweet.hs view
@@ -3,7 +3,7 @@  -- | Various utilities to tweet using the twitter api -- --- Make sure you have a file credentials file (default `.cred`) with the following info in the correct order:+-- Make sure you have a file credentials file (default `.cred`) with the following info: -- -- api-key: API_KEY --@@ -64,19 +64,30 @@ -- | Create an OAuth token oAuth :: FilePath -> IO OAuth oAuth filepath = do-    secret <- (flip (!!) 1) <$> getConfigData filepath-    key <- (flip (!!) 0) <$> getConfigData filepath+    secret <- (lineByKey "api-sec") <$> getConfigData filepath+    key <- (lineByKey "api-key") <$> getConfigData filepath     let url = "api.twitter.com"     return newOAuth { oauthConsumerKey = key , oauthConsumerSecret = secret , oauthServerName = url }  -- | Create a new credential from a token and secret component of that token credential :: FilePath -> IO Credential credential filepath = newCredential <$> token <*> secretToken-    where token       = (flip (!!) 2) <$> getConfigData filepath-          secretToken = (flip (!!) 3) <$> getConfigData filepath+    where token       = (lineByKey "tok") <$> getConfigData filepath+          secretToken = (lineByKey "tok-sec") <$> getConfigData filepath -getConfigData :: FilePath -> IO [BS.ByteString]-getConfigData filepath = ((map (BS.pack . filterLine)) . lines) <$> readFile filepath+-- | Pick out a key value from a key+lineByKey :: BS.ByteString -> [(BS.ByteString, BS.ByteString)] -> BS.ByteString+lineByKey key = snd . head . (filter (\i -> fst i == key))++-- | Get pairs of "key" to search for and actual values+getConfigData :: FilePath -> IO [(BS.ByteString, BS.ByteString)]+getConfigData filepath = zip <$> keys <*> content+    where content = (map (BS.pack . filterLine)) . lines <$> file+          keys    = (map (BS.pack . keyLine)) . lines <$> file+          file    = readFile filepath++keyLine :: String -> String+keyLine = takeWhile (/=':')  -- | Filter a line of a file for only the actual data and no descriptors filterLine :: String -> String