Ejemplo n.º 1
0
        public void mSet(object o, String key, Action <object, OKCloudException> handler)
        {
            OKUser u = GetUser();

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

            string objRep = "";

            objRep += JSONObjectExt.encode(o);

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

            reqParams.Add("user_id", u.OKUserID.ToString());
            reqParams.Add("field_key", key);
            reqParams.Add("field_value", objRep);

            OKCloudAsyncRequest req = new OKCloudAsyncRequest("developer_data", "POST", reqParams);

            req.performWithCompletionHandler((string response, OKCloudException e) => {
                handler(o, e);
            });
        }
Ejemplo n.º 2
0
        public void mGet(String key, Action <object, OKCloudException> handler)
        {
            OKUser u = GetUser();

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

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

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

            string path = string.Format("/developer_data/{0}", key);

            OKCloudAsyncRequest.Get(path, reqParams, (JSONObject responseObj, OKCloudException e) => {
                JSONObject j     = responseObj.GetField(key);
                object retObject = JSONObjectExt.DeJSONify(j);
                if (retObject == null)
                {
                    handler(null, new OKCloudException("Fail."));
                }
                else
                {
                    handler(retObject, null);
                }
            });
        }
Ejemplo n.º 3
0
        private static RestRequest BuildPutRequest(string path, RequestParams parameters)
        {
            RestRequest request = new RestRequest(path, Method.PUT);

            request.AddHeader("Accepts", "application/json");
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONObjectExt.encode(parameters), ParameterType.RequestBody);
            return(request);
        }
        private static RestRequest BuildPostRequest(string relativePath, Dictionary <string, object> requestParams)
        {
            RestRequest request = new RestRequest(relativePath, Method.POST);

            request.AddHeader("Accepts", "application/json");
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JSONObjectExt.encode(requestParams), ParameterType.RequestBody);
            return(request);
        }
Ejemplo n.º 5
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")));
                }
            });
        }
Ejemplo n.º 7
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);
            });
        }