-- |
-- The Github Search API, as described at
-- <http://developer.github.com/v3/search/>.

module GitHub.Endpoints.Search(
    searchReposR,
    searchCodeR,
    searchIssuesR,
    searchUsersR,
    module GitHub.Data,
    ) where

import GitHub.Data
import GitHub.Internal.Prelude
import Prelude ()

import qualified Data.Text.Encoding as TE

-- | Search repositories.
-- See <https://developer.github.com/v3/search/#search-repositories>
searchReposR :: Text -> FetchCount -> Request k (SearchResult Repo)
searchReposR :: forall (k :: RW).
Text -> FetchCount -> Request k (SearchResult Repo)
searchReposR Text
searchString =
    Paths
-> QueryString
-> FetchCount
-> GenRequest 'MtJSON k (SearchResult Repo)
forall a (t :: * -> *) b (mt :: MediaType (*)) (rw :: RW).
(a ~ t b, Foldable t, Semigroup a) =>
Paths -> QueryString -> FetchCount -> GenRequest mt rw a
PagedQuery [Text
"search", Text
"repositories"] [(ByteString
"q", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ Text -> ByteString
TE.encodeUtf8 Text
searchString)]

-- | Search code.
-- See <https://developer.github.com/v3/search/#search-code>
searchCodeR :: Text -> FetchCount -> Request k (SearchResult Code)
searchCodeR :: forall (k :: RW).
Text -> FetchCount -> Request k (SearchResult Code)
searchCodeR Text
searchString =
    Paths
-> QueryString
-> FetchCount
-> GenRequest 'MtJSON k (SearchResult Code)
forall a (t :: * -> *) b (mt :: MediaType (*)) (rw :: RW).
(a ~ t b, Foldable t, Semigroup a) =>
Paths -> QueryString -> FetchCount -> GenRequest mt rw a
PagedQuery [Text
"search", Text
"code"] [(ByteString
"q", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ Text -> ByteString
TE.encodeUtf8 Text
searchString)]

-- | Search issues.
-- See <https://developer.github.com/v3/search/#search-issues>
searchIssuesR :: Text -> FetchCount -> Request k (SearchResult Issue)
searchIssuesR :: forall (k :: RW).
Text -> FetchCount -> Request k (SearchResult Issue)
searchIssuesR Text
searchString =
    Paths
-> QueryString
-> FetchCount
-> GenRequest 'MtJSON k (SearchResult Issue)
forall a (t :: * -> *) b (mt :: MediaType (*)) (rw :: RW).
(a ~ t b, Foldable t, Semigroup a) =>
Paths -> QueryString -> FetchCount -> GenRequest mt rw a
PagedQuery [Text
"search", Text
"issues"] [(ByteString
"q", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ Text -> ByteString
TE.encodeUtf8 Text
searchString)]

-- | Search users.
-- See <https://developer.github.com/v3/search/#search-code>
searchUsersR :: Text -> FetchCount -> Request k (SearchResult SimpleUser)
searchUsersR :: forall (k :: RW).
Text -> FetchCount -> Request k (SearchResult SimpleUser)
searchUsersR Text
searchString =
    Paths
-> QueryString
-> FetchCount
-> GenRequest 'MtJSON k (SearchResult SimpleUser)
forall a (t :: * -> *) b (mt :: MediaType (*)) (rw :: RW).
(a ~ t b, Foldable t, Semigroup a) =>
Paths -> QueryString -> FetchCount -> GenRequest mt rw a
PagedQuery [Text
"search", Text
"users"] [(ByteString
"q", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ Text -> ByteString
TE.encodeUtf8 Text
searchString)]