Skip to content

Commit

Permalink
Add type aliases to minimize diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
himura committed Nov 17, 2021
1 parent a10c8fb commit 7f8c982
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Web/Twitter/Conduit/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ search = searchTweets
-- APIRequest "GET" "https://api.twitter.com/1.1/direct_messages/events/list.json" []
-- >>> directMessages & #count ?~ 50
-- APIRequest "GET" "https://api.twitter.com/1.1/direct_messages/events/list.json" [("count","50")]
directMessages :: APIRequest DirectMessages (WithCursor T.Text "events" DirectMessage)
directMessages :: APIRequest DirectMessages (WithCursor T.Text EventsCursorKey DirectMessage)
directMessages = APIRequest "GET" (endpoint ++ "direct_messages/events/list.json") def

type DirectMessages =
Expand Down Expand Up @@ -653,7 +653,7 @@ type FriendshipsNoRetweetsIds = EmptyParams
-- APIRequest "GET" "https://api.twitter.com/1.1/friends/ids.json" [("screen_name","thimura")]
-- >>> friendsIds (ScreenNameParam "thimura") & #count ?~ 5000
-- APIRequest "GET" "https://api.twitter.com/1.1/friends/ids.json" [("count","5000"),("screen_name","thimura")]
friendsIds :: UserParam -> APIRequest FriendsIds (WithCursor Integer "ids" UserId)
friendsIds :: UserParam -> APIRequest FriendsIds (WithCursor Integer IdsCursorKey UserId)
friendsIds q = APIRequest "GET" (endpoint ++ "friends/ids.json") (mkUserParam q)

type FriendsIds =
Expand All @@ -679,7 +679,7 @@ type FriendsIds =
-- APIRequest "GET" "https://api.twitter.com/1.1/followers/ids.json" [("screen_name","thimura")]
-- >>> followersIds (ScreenNameParam "thimura") & #count ?~ 5000
-- APIRequest "GET" "https://api.twitter.com/1.1/followers/ids.json" [("count","5000"),("screen_name","thimura")]
followersIds :: UserParam -> APIRequest FollowersIds (WithCursor Integer "ids" UserId)
followersIds :: UserParam -> APIRequest FollowersIds (WithCursor Integer IdsCursorKey UserId)
followersIds q = APIRequest "GET" (endpoint ++ "followers/ids.json") (mkUserParam q)

type FollowersIds =
Expand All @@ -703,7 +703,7 @@ type FollowersIds =
--
-- >>> friendshipsIncoming
-- APIRequest "GET" "https://api.twitter.com/1.1/friendships/incoming.json" []
friendshipsIncoming :: APIRequest FriendshipsIncoming (WithCursor Integer "ids" UserId)
friendshipsIncoming :: APIRequest FriendshipsIncoming (WithCursor Integer IdsCursorKey UserId)
friendshipsIncoming = APIRequest "GET" (endpoint ++ "friendships/incoming.json") def

type FriendshipsIncoming =
Expand All @@ -726,7 +726,7 @@ type FriendshipsIncoming =
--
-- >>> friendshipsOutgoing
-- APIRequest "GET" "https://api.twitter.com/1.1/friendships/outgoing.json" []
friendshipsOutgoing :: APIRequest FriendshipsOutgoing (WithCursor Integer "ids" UserId)
friendshipsOutgoing :: APIRequest FriendshipsOutgoing (WithCursor Integer IdsCursorKey UserId)
friendshipsOutgoing = APIRequest "GET" (endpoint ++ "friendships/outgoing.json") def

type FriendshipsOutgoing =
Expand Down Expand Up @@ -787,7 +787,7 @@ type FriendshipsDestroy = EmptyParams
-- APIRequest "GET" "https://api.twitter.com/1.1/friends/list.json" [("screen_name","thimura")]
-- >>> friendsList (UserIdParam 69179963)
-- APIRequest "GET" "https://api.twitter.com/1.1/friends/list.json" [("user_id","69179963")]
friendsList :: UserParam -> APIRequest FriendsList (WithCursor Integer "users" User)
friendsList :: UserParam -> APIRequest FriendsList (WithCursor Integer UsersCursorKey User)
friendsList q = APIRequest "GET" (endpoint ++ "friends/list.json") (mkUserParam q)

type FriendsList =
Expand Down Expand Up @@ -815,7 +815,7 @@ type FriendsList =
-- APIRequest "GET" "https://api.twitter.com/1.1/followers/list.json" [("screen_name","thimura")]
-- >>> followersList (UserIdParam 69179963)
-- APIRequest "GET" "https://api.twitter.com/1.1/followers/list.json" [("user_id","69179963")]
followersList :: UserParam -> APIRequest FollowersList (WithCursor Integer "users" User)
followersList :: UserParam -> APIRequest FollowersList (WithCursor Integer UsersCursorKey User)
followersList q = APIRequest "GET" (endpoint ++ "followers/list.json") (mkUserParam q)

type FollowersList =
Expand Down Expand Up @@ -1027,7 +1027,7 @@ type ListsMembersDestroy = EmptyParams
-- APIRequest "GET" "https://api.twitter.com/1.1/lists/memberships.json" [("screen_name","thimura")]
-- >>> listsMemberships (Just (UserIdParam 69179963))
-- APIRequest "GET" "https://api.twitter.com/1.1/lists/memberships.json" [("user_id","69179963")]
listsMemberships :: Maybe UserParam -> APIRequest ListsMemberships (WithCursor Integer "lists" List)
listsMemberships :: Maybe UserParam -> APIRequest ListsMemberships (WithCursor Integer ListsCursorKey List)
listsMemberships q = APIRequest "GET" (endpoint ++ "lists/memberships.json") $ maybe [] mkUserParam q

type ListsMemberships =
Expand All @@ -1047,7 +1047,7 @@ type ListsMemberships =
-- APIRequest "GET" "https://api.twitter.com/1.1/lists/subscribers.json" [("slug","haskell"),("owner_screen_name","thimura")]
-- >>> listsSubscribers (ListIdParam 20849097)
-- APIRequest "GET" "https://api.twitter.com/1.1/lists/subscribers.json" [("list_id","20849097")]
listsSubscribers :: ListParam -> APIRequest ListsSubscribers (WithCursor Integer "users" User)
listsSubscribers :: ListParam -> APIRequest ListsSubscribers (WithCursor Integer UsersCursorKey User)
listsSubscribers q = APIRequest "GET" (endpoint ++ "lists/subscribers.json") (mkListParam q)

type ListsSubscribers =
Expand All @@ -1070,7 +1070,7 @@ type ListsSubscribers =
-- APIRequest "GET" "https://api.twitter.com/1.1/lists/subscriptions.json" [("screen_name","thimura")]
-- >>> listsSubscriptions (Just (UserIdParam 69179963))
-- APIRequest "GET" "https://api.twitter.com/1.1/lists/subscriptions.json" [("user_id","69179963")]
listsSubscriptions :: Maybe UserParam -> APIRequest ListsSubscriptions (WithCursor Integer "lists" List)
listsSubscriptions :: Maybe UserParam -> APIRequest ListsSubscriptions (WithCursor Integer ListsCursorKey List)
listsSubscriptions q = APIRequest "GET" (endpoint ++ "lists/subscriptions.json") $ maybe [] mkUserParam q

type ListsSubscriptions =
Expand All @@ -1092,7 +1092,7 @@ type ListsSubscriptions =
-- APIRequest "GET" "https://api.twitter.com/1.1/lists/ownerships.json" [("screen_name","thimura")]
-- >>> listsOwnerships (Just (UserIdParam 69179963))
-- APIRequest "GET" "https://api.twitter.com/1.1/lists/ownerships.json" [("user_id","69179963")]
listsOwnerships :: Maybe UserParam -> APIRequest ListsOwnerships (WithCursor Integer "lists" List)
listsOwnerships :: Maybe UserParam -> APIRequest ListsOwnerships (WithCursor Integer ListsCursorKey List)
listsOwnerships q = APIRequest "GET" (endpoint ++ "lists/ownerships.json") $ maybe [] mkUserParam q

type ListsOwnerships =
Expand Down Expand Up @@ -1146,7 +1146,7 @@ type ListsMembersDestroyAll = EmptyParams
-- APIRequest "GET" "https://api.twitter.com/1.1/lists/members.json" [("slug","haskell"),("owner_screen_name","thimura")]
-- >>> listsMembers (ListIdParam 20849097)
-- APIRequest "GET" "https://api.twitter.com/1.1/lists/members.json" [("list_id","20849097")]
listsMembers :: ListParam -> APIRequest ListsMembers (WithCursor Integer "users" User)
listsMembers :: ListParam -> APIRequest ListsMembers (WithCursor Integer UsersCursorKey User)
listsMembers q = APIRequest "GET" (endpoint ++ "lists/members.json") (mkListParam q)

type ListsMembers =
Expand Down
9 changes: 9 additions & 0 deletions Web/Twitter/Conduit/Cursor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
{-# LANGUAGE ScopedTypeVariables #-}

module Web.Twitter.Conduit.Cursor (
IdsCursorKey,
UsersCursorKey,
ListsCursorKey,
EventsCursorKey,
WithCursor (..),
) where

Expand All @@ -22,6 +26,11 @@ import GHC.TypeLits (KnownSymbol, Symbol, symbolVal)
-- >>> import Data.Text
-- >>> type UserId = Integer

type IdsCursorKey = "ids"
type UsersCursorKey = "users"
type ListsCursorKey = "lists"
type EventsCursorKey = "events"

-- | A wrapper for API responses which have "next_cursor" field.
--
-- The first type parameter of 'WithCursor' specifies the field name of contents.
Expand Down

0 comments on commit 7f8c982

Please sign in to comment.