{-# LANGUAGE DeriveGeneric #-}{- |
The 'Response' data type. This should be imported qualified so as not
to conflict with the accessors from the 'Item' and 'Image' data types:
> import qualified IsoHunt.Response as Response
> import qualified IsoHunt.Item as Item
> import qualified IsoHunt.Image as Image
>
> ... Response.title r ... Item.title i ... Image.title im ...
These fields are mostly undocumented; see
<http://ca.isohunt.com/js/json.php?ihq=ubuntu&start=1&rows=4> for
an example response.
-}moduleIsoHunt.Response(Response(..),)whereimportControl.ApplicativeimportControl.MonadimportqualifiedData.VectorasVimportData.AesonimportData.TextimportGHC.GenericsimportData.HashMap.StrictasHimportData.TypeableimportIsoHunt.Item(Item)importIsoHunt.Image(Image)dataResponse=Response{title::Text,link::Text,category::Text,pubDate::Text,description::Text,language::Text,maxResults::Integer,ttl::Integer,image::Image,lastBuildDate::Text,totalResults::Integer,items::V.VectorItem,-- ^ search resultscensored::Integer}deriving(Eq,Ord,Show,Typeable,Generic)-- we supply a custom instance because:-- * we want to change the names (totalResults vs total_results)-- * the items field has a weird JSON representationinstanceFromJSONResponsewhereparseJSON(Objectv)=Response<$>v.:"title"<*>v.:"link"<*>v.:"category"<*>v.:"pubDate"<*>v.:"description"<*>v.:"language"<*>v.:"max_results"<*>v.:"ttl"<*>v.:"image"<*>v.:"lastBuildDate"<*>v.:"total_results"<*>listv"items"<*>v.:"censored"parseJSON_=mzerolistobjkey=caseH.lookupkeyobjofJust(Objectv)->v.:"list"Just_->fail$"key "++showkey++" is not an object"Nothing->returnV.empty