public static String prepareMapPayload(String prepend, EgoiMap values) { StringBuilder q = new StringBuilder(); foreach (String key in values.Keys) { Object value = values[key]; String result = null; String prefix = String.Format("{0}[{1}]", prepend, key); if (value is EgoiMap) { EgoiMap map = (EgoiMap)value; result = prepareMapPayload(prefix, map); } else if (value is EgoiMapList) { EgoiMapList list = (EgoiMapList)value; result = prepareListPayload(prefix, list); } else { result = String.Format("{0}={1}&", prefix, value.ToString()); } q.Append(result); } return q.ToString(); }
public String buildPayload(EgoiMap values) { if (values != null) return values.ToString(); return ""; }
private void processCall_Click(object sender, EventArgs e) { status.Text = ""; output.Clear(); Protocol p = (Protocol) protocol.SelectedItem; try { EgoiApi api = EgoiApiFactory.getApi(p); EgoiMap arguments = new EgoiMap(); arguments.Add("apikey", apiKey.Text); EgoiMap result = api.getUserData(arguments); output.Text = result.ToString(); } catch(EgoiException ex) { status.Text = ex.Message; } }
public String buildPayload(EgoiMap values) { StringBuilder url = new StringBuilder(); int i = 0; foreach (String key in values.Keys) { Object value = values[key]; if (i > 0) url.Append("&"); if(value is Array) { string valueToAppend = string.Empty; foreach(var val in (Array)value) { valueToAppend += val.ToString() + ","; } if (!string.IsNullOrEmpty(valueToAppend)) { valueToAppend = valueToAppend.Trim(','); url.Append(String.Format("{0}={1}", key, valueToAppend)); } } else { url.Append(String.Format("{0}={1}", key, value.ToString())); } i++; } return url.ToString(); }
/////////////////////////////////////////////////////////////////////////////////////// public string getPartnersProducts(EgoiMap arguments) { return processResult("partners/products", "GET", arguments); }
public EgoiMap checklogin(EgoiMap arguments) { return decodeMapResult("checklogin", arguments); }
public EgoiMap getUserData(EgoiMap arguments) { return decodeMapResult("getUserData", arguments); }
public string getSubaccountsProperties(EgoiMap arguments) { return processResult("subaccounts/properties", "GET", arguments); }
public string processResult(string method, string methodType, EgoiMap arguments) { string payload = buildPayload(arguments); string json = fetchResponse(payload, method, methodType); return json; }
public EgoiMap subscriberData(EgoiMap arguments) { return decodeMapResult("subscriberData", arguments); }
public EgoiMap updateList(EgoiMap arguments) { return decodeMapResult("updateList", arguments); }
public EgoiMap sendFAX(EgoiMap arguments) { return decodeMapResult("sendFAX", arguments); }
public EgoiMap sendSMS(EgoiMap arguments) { return decodeMapResult("sendSMS", arguments); }
public EgoiMap sendEmail(EgoiMap arguments) { return decodeMapResult("sendEmail", arguments); }
public EgoiMap removeSubscriber(EgoiMap arguments) { return decodeMapResult("removeSubscriber", arguments); }
public Dictionary<string, object> processResult(string method, EgoiMap arguments) { string payload = buildPayload(method, arguments); string json = fetchResponse(payload); JavaScriptSerializer s = new JavaScriptSerializer(); /** * IT's A TRAP! */ Dictionary<string, object> response = s.Deserialize<Dictionary<string, object>>(json); Dictionary<string, object> r2 = response["Egoi_Api"] as Dictionary<string, object>; Dictionary<string, object> map = r2[method] as Dictionary<string, object>; if (map.ContainsKey("response")) throw new EgoiException(EgoiException.idToMessage(map["response"] as string)); // Status not used map.Remove("status"); return map; }
public string getPartnersProductsById(string id, EgoiMap arguments) { return processResult("partners/products/" + id, "GET", arguments); }
protected EgoiMap walkValues(EgoiMap map) { List<string> keys = map.Keys.ToList<string>(); foreach(string key in keys) { object obj = map[key]; if (obj is Dictionary<string, object>) { Dictionary<string, object> sm = obj as Dictionary<string, object>; map[key] = walkMap(sm); } if(obj is object[]) { List<Dictionary<string, object>> mapList = extractMapList((Object[]) obj); map[key] = walkArray(mapList); } } return map; }
public string getSubaccountsBalanceById(string id, EgoiMap arguments) { return processResult("subaccounts/balance/" + id, "GET", arguments); }
public string updateSubaccounts(string id, EgoiMap arguments) { return processResult("subaccounts/" + id, "PUT", arguments); }
public string getSubaccountsPropertiesById(string id, EgoiMap arguments) { return processResult("subaccounts/properties/" + id, "GET", arguments); }
public string addSubaccountsProducts(EgoiMap arguments) { return processResult("subaccounts/products/assign", "POST", arguments); }
public string topupSubaccountsProducts(EgoiMap arguments) { return processResult("subaccounts/products/topup", "GET", arguments); }
public EgoiMapList getSenders(EgoiMap arguments) { return decodeMapListResult("getSenders", arguments); }
public string addSubaccounts(EgoiMap arguments) { return processResult("subaccounts", "POST", arguments); }
/////////////////////////////////////////////////////////////////////////////////////// public EgoiMap addExtraField(EgoiMap arguments) { return decodeMapResult("addExtraField", arguments); }
public string blockSubaccounts(EgoiMap arguments) { return processResult("subaccounts/block", "POST", arguments); }
public EgoiMap addSubscriberBulk(EgoiMap arguments) { return decodeMapResult("addSubscriberBulk", arguments); }
public string deleteSubaccountsProducts(string id, EgoiMap arguments) { return processResult("subaccounts/products/assign/" + id, "DELETE", arguments); }
public String buildPayload(String method, EgoiMap values) { StringBuilder url = new StringBuilder(); url .Append("type=json&") .Append("method=").Append(method).Append("&") .Append(prepareMapPayload("functionOptions", values)); return url.ToString(); }