1. Maxim Moiseev
  2. evernote-haskell-bindings

Source

evernote-haskell-bindings / test / SampleWorkflowTest.hs

{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Evernote (createNote)
import           Evernote.Network (
      Credentials(..)
    , setupEvernote
    , connectToUserStore
    , authenticate
    , connectToNoteStore
    , saveToDefaultNotebook
    )
import qualified Evernote.Enml as E

import qualified Control.Exception as C
import           Data.ByteString.UTF8 (fromString)

import LocalSettings (credentials, settings)

main :: IO ()
main =
    let go = do
        usc <- connectToUserStore useSandbox
        auth <- authenticate usc settings credentials
        nsc <- connectToNoteStore auth useSandbox
        newNote <- saveToDefaultNotebook nsc testNote
        putStrLn $ "Created note: " ++ show newNote
    in
        go `C.catch` \(C.SomeException e) ->
            putStrLn $ "Exception caught: " ++ (show e)
  where
    useSandbox = True

    testNote = createNote title content
    title = "Test note from Haskell"
    content = [
        E.text "Hello world!",
        E.br,
        E.todo "A simple todo item",
        E.br,
        E.done "Checked todo item",
        E.br,
        E.text $ fromString "Привет, мир!"
        ]

    printSomething :: Show a => String -> Maybe a -> IO ()
    printSomething prefix = do
        maybe (return ()) $ \x ->
            putStrLn $ prefix ++ show x