Skip to content

Commit ac88319

Browse files
author
Johann Egger
committed
delete request implemented
1 parent 0c4372e commit ac88319

File tree

2 files changed

+10
-31
lines changed

2 files changed

+10
-31
lines changed

src/main/scala/com/codacy/client/bitbucket/client/BitbucketClient.scala

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,36 +75,20 @@ class BitbucketClient(key: String, secretKey: String, token: String, secretToken
7575
}
7676
}
7777
/* copy paste from post ... */
78-
def delete[T](request: Request[T])(implicit reader: Reads[T]): RequestResponse[T] = {
78+
def delete[T](url: String): RequestResponse[Boolean] = {
7979
val client: WSClient = new NingWSClient(new AsyncHttpClient().getConfig)
8080

81-
val jpromise = client.url(request.url).sign(OAuthCalculator(KEY, TOKEN)).withFollowRedirects(follow = true).delete()
81+
val jpromise = client.url(url).sign(OAuthCalculator(KEY, TOKEN)).withFollowRedirects(follow = true).delete()
8282
val result = Await.result(jpromise, Duration(10, SECONDS))
8383

84-
if (Seq(HTTPStatusCodes.OK, HTTPStatusCodes.CREATED).contains(result.status)) {
85-
val body = result.body
86-
87-
/* TODO: remove this when not needed (only keep for debug purposes) */
88-
// println("\n\n")
89-
// println(s"STATUS: ${result.status}")
90-
// println("\n\n")
91-
// println(body)
92-
// println("\n\n")
93-
94-
val jsValue = parseJson(body)
95-
jsValue match {
96-
case Right(responseObj) =>
97-
RequestResponse(responseObj.asOpt[T])
98-
case Left(message) =>
99-
RequestResponse(None, message = message.detail, hasError = true)
100-
}
101-
} else {
84+
if (Seq(HTTPStatusCodes.OK, HTTPStatusCodes.CREATED, HTTPStatusCodes.NO_CONTENT).contains(result.status)) {
85+
RequestResponse(Option(true))
86+
}
87+
else {
10288
RequestResponse(None, result.statusText, hasError = true)
10389
}
10490
}
10591

106-
107-
10892
private def get(url: String): Either[ResponseError, JsValue] = {
10993
val client: WSClient = new NingWSClient(new AsyncHttpClient().getConfig)
11094

src/main/scala/com/codacy/client/bitbucket/service/HookServices.scala

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,10 @@ class ServiceServices(client: BitbucketClient) {
88
def list(author: String, repo: String): RequestResponse[Seq[Service]] =
99
AuthorRepoOps(author,repo).list()
1010

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-
}*/
16-
1711
def created(author: String, repo: String, payload: Map[String,Seq[String]]) =
1812
AuthorRepoOps(author,repo).created(payload)
1913

20-
def removed(author: String, repo: String, id:Long) =
14+
def removed(author: String, repo: String, id:Long): RequestResponse[Boolean] =
2115
AuthorRepoOps(author,repo).removed(id)
2216

2317
private[this] lazy val BASE_URL: String = "https://bitbucket.org/!api/1.0/repositories"
@@ -29,8 +23,9 @@ class ServiceServices(client: BitbucketClient) {
2923
def created(payload: Map[String,Seq[String]]): RequestResponse[Service] =
3024
client.post(Request(BASE_URL,classOf[Service]),payload)
3125

32-
def removed(id:Long): RequestResponse[Boolean] =
33-
client.delete(Request(s"%BASE_URL/$id",classOf[Boolean]))
26+
def removed(id:Long): RequestResponse[Boolean] = {
27+
client.delete(s"$BASE_URL/$id")
28+
}
3429

3530
def list(): RequestResponse[Seq[Service]] =
3631
client.execute(Request(BASE_URL,classOf[Seq[Service]]))

0 commit comments

Comments
 (0)