Skip to content

Instantly share code, notes, and snippets.

View btompkins's full-sized avatar

Brendan Tompkins btompkins

View GitHub Profile
@btompkins
btompkins / gist:8722291
Created January 30, 2014 23:22
Geocode using Geocodio in C#
public class Geocodio
{
public string ApiKey { get; set; }
public GeocodioResponse GeoCodeByCityState(string address)
{
var client = new RestClient("http://api.geocod.io/v1/");
// client.Authenticator = new HttpBasicAuthenticator(username, password);
var request = new RestRequest("geocode", Method.GET);
namespace PSI.Common.Appointments
{
public enum AppointmentState
{
[Description("Appointment #{0} Scheduled for {1} Confirmed and On Time")]
Confirmed = 0,
[Description("Appointment #{0} Scheduled for {1} Confirmed within Grace Peroid")]
ConfirmedWithinGracePeriod = 1,
[Description("Appointment #{0} Scheduled for {1} Confirmed Late")]
public class PngProcessor : MediaTypeProcessor
{
public PngProcessor(HttpOperationDescription operation,
MediaTypeProcessorMode mode) : base (operation, mode)
{
}
public override IEnumerable< string > SupportedMediaTypes
{
get
protected void Application_Start(object sender, EventArgs e)
{
var configuration = new ContactManagerConfiguration();
RouteTable.Routes.AddServiceRoute<ContactResource>( “contact“, configuration);
RouteTable.Routes.AddServiceRoute<ContactsResource>( “contacts“, configuration);
}
[ServiceContract]
public class ContactsResource
{
private static int nextId = 1;
[WebInvoke(UriTemplate = "", Method = "POST")]
public JsonValue Post(JsonValue contact)
{
var postedContact = (dynamic)contact;
var contactResponse = (dynamic)new JsonObject();
public class ContactManagerConfiguration : HostConfiguration
{
public override void RegisterRequestProcessorsForOperation( HttpOperationDescription operation,
IList<Processor> processors, MediaTypeProcessorMode mode)
{
processors.Add(new JsonProcessor(operation, mode));
processors.Add(new FormUrlEncodedProcessor(operation, mode));
}
public override void RegisterResponseProcessorsForOperation( HttpOperationDescription operation,
[WebGet(UriTemplate = "")]
[QueryComposition]
public IEnumerable<Contact> Get()
{
return contacts.AsQueryable();
}
public class JsonValueSampleConfiguration : HostConfiguration
{
public override void RegisterRequestProcessorsForOperation( HttpOperationDescription operation, IList<Processor> processors, MediaTypeProcessorMode mode)
{
processors.Add(new FormUrlEncodedProcessor(operation, mode));
}
public override void RegisterResponseProcessorsForOperation( HttpOperationDescription operation, IList<Processor> processors, MediaTypeProcessorMode mode)
{
processors.ClearMediaTypeProcessors();
var client = new HttpClient();
client.DefaultHeaders.Accept.Add("text/xml");
var resp = client.Get("http://contoso.com/contacts/1");
resp.Content.ReadAsXmlSerializable<Contact>();
[ServiceContract]
public class DocumentResource
{
[WebGet(UriTemplate="{name}")]
public Document Get(string name, HttpResponseMessage resp)
{
Document doc;