Skip to content

Instantly share code, notes, and snippets.

View johnsheehan's full-sized avatar

John Sheehan johnsheehan

  • White Bear Lake, MN
View GitHub Profile
var assembly = Assembly.GetCallingAssembly();
var actionMethods = assembly.GetTypes()
// Find all non abstract classes of type Controller and whose names end with "Controller"
.Where(x => x.IsClass && !x.IsAbstract && x.IsSubclassOf(typeof(TwilioController)) && x.Name.EndsWith("Controller"))
// Find all public methods from those controller classes
.SelectMany(x => x.GetMethods().Where(m => m.DeclaringType.Name == x.Name), (x, y) => new { Controller = x.Name.Substring(0, x.Name.Length - 10), Method = y.Name });
foreach (var action in actionMethods) {
routes.MapRoute(action.Method, action.Method, new { controller = action.Controller, action = action.Method });
}
public class HomeController : TwilioController
{
// /StartPhoneCall
public void StartPhoneCall() {
Say("Thank you for calling " + Called);
Say("Hello world!", 1, Voice.Man, Language.English);
Play("http://example.com", 1);
Gather(30,
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Threading;
namespace LongPolling
{
class MainClass
twilio.SendSmsMessageAsync("5551111111", "5552222222", "Async! ", (msg) => {
Dispatcher.BeginInvoke(() => { txtOutput.Text = msg.Sid; });
});
twilio.SendSmsMessageAsync("5551111111", "5552222222", "Async! ", smsSent);
public void smsSent(SmsMessage msg) {
Dispatcher.BeginInvoke(() => { txtOutput.Text = msg.Sid; });
}
// or
@johnsheehan
johnsheehan / StatsMixClient.cs
Created December 10, 2010 07:54
basic client for StatsMix REST API
using System;
using RestSharp;
namespace StatsMix
{
// Requires RestSharp
// http://restsharp.org
// http://github.com/johnsheehan/RestSharp
// Usage
C:\dev\heroku-test\public>ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (//.ssh/id_rsa):
Could not create directory '//.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
open //.ssh/id_rsa failed: No such file or directory.
Saving the key failed: //.ssh/id_rsa.
[TestMethod]
public void Can_Generate_Single_Say_With_Shortcut()
{
var response = new TwilioResponse();
response.Say("Hello world");
var expected = XDocument.Parse("<Response><Say>Hello world</Say></Response>").ToString();
var actual = response.ToString();
Assert.AreEqual(expected, actual);
public class EntityBase:DynamicModel {
public EntityBase():base("northwind") {
PrimaryKeyField = "Id";
}
}
public class Product : EntityBase {
}
public class User : EntityBase {
@johnsheehan
johnsheehan / restsharp2prototype.cs
Created April 29, 2011 04:17
some ideas for the next restsharp
var http = new Http("https://api.twilio.com/{version}/Accounts");
http.AddUrlSegment("version", "2010-04-01");
http.AddParameter("name", "value");
http.Authenticate = (request) => // authenticators would just follow this contract
{
request.AddHeader("name", "value");
};
http.Complete = (response, data) =>
{
// use in webmatrix
@{
Helper.Fetch(url: "http://example.com", method: "GET");
}
@{
Helper.Fetch(url: "http://example.com", method: HttpMethod.GET); // no intellisense or build protection
}
// regular code use, not webmatrix and not 4.0