module Web.Last.Group where import Control.Applicative import Control.Arrow import Web.Last.Types import Web.Last.Request import qualified Web.Last.Parsing as P import Text.JSON.Combinators getMembers :: String -> Last (Paged (User,[Image])) getMembers group = pagedRequest "group.getmembers" [("group",group)] [] pa pno where pa = objOf $ inObj "members" $ llArr "user" $ P.user &&& (objOf $ llArr "image" P.image) pno = objOf $ inObj "members" $ P.readInt <$> ll "totalPages" strJS -- String is playcount getWeeklyAlbumChart :: String -> Maybe String -> Maybe String -> Last [(Album,String)] getWeeklyAlbumChart group from to = anonRequest "group.getweeklyalbumchart" [("group",group)] [("from",from),("to",to)] pa where pa = objOf $ inObj "weeklyalbumchart" $ llArr "album" $ P.album &&& (objOf $ ll "playcount" strJS) -- String is playcount getWeeklyArtistChart :: String -> Maybe String -> Maybe String -> Last [(Artist,String)] getWeeklyArtistChart group from to = anonRequest "group.getweeklyartistchart" [("group",group)] [("from",from),("to",to)] pa where pa = objOf $ inObj "weeklyartistchart" $ llArr "artist" $ P.artist &&& (objOf $ ll "playcount" strJS) getWeeklyChartList :: String -> Last [(String,String)] getWeeklyChartList group = anonRequest "group.getweeklychartlist" [("group",group)] [] pa where pa = objOf $ inObj "weeklychartlist" $ llArr "chart" $ objOf $ (ll "from" strJS) &&& (ll "to" strJS) -- String is playcount getWeeklyTrackChart :: String -> Maybe String -> Maybe String -> Last [(Track,String)] getWeeklyTrackChart group from to = anonRequest "group.getweeklytrackchart" [("group",group)] [("from",from),("to",to)] pa where pa = objOf $ inObj "weeklytrackchart" $ llArr "track" $ P.track &&& (objOf $ ll "playcount" strJS)