forked from haskell-github/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding read-only parts of emails endpoint
- Loading branch information
Showing
6 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Main (main) where | ||
|
||
import Common | ||
import Prelude () | ||
import qualified GitHub.Endpoints.Users.Emails as GitHub | ||
|
||
|
||
main :: IO () | ||
main = do | ||
emails <- GitHub.currentUserEmails' (GitHub.OAuth "token") | ||
putStrLn $ either (("Error: " <>) . tshow) | ||
(foldMap ((<> "\n") . formatEmail)) | ||
emails | ||
|
||
formatEmail :: GitHub.Email -> Text | ||
formatEmail e = GitHub.emailAddress e <> if GitHub.emailPrimary e then " [primary]" else "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
----------------------------------------------------------------------------- | ||
-- | | ||
-- License : BSD-3-Clause | ||
-- Maintainer : Oleg Grenrus <[email protected]> | ||
-- | ||
module GitHub.Data.Email where | ||
|
||
import GitHub.Internal.Prelude | ||
import Prelude () | ||
|
||
data EmailVisibility | ||
= EmailVisibilityPrivate | ||
| EmailVisibilityPublic | ||
deriving (Show, Data, Enum, Bounded, Typeable, Eq, Ord, Generic) | ||
|
||
instance NFData EmailVisibility where rnf = genericRnf | ||
instance Binary EmailVisibility | ||
|
||
instance FromJSON EmailVisibility where | ||
parseJSON (String "private") = pure EmailVisibilityPrivate | ||
parseJSON (String "public") = pure EmailVisibilityPublic | ||
parseJSON _ = fail "Could not build an EmailVisibility" | ||
|
||
data Email = Email | ||
{ emailAddress :: !Text | ||
, emailVerified :: !Bool | ||
, emailPrimary :: !Bool | ||
, emailVisibility :: !(Maybe EmailVisibility) | ||
} deriving (Show, Data, Typeable, Eq, Ord, Generic) | ||
|
||
instance NFData Email where rnf = genericRnf | ||
instance Binary Email | ||
|
||
instance FromJSON Email where | ||
parseJSON = withObject "Email" $ \o -> Email | ||
<$> o .: "email" | ||
<*> o .: "verified" | ||
<*> o .: "primary" | ||
<*> o .:? "visibility" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
----------------------------------------------------------------------------- | ||
-- | | ||
-- License : BSD-3-Clause | ||
-- Maintainer : Oleg Grenrus <[email protected]> | ||
-- | ||
-- The user emails API as described on | ||
-- <http://developer.github.com/v3/users/emails/>. | ||
module GitHub.Endpoints.Users.Emails ( | ||
currentUserEmails', | ||
currentUserEmailsR, | ||
currentUserPublicEmails', | ||
currentUserPublicEmailsR, | ||
module GitHub.Data, | ||
) where | ||
|
||
import GitHub.Data | ||
import GitHub.Internal.Prelude | ||
import GitHub.Request | ||
import Prelude () | ||
|
||
-- | List email addresses for the authenticated user. | ||
-- | ||
-- > currentUserEmails' (OAuth "token") | ||
currentUserEmails' :: Auth -> IO (Either Error (Vector Email)) | ||
currentUserEmails' auth = | ||
executeRequest auth $ currentUserEmailsR FetchAll | ||
|
||
-- | List email addresses. | ||
-- See <https://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user> | ||
currentUserEmailsR :: FetchCount -> Request 'RA (Vector Email) | ||
currentUserEmailsR = | ||
pagedQuery ["user", "emails"] [] | ||
|
||
-- | List public email addresses for the authenticated user. | ||
-- | ||
-- > currentUserPublicEmails' (OAuth "token") | ||
currentUserPublicEmails' :: Auth -> IO (Either Error (Vector Email)) | ||
currentUserPublicEmails' auth = | ||
executeRequest auth $ currentUserPublicEmailsR FetchAll | ||
|
||
-- | List public email addresses. | ||
-- See <https://developer.github.com/v3/users/emails/#list-public-email-addresses-for-a-user> | ||
currentUserPublicEmailsR :: FetchCount -> Request 'RA (Vector Email) | ||
currentUserPublicEmailsR = | ||
pagedQuery ["user", "public_emails"] [] |