<commit_before>{-# LANGUAGE OverloadedStrings #-}
-----------------------------------------------------------------------------
-- |
-- Module : Web.Pagure.Users
-- Copyright : (C) 2015 <NAME>
-- License : BSD2 (see LICENSE file)
-- Maintainer : <NAME> <<EMAIL>>
-- Stability : experimental
-- Portability : ghc (lens)
--
-- Access to the \"Users\" endpoints of the Pagure API.
----------------------------------------------------------------------------
module Web.Pagure.Users where

import Control.Lens
import Data.Aeson.Lens
import Network.Wreq
import Web.Pagure.Internal.Wreq
import Web.Pagure.Types

-- | Access the @/users@ endpoint.
--
-- Example:
--
-- @
-- >>> import Web.Pagure
-- >>> let pc = PagureConfig "https://pagure.io" Nothing
-- >>> runPagureT users pc
-- ["adamwill","alphacc","asamalik","ausil","bkabrda","bochecha",[...]
-- @
users :: PagureT [Username]
users = do
  resp <- pagureGet "users"
  return $ resp ^.. responseBody . key "users" . values . _String

-- | Access the @/groups@ endpoint.
--
-- Example:
--
-- @
-- >>> import Web.Pagure
-- >>> let pc = PagureConfig "https://pagure.io" Nothing
-- >>> runPagureT groups pc
-- ["releng","Fedora-Infra"]
-- @
groups :: PagureT [Group]
groups = do
  resp <- pagureGet "groups"
  return $ resp ^.. responseBody . key "groups" . values . _String<commit_msg>Make users/groups take an optional pattern<commit_after>{-# LANGUAGE OverloadedStrings #-}
-----------------------------------------------------------------------------
-- |
-- Module : Web.Pagure.Users
-- Copyright : (C) 2015 <NAME>
-- License : BSD2 (see LICENSE file)
-- Maintainer : <NAME> <<EMAIL>>
-- Stability : experimental
-- Portability : ghc (lens)
--
-- Access to the \"Users\" endpoints of the Pagure API.
----------------------------------------------------------------------------
module Web.Pagure.Users where

import Control.Lens
import Data.Aeson.Lens
import qualified Data.Text as T
import Network.Wreq
import Web.Pagure.Internal.Wreq
import Web.Pagure.Types

-- | Access the @/users@ endpoint.
--
-- Example:
--
-- @
-- >>> import Web.Pagure
-- >>> let pc = PagureConfig "https://pagure.io" Nothing
-- >>> runPagureT users pc
-- ["adamwill","alphacc","asamalik","ausil","bkabrda","bochecha",[...]
-- @
users ::
  Maybe T.Text -- ^ Optional pattern to search for
  -> PagureT [Username]
users pattern = do
  opts <- pagureWreqOptions
  let opts' = case pattern of
        Nothing -> opts
        Just p -> opts & param "pattern" .~ [p]
  resp <- pagureGetWith opts' "users"
  return $ resp ^.. responseBody . key "users" . values . _String

-- | Access the @/groups@ endpoint.
--
-- Example:
--
-- @
-- >>> import Web.Pagure
-- >>> let pc = PagureConfig "https://pagure.io" Nothing
-- >>> runPagureT groups pc
-- ["releng","Fedora-Infra"]
-- @
groups ::
  Maybe T.Text -- ^ Optional pattern to search for
  -> PagureT [Group]
groups pattern = do
  opts <- pagureWreqOptions
  let opts' = case pattern of
        Nothing -> opts
        Just p -> opts & param "pattern" .~ [p]
  resp <- pagureGetWith opts' "groups"
  return $ resp ^.. responseBody . key "groups" . values . _String
{'fraction_non_alphanumeric': 0.2555094219099329, 'fraction_numerical': 0.0031938677738741618, 'mean_word_length': 2.049659201557936, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 53, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6309089', 'n_tokens_mistral': 974, 'n_tokens_neox': 951, 'n_words': 269}