Properly handle empty "location" fields.

This commit is contained in:
Andrew Darqui 2016-06-20 02:14:11 -04:00
parent 3f204a9ae3
commit 8241ef5e97

View File

@ -37,7 +37,7 @@ data GithubUser = GithubUser
, githubUserName :: Maybe Text , githubUserName :: Maybe Text
, githubUserLogin :: Text , githubUserLogin :: Text
, githubUserAvatarUrl :: Text , githubUserAvatarUrl :: Text
, githubUserLocation :: Text , githubUserLocation :: Maybe Text
, githubUserPublicEmail :: Maybe Text , githubUserPublicEmail :: Maybe Text
} }
@ -47,8 +47,8 @@ instance FromJSON GithubUser where
<*> o .:? "name" <*> o .:? "name"
<*> o .: "login" <*> o .: "login"
<*> o .: "avatar_url" <*> o .: "avatar_url"
<*> o .: "location" <*> o .:? "location"
<*> o .: "email" <*> o .:? "email"
parseJSON _ = mzero parseJSON _ = mzero
@ -104,11 +104,11 @@ toCreds user userMails token = Creds
[ ("email", githubUserEmailAddress email) [ ("email", githubUserEmailAddress email)
, ("login", githubUserLogin user) , ("login", githubUserLogin user)
, ("avatar_url", githubUserAvatarUrl user) , ("avatar_url", githubUserAvatarUrl user)
, ("location", githubUserLocation user)
, ("access_token", decodeUtf8 $ accessToken token) , ("access_token", decodeUtf8 $ accessToken token)
] ]
++ maybeName (githubUserName user) ++ maybeName (githubUserName user)
++ maybePublicEmail (githubUserPublicEmail user) ++ maybePublicEmail (githubUserPublicEmail user)
++ maybeLocation (githubUserLocation user)
} }
where where
@ -119,3 +119,6 @@ toCreds user userMails token = Creds
maybePublicEmail Nothing = [] maybePublicEmail Nothing = []
maybePublicEmail (Just e) = [("public_email", e)] maybePublicEmail (Just e) = [("public_email", e)]
maybeLocation Nothing = []
maybeLocation (Just location) = [("location", location)]