packages feed

clit 0.2.2.6 → 0.2.3.0

raw patch · 5 files changed

+89/−3 lines, 5 filesdep +clitdep ~basedep ~http-clientdep ~http-client-tlsnew-component:exe:tweet

Dependencies added: clit

Dependency ranges changed: base, http-client, http-client-tls

Files

+ README.md view
@@ -0,0 +1,56 @@+# Command Line Interface Tweeter++## Config+Generate a token to authorize access to your twitter account by following the guide [here](https://dev.twitter.com/oauth/overview/application-owner-access-tokens)++Then place your API keys and OAuth tokens in a file `.cred`, separated by a line break:++```+api-key: API_KEY_HERE+api-sec: API_SECRET_HERE+tok: OAUTH_TOKEN_HERE+tok-sec: TOKEN_SECRET_HERE+```++## Installation++Install [haskell stack](https://docs.haskellstack.org/en/stable/README/#how-to-install); on unix systems this is as simple as++```+wget -qO- https://get.haskellstack.org/ | sh+```++Then type `stack install` in the directory and it will generate an executable called `tweet`, which is what we want.++## Use+To tweet from stderr, run a command that pipes stderr to stdin, i.e.++```+YOUR_BUILD_COMMAND 2>&1 >/dev/null | tweet+```++The `tweet` executable reads from stdIn as its only behavior, but you can view the options (replies, number of tweets to thread, etc.) with++```+tweet --help+```++This script powers the twitter account [@my\_build\_errors](https://twitter.com/my_build_errors) for instance. There's an example bash script for in `bash/example`++### Completions++The directory `bash/` has a `mkCompletions` script to allow command completions for your convenice.++## Library+A haskell package is included. It's fairly easy to use once you have the credentials set up, with two main functions: `thread` and `basicTweet`: the first for threading your own tweets or replying to someone else's and the second for just tweeting.++### Finer details+The function `tweetData` will tweet an object of type `Tweet`. Its use is pretty self-explanatory, but how to best form `Tweet`s is not immediately obvious.++`Tweet` is an instance of `Default` so you can use `def` to get an empty tweet replying to nobody and not fetching extended user data. This is especially useful if you want to use lenses and avoid ugly record syntax, e.g.++```+set status "This is the new status field" $ def+```++will give you a `Tweet` with sensible defaults and the desired text.
+ app/Main.hs view
@@ -0,0 +1,6 @@+module Main where++import Web.Tweet.Exec++main :: IO ()+main = exec
clit.cabal view
@@ -1,5 +1,5 @@ name: clit-version: 0.2.2.6+version: 0.2.3.0 cabal-version: >=1.10 build-type: Simple license: BSD3@@ -13,6 +13,8 @@     a Command Line Interface Tweeter category: Web author: Vanessa McHale+extra-source-files:+    README.md  source-repository head     type: git@@ -25,8 +27,8 @@     build-depends:         base >=4.7 && <5,         aeson >=1.0.2.1 && <1.1,-        http-client-tls >=0.3.3.1 && <0.4,-        http-client >=0.5.5 && <0.6,+        http-client-tls >=0.3.4 && <0.4,+        http-client >=0.5.6.1 && <0.6,         http-types >=0.9.1 && <0.10,         authenticate-oauth ==1.6.*,         bytestring >=0.10.8.1 && <0.11,@@ -41,4 +43,13 @@         Web.Tweet.Types         Web.Tweet.Utils         Web.Tweet.Sign++executable tweet+    main-is: Main.hs+    build-depends:+        base >=4.9.1.0 && <4.10,+        clit >=0.2.3.0 && <0.3+    default-language: Haskell2010+    hs-source-dirs: app+    ghc-options: -threaded -rtsopts -with-rtsopts=-N 
src/Web/Tweet.hs view
@@ -96,6 +96,13 @@     request <- signRequest filepath $ initialRequest { method = "POST" }     response request manager +getTimeline :: Int -> FilePath -> IO Response+getTimeline count filepath = do+    let requestString = "?count=" ++ (show count)+    manager <- newManager tlsManagerSettings+    initialRequest <- parseRequest ("https://api.twitter.com/1.1/statuses/home_timeline.json" ++ requestString)+    response request manager+ -- | print output of a request and return status id as an `Int`.  response :: Request -> Manager -> IO Int response request manager = do
src/Web/Tweet/Types.hs view
@@ -22,6 +22,12 @@     , _replyID  :: Maybe Int     } deriving (Generic, Default) +data Timeline = Timeline+    { _screenName :: String+    , _includeRTs :: Maybe Bool+    , _count :: Int+    }+ makeLenses ''Tweet  instance ToJSON Tweet where