Exemplo n.º 1
0
        protected void SynchronizedPerform()
        {
            _killSwitch = _httpClient.ExecuteAsync(GetHttpRequest(), response => {
                var y = new OKServiceResponse();

                if (response.ResponseStatus == ResponseStatus.Aborted)
                {
                    y.Status = OKIOStatus.Cancelled;
                }
                else
                {
                    switch (response.StatusCode)
                    {
                    case HttpStatusCode.OK:
                        y.Status = OKIOStatus.Succeeded;
                        y.Obj    = JSONObjectExt.decode(response.Content);
                        break;

                    case HttpStatusCode.Forbidden:
                        y.Status = OKIOStatus.FailedWithError;
                        y.Err    = new OKException("Forbidden: Verify that your key and secret are correct.");
                        break;

                    default:
                        y.Status = OKIOStatus.FailedWithError;
                        y.Err    = new OKException("OKServiceRequest failed.  Response body: " + response.Content);
                        break;
                    }
                }

                SynchronizationContext c = OKCtx.Ctx;
                if (c == null)
                {
                    _didFinish(y);
                }
                else
                {
                    c.Post(s => _didFinish(y), null);
                }

                _killSwitch = null;
            });
        }
        public static void Request(RestRequest request, Action <JSONObject, OKCloudException> handler)
        {
            RestClient client = GetRestClient();

            client.ExecuteAsync(request, (response) => {
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    JSONObject jsonObj = JSONObjectExt.decode(response.Content);
                    handler(jsonObj, null);
                }
                else if (response.StatusCode == System.Net.HttpStatusCode.Forbidden)
                {
                    handler(null, new OKCloudException("Forbidden: Verify that your key and secret are correct."));
                }
                else
                {
                    handler(null, new OKCloudException("Async request failed with message: " + JSONObjectExt.decode(response.Content).GetField("message")));
                }
            });
        }
Exemplo n.º 3
0
        public void mGet(String key, Action <JSONObject, OKCloudException> handler)
        {
            OKUser u = GetUser();

            if (u == null)
            {
                throw new Exception("You need a user to perform cloud get.");
            }

            Dictionary <string, string> reqParams = new Dictionary <string, string>();

            reqParams.Add("user_id", u.OKUserID.ToString());

            string path             = string.Format("developer_data/{0}", key);
            OKCloudAsyncRequest req = new OKCloudAsyncRequest(path, "GET", reqParams);

            req.performWithCompletionHandler((string response, OKCloudException e) => {
                JSONObject jsonObj = JSONObjectExt.decode(response);
                handler(jsonObj.GetField(key), e);
            });
        }