public static void DoCallback <TResult> (TResult result, FizzException ex, Action <TResult, FizzException> callback) { if (callback != null) { try { callback(result, ex); } catch (Exception callbackEx) { FizzLogger.W("Callback threw exception: " + callbackEx.Message); } } }
public static void DoCallback(Action callback) { if (callback != null) { try { callback.Invoke(); } catch { FizzLogger.W("Callback threw exception"); } } }
public static void DoCallback(FizzException ex, Action <FizzException> callback) { if (callback != null) { try { callback(ex); } catch { FizzLogger.W("Callback threw exception"); } } }
public void FetchToken(string userId, string locale, Action <FizzSession, FizzException> callback) { if (string.IsNullOrEmpty(locale)) { FizzUtils.DoCallback <FizzSession>(new FizzSession(null, null, 0), ERROR_INVALID_LOCALE, callback); return; } JSONClass node = new JSONClass(); node["user_id"] = userId; node["locale"] = locale; node["app_id"] = _appId; string body = node.ToString(); string digest = GenerateHmac(body, _appSecret); var headers = new Dictionary <string, string>() { { "Authorization", "HMAC-SHA256 " + digest } }; _restClient.Post(FizzConfig.API_BASE_URL, FizzConfig.API_PATH_SESSIONS, body, headers, (response, ex) => { if (ex != null) { FizzUtils.DoCallback(new FizzSession("", "", FizzUtils.Now()), ex, callback); } else { try { FizzSession session = ParseSession(JSONNode.Parse(response)); FizzUtils.DoCallback(session, null, callback); } catch (Exception responseEx) { FizzLogger.E(responseEx.Message); FizzUtils.DoCallback(new FizzSession("", "", FizzUtils.Now()), ERROR_SESSION_CREATION_FAILED, callback); } } }); }