Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Expose support for setting aliases when building trees of artists/lab…
Browse files Browse the repository at this point in the history
…els/works
  • Loading branch information
ocharles committed Jan 26, 2013
1 parent 1c755a0 commit e1c8231
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
21 changes: 21 additions & 0 deletions src/MusicBrainz/API.hs
Expand Up @@ -19,6 +19,9 @@ module MusicBrainz.API
, url
, work

-- ** Tree data
, aliases

-- * Running API Calls
, runApi

Expand All @@ -34,6 +37,7 @@ import Network.URI (parseURI)
import Text.Digestive

import Data.Set ()
import qualified Data.Set as Set
import qualified Data.Text as T

import MusicBrainz hiding (mbid, labelCode)
Expand Down Expand Up @@ -231,3 +235,20 @@ edit = "edit" .: editRef
revision :: ResolveReference (Revision a) => Form Text MusicBrainz (Ref (Revision a))
revision = "revision" .: revisionRef
where revisionRef = ref "Invalid revision reference"


--------------------------------------------------------------------------------
aliases :: ResolveReference (AliasType a) => Form Text MusicBrainz (Set.Set (Alias a))
aliases = Set.fromList <$> "aliases" .: listOf (const alias) Nothing
where
alias = Alias <$> "name" .: nonEmptyText
<*> "sort-name" .: nonEmptyText
<*> beginDate
<*> endDate
<*> ended
<*> "type" .: aliasTypeRef
<*> "locale" .: locale
<*> "primary-for-locale" .: bool Nothing
locale = validate (\t -> if T.null t then Success Nothing else Success (Just t)) $
text Nothing
aliasTypeRef = optionalRef "Invalid alias type reference"
2 changes: 1 addition & 1 deletion src/MusicBrainz/API/Artist.hs
Expand Up @@ -30,7 +30,7 @@ create :: Form Text MusicBrainz (RefObject (Revision Artist))
create = Create.create $
ArtistTree <$> "artist" .: artist
<*> pure Set.empty
<*> pure Set.empty
<*> aliases
<*> pure Set.empty
<*> pure ""

Expand Down
2 changes: 1 addition & 1 deletion src/MusicBrainz/API/JSON.hs
Expand Up @@ -44,7 +44,7 @@ instance (ToJSON a, ToJSON (Ref a)) => ToJSON (Entity a) where


--------------------------------------------------------------------------------
instance ToJSON Alias where
instance ToJSON (Alias a) where
toJSON Alias{..} = object [ "name" .= aliasName
, "sort-name" .= aliasSortName
, "locale" .= aliasLocale
Expand Down
2 changes: 1 addition & 1 deletion src/MusicBrainz/API/Label.hs
Expand Up @@ -30,7 +30,7 @@ create :: Form Text MusicBrainz (RefObject (Revision Label))
create = Create.create $
LabelTree <$> "label" .: label
<*> pure Set.empty
<*> pure Set.empty
<*> aliases
<*> pure Set.empty
<*> pure ""

Expand Down
4 changes: 2 additions & 2 deletions src/MusicBrainz/API/Work.hs
Expand Up @@ -51,7 +51,7 @@ tree :: Form Text MusicBrainz (Tree Work)
tree =
WorkTree <$> "work" .: work
<*> pure mempty
<*> pure mempty
<*> aliases
<*> "annotation" .: (text Nothing)
<*> (Set.fromList <$> "iswcs" .: listOf (const $ "iswc" .: iswcF) Nothing)
where
Expand All @@ -62,7 +62,7 @@ tree =


--------------------------------------------------------------------------------
viewAliases :: Form Text MusicBrainz (Set.Set Alias)
viewAliases :: Form Text MusicBrainz (Set.Set (Alias Work))
viewAliases = runApi $
MB.viewAliases <$> workRevision

Expand Down

0 comments on commit e1c8231

Please sign in to comment.