public void Post(string host,
                  string path,
                  string json,
                  Action <string, FizzException> callback)
 {
     _restClient.Post(host, path, json, AuthHeaders(), (response, ex) =>
     {
         ProcessResponse(response, ex, callback, () =>
         {
             _restClient.Post(host, path, json, AuthHeaders(), callback);
         });
     });
 }
Beispiel #2
0
        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);
                    }
                }
            });
        }