alfred-0.4: utility library for Alfred version 2

Copyright(c) 2014 Patrick Bahr
LicenseBSD3
MaintainerPatrick Bahr <paba@di.ku.dk>
Stabilityexperimental
Portabilitynon-portable (GHC Extensions)
Safe HaskellNone
LanguageHaskell98

Alfred.Query

Description

This module provides utility functions to query web APIs. These queries can then be used to feed Alfred with suggestions.

Synopsis

Documentation

jsonQuery :: FromJSON a => Text -> Query a Source

This function performs a query by performing an HTTP GET request at the url obtained by concatenating the first argument with the second one (after escaping it). The returned query takes a string as an argument and appends it to the base url to obtain the url that is used for the query. The result is then parsed as a JSON object. For example, for a Google search:

 runQuery :: Query (Text,[Text])
 runQuery = jsonQuery suggestURL

 suggestURL = "http://google.com/complete/search?client=firefox&q="

jsonQuery' :: FromJSON a => (ByteString -> ByteString) -> Text -> Query a Source

This function is a variant of jsonQuery that takes a function as an additional argument that is used to transform the raw ByteString that is returned by the query. This can be helpful if the source does not provide valid UTF-8 formatted JSON. For example, for a Google search:

 runQuery :: Query (Text,[Text])
 runQuery = jsonQuery' (encodeUtf8 . decodeLatin1) suggestURL

 suggestURL = "http://google.com/complete/search?client=firefox&q="

xmlQuery :: (GenericXMLString a, GenericXMLString b) => Text -> Query (Node a b) Source

This function performs a query by performing an HTTP GET request at the url obtained by concatenating the first argument with the second one (after escaping it). The returned query takes a string as an argument and appends it to the base url to obtain the url that is used for the query. The result is then parsed as an XML document. For example, for a DBLP search:

runQuery :: Query (Node Text Text)
runQuery query = xmlQuery suggestURL query

suggestURL = "http://dblp.uni-trier.de/search/author?xauthor="

xmlQueryLazy :: (GenericXMLString a, GenericXMLString b) => Text -> Query (Node a b) Source

Lazy variant of xmlQueryLazy. This function may be useful if results tend to be lengthy and only a small prefix of the result is used.

escapeString :: String -> String Source

Escapes the string for use in a URL.

escapeText :: Text -> Text Source

Escapes the text for use in a URL.

type Query a = Query' Text a Source

Type representing queries for use in runScript.

transformQuery :: (a -> b) -> Query' q a -> Query' q b Source

Functorial map for Query'.

type Query' q a = q -> IO (Either Text a) Source

Alternative type representing queries for use in runScript'.