Skip to content

Commit 874bd4a

Browse files
committed
Use stack to build samples (only one atm)
1 parent d83478a commit 874bd4a

38 files changed

Lines changed: 222 additions & 143 deletions

Github/Activity/Starring.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ stargazersFor auth user repo =
2727
-- See <https://developer.github.com/v3/activity/starring/#list-stargazers>
2828
stargazersForR :: Name GithubOwner -> Name Repo -> Maybe Count -> GithubRequest k (Vector GithubOwner)
2929
stargazersForR user repo =
30-
GithubPagedGet ["repos", untagName user, untagName repo, "stargazers"] []
30+
GithubPagedGet ["repos", toPathPart user, toPathPart repo, "stargazers"] []
3131

3232
-- | All the public repos starred by the specified user.
3333
--
@@ -40,7 +40,7 @@ reposStarredBy auth user =
4040
-- See <https://developer.github.com/v3/activity/starring/#list-repositories-being-starred>
4141
reposStarredByR :: Name GithubOwner -> Maybe Count -> GithubRequest k (Vector Repo)
4242
reposStarredByR user =
43-
GithubPagedGet ["users", untagName user, "starred"] []
43+
GithubPagedGet ["users", toPathPart user, "starred"] []
4444

4545
-- | All the repos starred by the authenticated user.
4646
myStarred :: GithubAuth -> IO (Either Error (Vector Repo))

Github/Activity/Watching.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ watchersFor' auth user repo =
3333
-- See <https://developer.github.com/v3/activity/watching/#list-watchers>
3434
watchersForR :: Name GithubOwner -> Name Repo -> Maybe Count -> GithubRequest k (Vector GithubOwner)
3535
watchersForR user repo limit =
36-
GithubPagedGet ["repos", untagName user, untagName repo, "watchers"] [] limit
36+
GithubPagedGet ["repos", toPathPart user, toPathPart repo, "watchers"] [] limit
3737

3838
-- | All the public repos watched by the specified user.
3939
--
@@ -53,4 +53,4 @@ reposWatchedBy' auth user =
5353
-- See <https://developer.github.com/v3/activity/watching/#list-repositories-being-watched>
5454
reposWatchedByR :: Name GithubOwner -> Maybe Count -> GithubRequest k (Vector Repo)
5555
reposWatchedByR user =
56-
GithubPagedGet ["users", untagName user, "subscriptions"] []
56+
GithubPagedGet ["users", toPathPart user, "subscriptions"] []

Github/Data.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
module Github.Data (
1111
-- * Module re-exports
12+
module Github.Auth,
1213
module Github.Data.Definitions,
1314
module Github.Data.Gists,
1415
module Github.Data.GitData,
@@ -42,6 +43,7 @@ import qualified Data.HashMap.Lazy as Map
4243
import qualified Data.Text as T
4344
import qualified Data.Vector as V
4445

46+
import Github.Auth
4547
import Github.Data.Definitions
4648
import Github.Data.Gists
4749
import Github.Data.GitData

Github/Data/Definitions.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ data Error =
3535

3636
data SimpleOwner = SimpleUserOwner {
3737
simpleOwnerAvatarUrl :: !Text
38-
,simpleOwnerLogin :: !(Name SimpleOwner)
38+
,simpleOwnerLogin :: !(Name GithubOwner)
3939
,simpleOwnerUrl :: !Text
40-
,simpleOwnerId :: !(Id SimpleOwner)
40+
,simpleOwnerId :: !(Id GithubOwner)
4141
,simpleOwnerGravatarId :: !(Maybe Text)
4242
}
4343
| SimpleOrganizationOwner {
4444
simpleOwnerAvatarUrl :: !Text
45-
,simpleOwnerLogin :: !(Name SimpleOwner)
45+
,simpleOwnerLogin :: !(Name GithubOwner)
4646
,simpleOwnerUrl :: !Text
47-
,simpleOwnerId :: !(Id SimpleOwner)
47+
,simpleOwnerId :: !(Id GithubOwner)
4848
} deriving (Show, Data, Typeable, Eq, Ord, Generic)
4949

5050
instance NFData SimpleOwner where rnf = genericRnf
@@ -183,9 +183,9 @@ data GithubOwner = GithubUser {
183183
,githubOwnerCompany :: !(Maybe Text)
184184
,githubOwnerEmail :: !(Maybe Text)
185185
,githubOwnerUrl :: !Text
186-
,githubOwnerId :: !(Id SimpleOwner)
186+
,githubOwnerId :: !(Id GithubOwner)
187187
,githubOwnerHtmlUrl :: !Text
188-
,githubOwnerLogin :: !(Name SimpleOwner)
188+
,githubOwnerLogin :: !(Name GithubOwner)
189189
}
190190
| GithubOrganization {
191191
githubOwnerCreatedAt :: !UTCTime
@@ -201,9 +201,9 @@ data GithubOwner = GithubUser {
201201
,githubOwnerLocation :: !(Maybe Text)
202202
,githubOwnerCompany :: !(Maybe Text)
203203
,githubOwnerUrl :: !Text
204-
,githubOwnerId :: !(Id SimpleOwner)
204+
,githubOwnerId :: !(Id GithubOwner)
205205
,githubOwnerHtmlUrl :: !Text
206-
,githubOwnerLogin :: !(Name SimpleOwner)
206+
,githubOwnerLogin :: !(Name GithubOwner)
207207
} deriving (Show, Data, Typeable, Eq, Ord, Generic)
208208

209209
instance NFData GithubOwner where rnf = genericRnf

Github/Data/Name.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ import Data.String (IsString (..))
1414
import Data.Text (Text)
1515
import GHC.Generics (Generic)
1616

17-
import qualified Data.Text as T
18-
1917
newtype Name entity = N Text
2018
deriving (Eq, Ord, Show, Read, Generic, Typeable, Data)
2119

2220
-- | Smart constructor for 'Name'
2321
mkName :: proxy entity -> Text -> Name entity
2422
mkName _ = N
2523

26-
untagName :: Name entity -> String
27-
untagName (N name) = T.unpack name
24+
untagName :: Name entity -> Text
25+
untagName (N name) = name
2826

2927
instance Hashable (Name entity)
3028

Github/Data/Request.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Github.Data.Request (
1212
PostMethod(..),
1313
toMethod,
1414
Paths,
15+
IsPathPart(..),
1516
QueryString,
1617
Count,
1718
) where
@@ -24,8 +25,12 @@ import Network.HTTP.Types (Status)
2425

2526
import qualified Data.ByteString as BS
2627
import qualified Data.ByteString.Lazy as LBS
28+
import qualified Data.Text as T
2729
import qualified Network.HTTP.Types.Method as Method
2830

31+
import Github.Data.Id (Id, untagId)
32+
import Github.Data.Name (Name, untagName)
33+
2934
------------------------------------------------------------------------------
3035
-- Auxillary types
3136
------------------------------------------------------------------------------
@@ -34,6 +39,15 @@ type Paths = [String]
3439
type QueryString = [(BS.ByteString, Maybe BS.ByteString)]
3540
type Count = Int
3641

42+
class IsPathPart a where
43+
toPathPart :: a -> String
44+
45+
instance IsPathPart (Name a) where
46+
toPathPart = T.unpack . untagName
47+
48+
instance IsPathPart (Id a) where
49+
toPathPart = show . untagId
50+
3751
-- | Http method of requests with body.
3852
data PostMethod = Post | Patch | Put
3953
deriving (Eq, Ord, Read, Show, Enum, Bounded, Generic, Typeable)

Github/Gists.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ gists = gists' Nothing
3030
-- | List gists.
3131
-- See <https://developer.github.com/v3/gists/#list-gists>
3232
gistsR :: Name GithubOwner -> Maybe Count -> GithubRequest k (Vector Gist)
33-
gistsR user = GithubPagedGet ["users", untagName user, "gists"] []
33+
gistsR user = GithubPagedGet ["users", toPathPart user, "gists"] []
3434

3535
-- | A specific gist, given its id, with authentication credentials
3636
--
@@ -49,4 +49,4 @@ gist = gist' Nothing
4949
-- See <https://developer.github.com/v3/gists/#get-a-single-gist>
5050
gistR :: Name Gist ->GithubRequest k Gist
5151
gistR gid =
52-
GithubGet ["gists", untagName gid] []
52+
GithubGet ["gists", toPathPart gid] []

Github/Gists/Comments.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ commentsOn gid =
2323
-- See <https://developer.github.com/v3/gists/comments/#list-comments-on-a-gist>
2424
commentsOnR :: Name Gist -> Maybe Count -> GithubRequest k (Vector GistComment)
2525
commentsOnR gid =
26-
GithubPagedGet ["gists", untagName gid, "comments"] []
26+
GithubPagedGet ["gists", toPathPart gid, "comments"] []
2727

2828
-- | A specific comment, by the comment ID.
2929
--
@@ -36,4 +36,4 @@ comment cid =
3636
-- See <https://developer.github.com/v3/gists/comments/#get-a-single-comment>
3737
gistCommentR :: Id GistComment -> GithubRequest k GistComment
3838
gistCommentR cid =
39-
GithubGet ["gists", "comments", show $ untagId cid] []
39+
GithubGet ["gists", "comments", toPathPart cid] []

Github/GitData/Blobs.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ blob = blob' Nothing
2828
-- See <https://developer.github.com/v3/git/blobs/#get-a-blob>
2929
blobR :: Name GithubOwner -> Name Repo -> Name Blob -> GithubRequest k Blob
3030
blobR user repo sha =
31-
GithubGet ["repos", untagName user, untagName repo, "git", "blobs", untagName sha] []
31+
GithubGet ["repos", toPathPart user, toPathPart repo, "git", "blobs", toPathPart sha] []

Github/GitData/Commits.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ commit user repo sha =
2020
-- See <https://developer.github.com/v3/git/commits/#get-a-commit>
2121
gitCommitR :: Name GithubOwner -> Name Repo -> Name GitCommit -> GithubRequest k GitCommit
2222
gitCommitR user repo sha =
23-
GithubGet ["repos", untagName user, untagName repo, "git", "commits", untagName sha] []
23+
GithubGet ["repos", toPathPart user, toPathPart repo, "git", "commits", toPathPart sha] []

0 commit comments

Comments
 (0)