OrchestrateDB-1.0.0.1: Unofficial Haskell Client Library for the Orchestrate.io API

Copyright(c) Adrian Dawid 2015
LicenseBSD3
Maintaineradriandwd@gmail.com
Stabilitystable
Safe HaskellNone
LanguageHaskell2010

Database.Orchestrate.REST

Description

This module conatins all the functions which interact with the Orchestrate.io REST API. Right now these actions are supported:

  • Validate API Keys
  • List Key/Values
  • Create Key/Value
  • Create Key/Value with server-generated key
  • Update Key/Value
  • Retrieve Value for Key
  • Delete Collection(s)
  • Query Collection

Synopsis

Documentation

validateApplication :: OrchestrateApplication -> IO Bool Source

The validateApplication function validates your API key, by making an authenticated HEAD request to the endpoint specified in the OrchestrateApplication record. The function returns False when the key is invalid or no connection with the endpoint could be established.

orchestrateCollectionPutWithoutKey :: ToJSON obj => OrchestrateApplication -> OrchestrateCollection -> obj -> IO Bool Source

The orchestrateCollectionPutWithoutKey function stores a Haskell value(with a ToJSON instance) in an Orchestrate.io database. It does so by making a POST request to the /$collection endpoint(Offical API docs:https://orchestrate.io/docs/apiref#keyvalue-post). This function does not need a user specified key, because it uses a server-generated key, if you want to know the key use orchestrateCollectionPut instead of this function.

Example:

     data TestRecord = TestRecord
       { string :: String
        , number :: Int
       } deriving (Show,Read,Generic,Eq)

     instance FromJSON TestRecord
     instance ToJSON TestRecord

     let dbApplication = DB.createStdApplication "APPLICATION_NAME" "API_KEY"
     let dbCollection = DB.createStdCollection "COLLECTION_NAME"
     let testRecord = TestRecord {string = "You may delay, but time will not!",number = 903}
     _ <- DB.orchestrateCollectionPutWithoutKey dbApplication dbCollection testRecord
  

orchestrateCollectionDelete :: OrchestrateApplication -> OrchestrateCollection -> IO Bool Source

The orchestrateCollectionDelete function deletes a collection from an Orchestrate.io application. This is done by making a DELETE request to the /$collection endpoint(Offical documentation:https://orchestrate.io/docs/apiref#collections-delete)

Example:

     let dbApplication = DB.createStdApplication "APPLICATION_NAME" "API_KEY"
     let dbCollection = DB.createStdCollection "COLLECTION_NAME"
     _ <- DB.orchestrateCollectionDelete dbApplication dbCollection
  

orchestrateCollectionGet :: FromJSON res => OrchestrateApplication -> OrchestrateCollection -> String -> IO (Maybe res) Source

The orchestrateCollectionGet function request a value from an Orchestrate.io database, and tries to convert it to the specified Haskell type, if either gettings the value from the database or converting it to the Haskell type fails Nothing is returned. The value is requested by making a GET request to the /$collection/$key endpoint(Offical documentation:https://orchestrate.io/docs/apiref#keyvalue-get)

Example:

     data TestRecord = TestRecord
       { string :: String
        , number :: Int
       } deriving (Show,Read,Generic,Eq)

     instance FromJSON TestRecord
     instance ToJSON TestRecord

     let dbApplication = DB.createStdApplication "APPLICATION_NAME" "API_KEY"
     let dbCollection = DB.createStdCollection "COLLECTION_NAME"
     let testRecord = TestRecord {string = "You may delay, but time will not!",number = 903}
     dbValue <- DB.orchestrateCollectionGet dbApplication dbCollection KEY :: IO (Maybe TestRecord)
  

orchestrateCollectionPut :: ToJSON obj => OrchestrateApplication -> OrchestrateCollection -> String -> obj -> IO Bool Source

The orchestrateCollectionPut function stores a Haskell value(with a ToJSON instance) in an Orchestrate.io database. It does so by making a PUT request to the /$collection/$key endpoint(Offical API docs:https://orchestrate.io/docs/apiref#keyvalue-put). In order to upload a Haskell Value to the database, it must have an instance of ToJSON because this client library uses Aeson to convert Haskel Values to JSON, which is required by Orchestrate.io.

Example:

     data TestRecord = TestRecord
       { string :: String
        , number :: Int
       } deriving (Show,Read,Generic,Eq)

     instance FromJSON TestRecord
     instance ToJSON TestRecord

     let dbApplication = DB.createStdApplication "APPLICATION_NAME" "API_KEY"
     let dbCollection = DB.createStdCollection "COLLECTION_NAME"
     let testRecord = TestRecord {string = "You may delay, but time will not!",number = 903}
     _ <- DB.orchestrateCollectionPutWithoutKey dbApplication dbCollection KEY testRecord
  

orchestrateCollectionDeleteKey :: OrchestrateApplication -> OrchestrateCollection -> String -> IO Bool Source

The orchestrateCollectionDeleteKey function deletes a value from an Orchestrate.io database. This is done by making a DELETE request to the /$collection/$key endpoint(Offical documentation:https://orchestrate.io/docs/apiref#keyvalue-delete)

Example:

     data TestRecord = TestRecord
       { string :: String
        , number :: Int
       } deriving (Show,Read,Generic,Eq)

     instance FromJSON TestRecord
     instance ToJSON TestRecord

     let dbApplication = DB.createStdApplication "APPLICATION_NAME" "API_KEY"
     let dbCollection = DB.createStdCollection "COLLECTION_NAME"
     _ <- DB.orchestrateCollectionKey dbApplication dbCollection KEY
  

orchestrateCollectionSearch :: OrchestrateApplication -> OrchestrateCollection -> String -> IO (Maybe ([Object], Bool)) Source

Please see orchestrateCollectionSearchWithOffset for more information. This function just calls it without an offset and with a limit of 10.

orchestrateCollectionSearchWithOffset :: OrchestrateApplication -> OrchestrateCollection -> String -> Integer -> Integer -> IO (Maybe ([Object], Bool)) Source

The orchestrateCollectionSearchWithOffset function searches for the query in the database and returns an array of the type "Maybe [Object]". Nothing is returned when establishing a connection or authenticating failed. The function uses the SEARCH method of the Orchestrate.io API (Offical documentation:https://orchestrate.io/docs/apiref#search-collection) , but automatically parsers the response. It returns a tupel of the type (Maybe([Object],Bool)), the boolean indicates wether or not more results are availble on the server. If that is true, the function should be called again with an increased offset, until (Just _,False) is returned.

Example:

     dbSearchResults query num =
         let results = DB.orchestrateCollectionSearchWithOffset query num (num+10)
         let currentResults = fromJust $ fst results
         if snd results
            then currentResults:(dbSearchResults query (num+10))
            else currentResults

     let dbApplication = DB.createStdApplication "APPLICATION_NAME" "API_KEY"
     let dbCollection = DB.createStdCollection "COLLECTION_NAME"
     let completeDBSearchResults = dbSearchResults QUERY 0
  

orchestrateCollectionList :: OrchestrateApplication -> OrchestrateCollection -> Integer -> IO (Maybe [Object]) Source

The orchestrateCollectionList function lists the contents of the specified collection, by making GET request to the /$collection?limit=$limit endpoint. For more information check out the Orchestrate.io API docs: https://orchestrate.io/docs/apiref#keyvalue-list. If connecting to the api fails, or the api key stored in the application record is invlaid, Nothing is returned. Otherwise an array of the type Object(see the documentation of Aeson for more information) is returned, it contains the values from the HTTP response(see https://orchestrate.io/docs/apiref#keyvalue-list for an example of how the response looks like in JSON).

Example:

     let dbApplication = DB.createStdApplication "APPLICATION_NAME" "API_KEY"
     let dbCollection = DB.createStdCollection "COLLECTION_NAME"
     dbContents <- DB.orchestrateCollectionList dbApplication dbCollection 10