orchestrate-0.2.0.0: An API client for http://orchestrate.io/.

Safe HaskellNone
LanguageHaskell2010

Database.Orchestrate.Utils

Contents

Synopsis

Type Utilities

Executing OrchestrateIO Actions

runO :: Monad m => OrchestrateT m a -> Session -> m (Either SomeException a) Source

Run an OrchestrateT action with a Session that does not include authentication. This function will add proper authentication before running the action.

runO' :: Monad m => OrchestrateT m a -> Session -> m (Either SomeException a) Source

Run an OrchestrateT action with a Session that already includes authentication.

This is the most minimal handler.

Lifting

orchestrateEither :: Monad m => Either SomeException a -> OrchestrateT m a Source

Lifts an Either value into the OrchestrateT monad.

io :: MonadIO m => IO a -> OrchestrateT m a Source

Lifts an IO action into the OrchestrateT monad.

API Infrastructure

api Source

Arguments

:: RequestHeaders

Additional HTTP headers.

-> [Text]

The parts of the URL path.

-> [FormParam]

The form parameters.

-> RestCall a

The wreq function to make the call.

-> OrchestrateIO (Response a)

Returns the call's response.

This assembles and performs an API call.

api' Source

Arguments

:: RequestHeaders

Additional HTTP headers.

-> [Text]

The parts of the URL path.

-> [FormParam]

The form parameters.

-> RestCall a

The wreq function to make the call.

-> OrchestrateIO (Either Status (Response a))

Returns either the error status or the response.

This assembles and peforms an API call, lifting any status code errors out of the monad and returning them in an explicit Either.

api404 Source

Arguments

:: Show a 
=> RequestHeaders

Additional HTTP headers.

-> [Text]

The parts of the URL path.

-> [FormParam]

The form parameters.

-> RestCall a

The wreq function to make the call.

-> OrchestrateIO (Maybe (Response a))

Returns maybe the response.

This assembles and performs an API call. It returns Nothing if the call returns a 404 status code.

apiCheck Source

Arguments

:: RequestHeaders

Additional HTTP headers.

-> [Text]

The parts of the URL path.

-> [FormParam]

The form parameters.

-> RestCall a

The wreq function to make the call.

-> OrchestrateIO (Response a)

Returns the verified response.

This assembles and performs an API call and checks that the status passes checkResponse.

apiCheckDecode Source

Arguments

:: FromJSON a 
=> RequestHeaders

Additional HTTP headers.

-> [Text]

The parts of the URL path.

-> [FormParam]

The form parameters.

-> RestCall ByteString

The wreq function to make the call.

-> OrchestrateIO a

Returns the verified, decoded response.

This assembles and performs an API call. Afterward it checks the status code and decodes the JSON response.

API Functions

ping :: OrchestrateIO () Source

Pings the Orchestrate API.

Data Type Helpers

Session Utilities

baseUrl :: Monad m => OrchestrateT m Text Source

Create the base Orchestrate API URL given the current Session.

buildUrl Source

Arguments

:: Monad m 
=> [Text]

The parts of the URL path. These are joined by /.

-> OrchestrateT m String

Returns the URL as a String.

Builds a URL from its assembled parts.

withAuth' :: APIKey -> Options Source

Adds the API key to the default Options.

withAuth :: APIKey -> Options -> Options Source

Adds the API key to a set of wreq Options.

envSession :: IO Session Source

This returns the Session with the API key taken from the ORCHESTRATE_API environment variable.

The value of sessionOptions will include authentication.

Match Utilities

ifMatch :: IfMatch -> [Header] Source

Takes an IfMatch and returns a list of request headers.

ifMatch' :: IfMatch' -> [Header] Source

Takes an IfMatch' and returns a list of request headers.

Location Prisms and Functions

locationCollection :: Prism' Text Text Source

A prism over the collection part of a Location URL.

locationKey :: Prism' Text Text Source

A prism over the key part of a Location URL.

locationRef :: Prism' Text Text Source

A prism over the ref part of a Location URL.

locationType :: Prism' Text Text Source

A prism over the type part of a Location URL from an event operation.

locationTimestamp :: Prism' Text Integer Source

A prism over the timestamp part of a Location URL from an event operation.

locationOrdinal :: Prism' Text Int Source

A prism over the ordinal part of a Location URL from an event operation.

getLocation :: Response a -> Text Source

Retrieves the Location from a response's headers.

Range Utilities

rangeStart Source

Arguments

:: FormValue a 
=> ByteString

The suffix for the form parameter.

-> RangeEnd a

The RangeEnd.

-> Maybe FormParam

Returns the form parameter.

Given a starting RangeEnd, return the form parameter.

rangeEnd Source

Arguments

:: FormValue a 
=> ByteString

The suffix for the form parameter.

-> RangeEnd a

The RangeEnd.

-> Maybe FormParam

Returns the form parameter.

Given an ending RangeEnd, return the form parameter.

General Utilities

rot :: (a -> b -> c -> d) -> c -> a -> b -> d Source

This takes a three-parameter function and rotates the parameters to return a function that takes the third parameter first.

tshow :: Show a => a -> Text Source

Show data as Text.

initTail :: [a] -> (Maybe a, [a]) Source

Returns both the last item in a list and the list's init.

If the list is empty, it will return (Nothing, []). Otherwise, it's an optimized call to (lastMay &&& initSafe).