Sebastián Magrí avatar Sebastián Magrí committed 53ebf79

Implement showInfo for groups

Comments (0)

Files changed (2)

src/Network/SoundCloud.hs

 scResourceShowInfo url | scResourceType url == "track"   = Track.showInfo url
                        | scResourceType url == "user"    = User.showInfo url
                        | scResourceType url == "set"     = Set.showInfo
-                       | scResourceType url == "group"   = Group.showInfo
+                       | scResourceType url == "group"   = Group.showInfo url
                        | scResourceType url == "app"     = App.showInfo url
 scResourceShowInfo _                                     = putStrLn "Unrecognized resource"
 

src/Network/SoundCloud/Group.hs

 import Data.Aeson (FromJSON, ToJSON, decode)
 import qualified Data.ByteString.Lazy.Char8 as BSL
 import GHC.Generics (Generic)
+import Text.Printf (printf)
 
 import qualified Network.SoundCloud.MiniUser as User
+import Network.SoundCloud.Util (scGet, scResolve)
 
 data JSON = JSON { id                     :: Int
                  , created_at             :: String
 decodeJSON :: String -> Maybe JSON
 decodeJSON dat = decode (BSL.pack dat) :: Maybe JSON
 
-showInfo :: IO ()
-showInfo = putStrLn "Not Implemented for groups"
+getJSON :: String -> IO (Maybe JSON)
+getJSON url =
+    do tUrl <- scResolve url
+       dat  <- scGet tUrl True
+       case dat of
+         Nothing -> return Nothing
+         Just d  -> return $ decodeJSON d
+
+showInfo :: String -> IO ()
+showInfo url =
+    do obj <- getJSON url
+       case obj of
+         Nothing        -> putStrLn "Unable to get track information."
+         Just o         ->
+             do let tmp = "%s\n%s (Since %s)\n\t%s\nCreated by %s\n"
+                printf
+                  tmp
+                  (permalink_url o)
+                  (name o)
+                  (created_at o)
+                  (description o)
+                  (User.username $ creator o)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.