Created
June 19, 2012 10:56
-
-
Save jesperbjensen/2953525 to your computer and use it in GitHub Desktop.
Geekhub.dk - API Opret
This file contains hidden or 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 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