Skip to content

Instantly share code, notes, and snippets.

@javi830810
Last active September 25, 2015 14:22
Show Gist options
  • Save javi830810/e4c726ddea5e53c29666 to your computer and use it in GitHub Desktop.
Save javi830810/e4c726ddea5e53c29666 to your computer and use it in GitHub Desktop.
Publish Action
public class ObjectTransformAction: IMapTransformAction
{
public object Transform(object input)
{
//What do you do here?....
}
}
public IPipeline GetPipelineForMessage(EventMessage message)
{
return new LinearPipeline () {
Actions = new List<IAction> () {
new JF.JotFormAPIAction () { },
new WebhookPublishAction () {
MessageType = "JotFormFullMessage",
Bus = this.container.Resolve<IBus> (),
WebhookStore = container.Resolve<IWebhookStore> (),
}
}
};
}
public class WebhookPublishAction: IVoidAction
{
public string MessageType { get; set; }
public IWebhookStore WebhookStore { get; set; }
public IBus Bus { get; set; }
public void Execute (object input)
{
foreach(var webhook in WebhookStore.QueryByEventType(this.MessageType))
{
var body = string.Empty;
if (input != null && webhook.BodyTemplate != null)
{
body = new MapTransformAction () {
OutputMessageTemplate = webhook.BodyTemplate
}.Transform((IDictionary)input);
}
Bus.Send ("ScaleBridge.Publisher", new SubmitViaHttpCommand () {
Url = webhook.Url,
Method = webhook.Method,
Headers = webhook.Headers,
Body = body
});
}
}
}
public class TemplateMapTransformAction: IMapTransformAction
{
public ITemplate OutputMessageTemplate { get; set; }
public string Transform(IDictionary input)
{
//No other Transformation happens at this level
return OutputMessageTemplate.Fill(input);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment