Skip to content

Commit 3d3906b

Browse files
committed
Github.Organizations.publicOrganizationsFor - all the public organizations for a user.
1 parent 018a20c commit 3d3906b

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

Github/Data.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ instance FromJSON EventType where
268268
parseJSON (String "unsubscribed") = pure Unsubscribed
269269
parseJSON _ = fail "Could not build an EventType"
270270

271+
instance FromJSON SimpleOrganization where
272+
parseJSON (Object o) =
273+
SimpleOrganization <$> o .: "url"
274+
<*> o .: "avatar_url"
275+
<*> o .: "id"
276+
<*> o .: "login"
277+
parseJSON _ = fail "Could not build a SimpleOrganization"
278+
271279
-- | A better version of Aeson's .:?, using `mzero' instead of `Nothing'
272280
(.:<) :: (FromJSON a) => Object -> T.Text -> Parser [a]
273281
obj .:< key = case Map.lookup key obj of

Github/Data/Definitions.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,10 @@ data Event = Event {
242242
,eventId :: Int
243243
,eventIssue :: Maybe Issue
244244
} deriving (Show, Data, Typeable, Eq, Ord)
245+
246+
data SimpleOrganization = SimpleOrganization {
247+
simpleOrganizationUrl :: String
248+
,simpleOrganizationAvatarUrl :: String
249+
,simpleOrganizationId :: Int
250+
,simpleOrganizationLogin :: String
251+
} deriving (Show, Data, Typeable, Eq, Ord)

Github/Organizations.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Github.Organizations (
2+
publicOrganizationsFor
3+
,module Github.Data
4+
) where
5+
6+
import Github.Data
7+
import Github.Private
8+
9+
publicOrganizationsFor :: String -> IO (Either Error [SimpleOrganization])
10+
publicOrganizationsFor userName = githubGet ["users", userName, "orgs"]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module ShowPublicOrganizations where
2+
3+
import qualified Github.Organizations as Github
4+
import Data.List (intercalate)
5+
6+
main = do
7+
possibleOrganizations <- Github.publicOrganizationsFor "mike-burns"
8+
case possibleOrganizations of
9+
(Left error) -> putStrLn $ "Error: " ++ (show error)
10+
(Right organizations) ->
11+
putStrLn $ intercalate "\n" $ map formatOrganization organizations
12+
13+
formatOrganization = Github.simpleOrganizationLogin

0 commit comments

Comments
 (0)