Skip to content

Instantly share code, notes, and snippets.

@brycehamrick
Created August 16, 2012 01:07
Show Gist options
  • Save brycehamrick/3365236 to your computer and use it in GitHub Desktop.
Save brycehamrick/3365236 to your computer and use it in GitHub Desktop.
Capture Promo Creation
public bool CaptureCanRedeem(string barcode, out bool alreadyExist)
{
alreadyExist = false;
query.Add("type_name", "promos");
query.Add("attributes", "{\"code\":\"" + barcode + "\"}");
query.Add("client_id", client_id);
query.Add("client_secret", client_secret);
JObject obj = GetData("https://loccitane.janraincapture.com/entity.create", query);
if (obj["stat"] != null && obj["stat"].Value<string>() == "error" && obj["error"] != null && obj["error"].Value<string>() == "unique_violation")
alreadyExist = true;
if ((obj["stat"] != null && obj["stat"].Value<string>() == "ok")
||
alreadyExist == true)
{
query = new Dictionary<string, string>();
query.Add("type_name", "promos");
query.Add("filter", "code='" + barcode + "'");
query.Add("client_id", client_id);
query.Add("client_secret", client_secret);
obj = GetData("https://loccitane.janraincapture.com/entity.find", query);
if (obj["stat"] != null && obj["stat"].Value<string>() == "ok" && obj["results"] != null && obj["results"].First()["redeemed"].Value<string>() == null)
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment