google-drive-0.4.1: Google Drive API access

Safe HaskellNone
LanguageHaskell2010

Network.Google.Api

Contents

Description

Actions for working with any of Google's APIs

Note: this module may become a standalone package at some point.

Synopsis

The Api monad

type Api = ReaderT (String, Manager) (ExceptT ApiError IO) Source

A transformer stack for providing the access token and rescuing errors

data ApiError Source

Constructors

HttpError HttpException

Exceptions raised by http-conduit

InvalidJSON String

Failure to parse a response as JSON

GenericError String

All other errors

runApi Source

Arguments

:: String

OAuth2 access token

-> Api a 
-> IO (Either ApiError a) 

Run an Api computation with the given Access token

runApi_ :: String -> Api a -> IO () Source

Like runApi but discards the result and raises ApiErrors as exceptions

throwApiError :: String -> Api a Source

Abort an Api computation with the given message

HTTP-related types

High-level requests

type DownloadSink a = ResumableSource (ResourceT IO) ByteString -> ResourceT IO a Source

Downloads use sinks for space efficiency and so that callers can implement things like throttling or progress output themselves. If you just want to download to a file, use the re-exported sinkFile

getJSON :: FromJSON a => URL -> Params -> Api a Source

Make an authorized GET request for JSON

getSource :: URL -> Params -> DownloadSink a -> Api a Source

Make an authorized GET request, sending the response to the given sink

postJSON :: (ToJSON a, FromJSON b) => URL -> Params -> a -> Api b Source

Make an authorized POST request for JSON

putJSON :: (ToJSON a, FromJSON b) => URL -> Params -> a -> Api b Source

Make an authorized PUT request for JSON

Lower-level requests

requestJSON :: FromJSON a => URL -> (Request -> Request) -> Api a Source

Make an authorized request for JSON, first modifying it via the passed function

requestLbs :: URL -> (Request -> Request) -> Api (Response ByteString) Source

Make an authorized request, first modifying it via the passed function, and returning the raw response content

Api helpers

authorize :: URL -> Api Request Source

Create an authorized request for the given URL

decodeBody :: FromJSON a => Response ByteString -> Api a Source

Decode a JSON body, capturing failure as an ApiError

Request helpers

allowStatus :: Status -> Request -> Request Source

Modify the Request's status check to not treat the given status as an error

Re-exports

liftIO :: MonadIO m => forall a. IO a -> m a

Lift a computation from the IO monad.

throwError :: MonadError e m => forall a. e -> m a

Is used within a monadic computation to begin exception processing.

catchError :: MonadError e m => forall a. m a -> (e -> m a) -> m a

A handler function to handle previous errors and return to normal execution. A common idiom is:

do { action1; action2; action3 } `catchError` handler

where the action functions can call throwError. Note that handler and the do-block must have the same return type.

sinkFile :: MonadResource m => FilePath -> Consumer ByteString m ()

Stream all incoming data to the given file.

Since 0.3.0