Skip to content

Instantly share code, notes, and snippets.

@jesperbjensen
Created June 19, 2012 10:56
Show Gist options
  • Save jesperbjensen/2953525 to your computer and use it in GitHub Desktop.
Save jesperbjensen/2953525 to your computer and use it in GitHub Desktop.
Geekhub.dk - API Opret
using System;
using RestSharp;
namespace geekhub.apitest
{
class Program
{
static void Main(string[] args)
{
// Needs NUGET Package: RestSharp
// Replace with live url, when ready
var client = new RestClient();
client.BaseUrl = "https://geekhub-test.herokuapp.com/api/v1";
client.Authenticator = new HttpBasicAuthenticator("User", "Password");
var request = new RestRequest();
request.Resource = "meetings";
request.Method = Method.POST;
request.AddParameter("meeting[title]", "Mit event");
request.AddParameter("meeting[starts_at]", DateTime.Now.AddDays(14));
request.AddParameter("meeting[description]", "Dette er min beskrivelse\nNew Line!" );
request.AddParameter("meeting[url]", "http://example.org");
request.AddParameter("meeting[location]", "Aarhus");
request.AddParameter("meeting[organizer]", "Evil Corp");
request.AddParameter("meeting[costs_money]", "1"); // 1 = true
var response = client.Execute(request);
var httpStatusUnprocessableEntity = 422;
if ((int)response.StatusCode == httpStatusUnprocessableEntity)
{
Console.WriteLine("Invalid request");
}
Console.WriteLine(response.Content);
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment