Permalink
Browse files

Expose /ipi/find-by-label

  • Loading branch information...
ocharles committed Feb 25, 2013
1 parent cda2d0e commit 49df90c9e2cd1bb587633d87b7e7509215dda6ee
View
@@ -54,7 +54,7 @@ import Data.Set ()
import qualified Data.Set as Set
import qualified Data.Text as T
-import MusicBrainz hiding (mbid, labelCode, coreRef)
+import MusicBrainz hiding (mbid, labelCode, coreRef, partialDate)
import qualified MusicBrainz as MB
import qualified MusicBrainz.Data.ArtistCredit as MB
@@ -230,9 +230,12 @@ comment = "comment" .: text Nothing
--------------------------------------------------------------------------------
partialDate, beginDate, endDate :: Monad m => Form Text m PartialDate
-partialDate = PartialDate <$> "year" .: optionalStringRead "Could not read integer" Nothing
- <*> "month" .: optionalStringRead "Could not read integer" Nothing
- <*> "day" .: optionalStringRead "Could not read integer" Nothing
+partialDate =
+ validate (maybe (Error "Invalid partial date") Success . preview MB.partialDate) $
+ (,,) <$> "year" .: optionalStringRead "Could not read integer" Nothing
+ <*> "month" .: optionalStringRead "Could not read integer" Nothing
+ <*> "day" .: optionalStringRead "Could not read integer" Nothing
+
beginDate = "begin-date" .: partialDate
endDate = "end-date" .: partialDate
View
@@ -0,0 +1,17 @@
+{-# LANGUAGE OverloadedStrings #-}
+module MusicBrainz.API.Ipi ( findByLabels ) where
+
+import Control.Applicative
+import Data.Map
+import Data.Text
+import Text.Digestive
+
+import qualified Data.Set as Set
+
+import MusicBrainz
+import MusicBrainz.API
+import qualified MusicBrainz.Data as MB
+
+findByLabels :: Form Text MusicBrainz (Map (Ref (Revision Label)) (Set.Set IPI))
+findByLabels = runApi $
+ MB.findIpiCodes <$> (Set.fromList <$> "revisions" .: listOf (const revision) Nothing)
@@ -11,7 +11,7 @@ module MusicBrainz.API.JSON
, TopLevel
) where
-import Control.Lens (view, re)
+import Control.Lens hiding ((.=))
import Data.Aeson
import Data.Set (Set)
import Data.Text (Text)
@@ -181,10 +181,11 @@ instance ToJSON Work where
--------------------------------------------------------------------------------
instance ToJSON PartialDate where
- toJSON (PartialDate y m d) = object [ "year" .= y
- , "month" .= m
- , "day" .= d
- ]
+ toJSON date = let (y, m, d) = date ^. re partialDate
+ in object [ "year" .= y
+ , "month" .= m
+ , "day" .= d
+ ]
--------------------------------------------------------------------------------
@@ -221,6 +222,11 @@ instance ToJSON ISWC where
toJSON = toJSON . view (re iswc)
+--------------------------------------------------------------------------------
+instance ToJSON IPI where
+ toJSON = toJSON . view (re ipi)
+
+
--------------------------------------------------------------------------------
newtype Annotation = Annotation Text
@@ -9,7 +9,7 @@ import Text.Digestive
import qualified Data.Set as Set
-import MusicBrainz hiding (coreRef, releaseLabel)
+import MusicBrainz hiding (coreRef, releaseLabel, partialDate)
import MusicBrainz.API
import qualified MusicBrainz.API.Common as Common
import MusicBrainz.API.JSON
@@ -39,6 +39,7 @@ import qualified MusicBrainz.API.Artist as Artist
import qualified MusicBrainz.API.ArtistType as ArtistType
import qualified MusicBrainz.API.Edit as Edit
import qualified MusicBrainz.API.Gender as Gender
+import qualified MusicBrainz.API.Ipi as Ipi
import qualified MusicBrainz.API.Iswc as Iswc
import qualified MusicBrainz.API.Label as Label
import qualified MusicBrainz.API.Recording as Recording
@@ -257,6 +258,8 @@ serviceInit connInfo sessionStore =
, ("/gender/add", expose Gender.add)
+ , ("/ipi/find-by-labels", expose Ipi.findByLabels)
+
, ("/iswc/find-by-works", expose Iswc.findByWorks)
, ("/label/create", expose Label.create)

0 comments on commit 49df90c

Please sign in to comment.