Created
September 16, 2013 14:19
-
-
Save tfennelly/6581304 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.foxweave.mocksaas; | |
import com.cloudbees.weave.api.webhook.WEAVEHook; | |
import com.foxweave.mocksaas.model.Contact; | |
import com.foxweave.mocksaas.model.Response; | |
import javax.ws.rs.Consumes; | |
import javax.ws.rs.DELETE; | |
import javax.ws.rs.POST; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.PathParam; | |
import javax.ws.rs.Produces; | |
@Path("/contacts") | |
@Produces("application/json") | |
@Consumes("application/json") | |
public class ContactService { | |
private WEAVEHook contactWeaveHook = new WEAVEHook("contact"); | |
/** | |
* Add a "contact" Webhook. | |
* @param webhookDirective The Webhook directive. | |
*/ | |
@POST | |
@Path("/webhook") | |
public Response addWebhook(String webhookDirective) { | |
contactWeaveHook.addWebhook(webhookDirective); | |
return Response.SUCCESS; | |
} | |
/** | |
* Remove a "contact" Webhook. | |
* @param id The id of the webhook to be removed. | |
*/ | |
@DELETE | |
@Path("/webhook/{id}") | |
public Response removeWebhook(@PathParam("id") String id) { | |
contactWeaveHook.removeWebhook(id); | |
return Response.SUCCESS; | |
} | |
/** | |
* Receive a "contact" CREATED event from a WEAVE@cloud integration. | |
* @param contact The contact JSON bound into a Contact object. | |
*/ | |
@POST | |
@Path("/created") | |
public void created(Contact contact) { | |
System.out.println("Contact added in source system: [" + contact + "]."); | |
// Do some business "stuff" ... | |
// Publish a "contact" notification to any WEAVE@cloud apps that have registered | |
// interest (via a Webhook) in contact CREATED events... | |
contactWeaveHook.created(contact); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment