Here is an example of a custom Luckycycle integration in a C# .net environment.
A DLL is coming soon.
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Script.Serialization;
namespace ConsoleApplication1 {
class Program {
private const string URL = "https://www.luckycycle.com/api/v1/operations/478aa07fa86b29703f73c78afe17f650/poke";
static void Main(string[] args ){
Console.WriteLine("Trying to poke");
HttpClient client = new HttpClient();
// Add an Accept header for JSON format ?
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("X-LuckyApiKey", "9c936dbf1cfa00bc11a8961238d34fb1");
string rs = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 8);
string json = @"{
""user_uid"":""ABGH"",
""item_uid"":""QOPOI7.815"",
""item_value"":""67.9"",
""language"":""en"",
""firstname"":""Jack"",
""lastname"":""Dawson"",
""email"":""[email protected]"",
""poke_software_version"":"".Net HttpClient"",
""discount"":""0"",
""cart"":[
{""price"":""21.99"", ""quantity"":""1"",""category_id"":""23"",""other_id"":""A""},
{""price"":""12.49"", ""quantity"":""1"",""category_id"":""12"",""other_id"":""B""}
]
}";
Console.WriteLine(json);
HttpResponseMessage response = client.PostAsync(URL, new StringContent(json,Encoding.UTF8, "application/json")).Result; // Blocking call!
if (response.IsSuccessStatusCode){
Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
Console.WriteLine("{0} ({1})", response.Content.ToString(), response.ToString());
} else {
Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
}
Console.ReadLine();
}
}
}
