-
-
Save nskerl/8be9a38859b8ba8fb791 to your computer and use it in GitHub Desktop.
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
{ | |
"webroot": "wwwroot", | |
"version": "1.0.0-*", | |
"dependencies": { | |
"Microsoft.AspNet.Server.IIS": "1.0.0-beta4", | |
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta4", | |
"Kestrel": "1.0.0-beta4" | |
}, | |
"commands": { | |
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000", | |
"kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://0.0.0.0:5001" | |
}, | |
"frameworks": { | |
"dnx451": {}, | |
"dnxcore50": {} | |
}, | |
"publishExclude": [ | |
"node_modules", | |
"bower_components", | |
"**.xproj", | |
"**.user", | |
"**.vspscc" | |
], | |
"exclude": [ | |
"wwwroot", | |
"node_modules", | |
"bower_components" | |
] | |
} |
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
using System; | |
using System.Threading.Tasks; | |
using System.IO; | |
using System.Text.RegularExpressions; | |
using Microsoft.AspNet.Builder; | |
using Microsoft.AspNet.Http; | |
using Microsoft.Framework.DependencyInjection; | |
namespace IFTTTEndpoint | |
{ | |
public class Startup | |
{ | |
public void ConfigureServices(IServiceCollection services) { } | |
static Regex methodRegex = new Regex(@"\<methodName\>(?<method>.*)\<\/methodName\>", RegexOptions.Singleline | RegexOptions.Compiled); | |
static Regex titleRegex = new Regex(@"<member><name>title</name><value><string>(?<title>.*?)</string></value></member>", RegexOptions.Singleline | RegexOptions.Compiled); | |
public void Configure(IApplicationBuilder app) | |
{ | |
app.Run(async (context) => | |
{ | |
string body = new StreamReader(context.Request.Body).ReadToEnd(); | |
var test = methodRegex.Match(body); | |
if (test.Success) { | |
switch(test.Groups["method"].Value) { | |
case "mt.supportedMethods": | |
await Xml(context, "metaWeblog.getRecentPosts"); | |
break; | |
case "metaWeblog.getRecentPosts": | |
await Xml(context, "<array><data></data></array>"); | |
break; | |
case "metaWeblog.newPost": | |
var title = titleRegex.Match(body); | |
Console.WriteLine("From Amazon: " + title.Groups["title"].Value); | |
await Xml(context, "<string>No forward url, but will assume data was handled locally</string>"); | |
break; | |
} | |
} else { | |
Console.WriteLine("Unrecognized: " + body); | |
await context.Response.WriteAsync("Hello World!"); | |
} | |
}); | |
} | |
public Task Xml(HttpContext context, string content) { | |
context.Response.ContentType = "text/xml"; | |
return context.Response.WriteAsync(string.Format(@"<?xml version=""1.0""?> | |
<methodResponse><params><param><value>{0}</value></param></params></methodResponse>", content)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment