Incomplete RESTful API for IRC
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ServersResource.java 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package name.smith.chris.restirc.resources;
  2. import com.sun.jersey.api.NotFoundException;
  3. import com.sun.jersey.spi.resource.Singleton;
  4. import java.net.URI;
  5. import java.net.URISyntaxException;
  6. import javax.ws.rs.GET;
  7. import javax.ws.rs.PUT;
  8. import javax.ws.rs.Path;
  9. import javax.ws.rs.PathParam;
  10. import javax.ws.rs.Produces;
  11. import name.smith.chris.restirc.model.Server;
  12. import name.smith.chris.restirc.model.ServerManager;
  13. import lombok.AllArgsConstructor;
  14. /**
  15. * Top-level resource for servers.
  16. */
  17. @Singleton
  18. @Path("/servers")
  19. public class ServersResource {
  20. private final ServerManager manager = new ServerManager() {{
  21. addServer("test", new Server() {{
  22. try {
  23. addAddress(new URI("irc://irc.quakenet.org:6667/"));
  24. addChannel("#mdbot");
  25. } catch (URISyntaxException ex) {
  26. // Fail
  27. }
  28. }});
  29. }};
  30. @GET
  31. @Produces("application/json")
  32. public String getList() {
  33. return "Meh";
  34. }
  35. @Path("/{id}")
  36. public ServerResource getSubResource(@PathParam("id") String id) {
  37. if (manager.hasServer(id)) {
  38. return new ServerResource(id);
  39. } else {
  40. throw new NotFoundException();
  41. }
  42. }
  43. @Path("/{id}")
  44. @GET
  45. public String getServer(@PathParam("id") String id) {
  46. if (manager.hasServer(id)) {
  47. return "Boo!";
  48. } else {
  49. throw new NotFoundException();
  50. }
  51. }
  52. @Path("/{id}")
  53. @PUT
  54. public String getTestyList() {
  55. throw new UnsupportedOperationException("TODO");
  56. }
  57. @AllArgsConstructor
  58. public static class ServerResource {
  59. private final String id;
  60. @GET
  61. @Produces("text/plain")
  62. @Path("/test")
  63. public String test() {
  64. return "Test! My ID is " + id;
  65. }
  66. }
  67. }