Created
November 20, 2015 11:45
-
-
Save furu/4258e34f0ebda937b990 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Web.Twitter.Conduit | |
import Web.Authenticate.OAuth | |
import System.Environment | |
import qualified Data.ByteString.Char8 as BS | |
import Network.HTTP.Conduit | |
import Control.Monad.IO.Class | |
import Control.Monad.Trans.Resource (runResourceT) | |
import Web.Twitter.Types | |
import qualified Data.Text as T | |
main :: IO () | |
main = do | |
timeline <- getHomeTimeline | |
let status = head timeline | |
putStrLn $ T.unpack $ statusText status | |
getTokens :: IO OAuth | |
getTokens = do | |
consumerKey <- getEnv "OAUTH_CONSUMER_KEY" | |
consumerSecret <- getEnv "OAUTH_CONSUMER_SECRET" | |
return $ twitterOAuth { | |
oauthConsumerKey = BS.pack consumerKey, | |
oauthConsumerSecret = BS.pack consumerSecret | |
} | |
getCredential :: IO Credential | |
getCredential = do | |
token <- getEnv "OAUTH_ACCESS_TOKEN" | |
tokenSecret <- getEnv "OAUTH_ACCESS_SECRET" | |
return $ Credential | |
[("oauth_token", BS.pack token), | |
("oauth_token_secret", BS.pack tokenSecret)] | |
getTwInfo :: IO TWInfo | |
getTwInfo = do | |
tokens <- getTokens | |
credential <- getCredential | |
return $ setCredential tokens credential def | |
getHomeTimeline :: IO [Status] | |
getHomeTimeline = do | |
twInfo <- getTwInfo | |
mgr <- newManager tlsManagerSettings | |
runResourceT $ do | |
timeline <- call twInfo mgr homeTimeline | |
return timeline |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: play-twitter-conduit | |
version: 0.1.0.0 | |
synopsis: Simple project template from stack | |
description: Please see README.md | |
homepage: http://github.com/githubuser/play-twitter-conduit#readme | |
license: BSD3 | |
license-file: LICENSE | |
author: Author name here | |
maintainer: [email protected] | |
copyright: 2010 Author Here | |
category: Web | |
build-type: Simple | |
cabal-version: >=1.10 | |
executable play-twitter-conduit | |
hs-source-dirs: src | |
main-is: Main.hs | |
default-language: Haskell2010 | |
build-depends: | |
base >= 4.7 && < 5 | |
, twitter-conduit | |
, authenticate-oauth | |
, bytestring | |
, http-conduit | |
, transformers | |
, resourcet | |
, twitter-types | |
, text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md | |
# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) | |
resolver: lts-3.6 | |
# Local packages, usually specified by relative directory name | |
packages: | |
- '.' | |
# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) | |
extra-deps: | |
- twitter-conduit-0.1.1.1 | |
- twitter-types-0.7.1.1 | |
- twitter-types-lens-0.7.1 | |
# Override default flag values for local packages and extra-deps | |
flags: | |
twitter-types: | |
time15: true | |
# Extra package databases containing global packages | |
extra-package-dbs: [] | |
# Control whether we use the GHC we find on the path | |
# system-ghc: true | |
# Require a specific version of stack, using version ranges | |
# require-stack-version: -any # Default | |
# require-stack-version: >= 0.1.4.0 | |
# Override the architecture used by stack, especially useful on Windows | |
# arch: i386 | |
# arch: x86_64 | |
# Extra directories used by stack for building | |
# extra-include-dirs: [/path/to/dir] | |
# extra-lib-dirs: [/path/to/dir] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment