rdioh 0.2.0 → 0.2.1
raw patch · 2 files changed
+100/−2 lines, 2 files
Files
- rdioh.cabal +2/−2
- src/Rdioh/Util.hs +98/−0
rdioh.cabal view
@@ -1,5 +1,5 @@ name: rdioh-version: 0.2.0+version: 0.2.1 category: Network, API, Web license: MIT license-file: LICENSE@@ -14,7 +14,7 @@ library build-depends: base >= 3 && <= 5 , mtl , MissingH , bytestring , json , hoauth , urlencoded, aeson, containers, transformers- exposed-modules: Rdioh, Rdioh.Models, Rdioh.Auth+ exposed-modules: Rdioh, Rdioh.Models, Rdioh.Auth, Rdioh.Util hs-source-dirs: src extensions: FlexibleContexts
+ src/Rdioh/Util.hs view
@@ -0,0 +1,98 @@+{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}+module Rdioh.Util where+import qualified Data.URLEncoded as UE+import qualified Data.List.Utils as U+import qualified Text.JSON as J+import Rdioh.Models++-- | used internally to convert a list of parameters to a string that can be passed via GET/POST+toParams :: [(String, String)] -> String+toParams = show . UE.importList++-- | used internally+(<+>) :: Param p => [(String, String)] -> (String, Maybe p) -> [(String, String)]+arr <+> (_, Nothing) = arr+arr <+> (str, (Just param)) = arr ++ [(str, toParam param)]++-- | used internally to easily convert different Rdio types to params for+-- | requests. You can use @toParam@ to do this if you want.+class Param a where+ toParam :: a -> String++instance Param Bool where+ toParam True = "true"+ toParam False = "false"++instance Param Int where+ toParam val = show val++instance Param String where+ toParam val = val++instance Param [String] where+ toParam list = U.join "," list++instance Param PlaylistType where+ toParam = show++instance Param CollaborationMode where+ toParam NoCollaboration = "0"+ toParam CollaborationWithAll = "1"+ toParam CollaborationWithFollowed = "2"++instance Param Scope where+ toParam = show++instance Param Timeframe where+ toParam = show++-- class RdioType a where+-- typeName :: String++-- instance RdioType Album where+-- typeName = "Album"++-- instance RdioType Artist where+-- typeName = "Artist"++-- instance RdioType Label where+-- typeName = "Label"++-- instance RdioType Track where+-- typeName = "Track"++-- instance RdioType Playlist where+-- typeName = "Playlist"++-- instance RdioType UserPlaylists where+-- typeName = "UserPlaylists"++-- instance RdioType User where+-- typeName = "User"++-- instance RdioType CollectionAlbum where+-- typeName = "CollectionAlbum"++-- instance RdioType CollectionArtist where+-- typeName = "CollectionArtist"++-- instance RdioType LabelStation where+-- typeName = "LabelStation"++-- instance RdioType ArtistStation where+-- typeName = "ArtistStation"++-- instance RdioType HeavyRotationUserStation where+-- typeName = "HeavyRotationUserStation"++-- instance RdioType ArtistTopSongsStation where+-- typeName = "ArtistTopSongsStation"++-- instance RdioType UserCollectionStation where+-- typeName = "UserCollectionStation"++-- instance RdioType SearchResults where+-- typeName = "SearchResults"++-- instance RdioType Activity where+-- typeName = "Activity"