@@ -3,16 +3,36 @@ package com.codacy.client.bitbucket.service
3
3
import com .codacy .client .bitbucket .Service
4
4
import com .codacy .client .bitbucket .client .{BitbucketClient , Request , RequestResponse }
5
5
6
- class HookServices (client : BitbucketClient ) {
6
+ class ServiceServices (client : BitbucketClient ) {
7
7
8
- def createPostPushHook (author : String , repo : String , hookUrl : String ): RequestResponse [Service ] = {
9
- val url = s " https://bitbucket.org/!api/1.0/repositories/ $ author/ $ repo/services "
8
+ def list (author : String , repo : String ): RequestResponse [Seq [ Service ]] =
9
+ AuthorRepoOps ( author, repo).list()
10
10
11
- val payload = Map (
12
- " type" -> " POST" ,
13
- " URL" -> hookUrl
14
- ).mapValues(Seq (_))
11
+ /* def byId(author: String, repo: String, id:Long) = {
12
+ val resp = AuthorRepoOps(author,repo).list()
13
+ val value = resp.value.map(_.find(_.id == id))
14
+ resp.copy(value = value)
15
+ }*/
15
16
16
- client.post(Request (url, classOf [Service ]), payload)
17
+ def created (author : String , repo : String , payload : Map [String ,Seq [String ]]) =
18
+ AuthorRepoOps (author,repo).created(payload)
19
+
20
+ def removed (author : String , repo : String , id: Long ) =
21
+ AuthorRepoOps (author,repo).removed(id)
22
+
23
+ private [this ] lazy val BASE_URL : String = " https://bitbucket.org/!api/1.0/repositories"
24
+ private [this ] def servicesUrl (author : String , repo : String ) = s " $BASE_URL/ $author/ $repo/services "
25
+
26
+ private [this ] case class AuthorRepoOps (author : String , repo : String ){
27
+ private [this ] lazy val BASE_URL = servicesUrl(author,repo)
28
+
29
+ def created (payload : Map [String ,Seq [String ]]): RequestResponse [Service ] =
30
+ client.post(Request (BASE_URL ,classOf [Service ]),payload)
31
+
32
+ def removed (id: Long ): RequestResponse [Boolean ] =
33
+ client.delete(Request (s " %BASE_URL/ $id" ,classOf [Boolean ]))
34
+
35
+ def list (): RequestResponse [Seq [Service ]] =
36
+ client.execute(Request (BASE_URL ,classOf [Seq [Service ]]))
17
37
}
18
38
}
0 commit comments