-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cca3c10
commit 91574bd
Showing
29 changed files
with
174 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
src/main/scala/io/github/daviddenton/fintrospect/DescribingRenderer.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/scala/io/github/daviddenton/fintrospect/util/ArgoJsonResponseBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.github.daviddenton.fintrospect.util | ||
|
||
import argo.jdom.JsonRootNode | ||
import com.twitter.finagle.http.path.Path | ||
import io.github.daviddenton.fintrospect.Route | ||
import io.github.daviddenton.fintrospect.util.ArgoUtil._ | ||
|
||
import scala.language.implicitConversions | ||
|
||
class ArgoJsonResponseBuilder(descBuilder: (Path, Seq[Route]) => JsonRootNode) extends TypedResponseBuilder[JsonRootNode]( | ||
() => new JsonResponseBuilder, | ||
descBuilder, | ||
badParameters => { | ||
val messages = badParameters.map(p => obj( | ||
"name" -> string(p.name), | ||
"type" -> string(p.where), | ||
"datatype" -> string(p.paramType.name), | ||
"required" -> boolean(p.requirement.required) | ||
)) | ||
|
||
obj("message" -> string("Missing/invalid parameters"), "params" -> array(messages)) | ||
}) |
34 changes: 34 additions & 0 deletions
34
src/main/scala/io/github/daviddenton/fintrospect/util/JsonResponseBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.github.daviddenton.fintrospect.util | ||
|
||
import argo.format.PrettyJsonFormatter | ||
import argo.jdom.JsonRootNode | ||
import io.github.daviddenton.fintrospect.ContentTypes | ||
import io.github.daviddenton.fintrospect.util.ArgoUtil._ | ||
import org.jboss.netty.handler.codec.http.{HttpResponseStatus, HttpResponse} | ||
import org.jboss.netty.handler.codec.http.HttpResponseStatus._ | ||
|
||
class JsonResponseBuilder extends ResponseBuilder[JsonRootNode]( | ||
new PrettyJsonFormatter().format, | ||
errorMessage => obj("message" -> string(errorMessage)), | ||
throwable => string(Option(throwable.getMessage).getOrElse(throwable.getClass.getName)).asInstanceOf[JsonRootNode], | ||
ContentTypes.APPLICATION_JSON) | ||
|
||
object JsonResponseBuilder { | ||
|
||
def Response() = apply() | ||
|
||
def Ok: HttpResponse = apply().withCode(OK).build | ||
|
||
def Ok(content: JsonRootNode): HttpResponse = apply().withCode(OK).withContent(content).build | ||
|
||
def Ok(content: String): HttpResponse = apply().withCode(OK).withContent(content).build | ||
|
||
def Error(status: HttpResponseStatus, content: JsonRootNode): HttpResponse = apply().withCode(status).withContent(content).build | ||
|
||
def Error(status: HttpResponseStatus, message: String): HttpResponse = apply().withCode(status).withErrorMessage(message).build | ||
|
||
def Error(status: HttpResponseStatus, error: Throwable): HttpResponse = apply().withCode(status).withError(error).build | ||
|
||
// bin?!?! | ||
def apply() = new JsonResponseBuilder() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.