Пример #1
0
        public void SubmitScore(Action <OKScore, OKException> callback)
        {
            OKUser u = GetUser();

            if (u == null)
            {
                throw new Exception("You need a user to submit a score");
            }

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

            score.Add("leaderboard_id", LeaderboardID);
            score.Add("value", scoreValue);
            score.Add("display_string", displayString);
            score.Add("metadata", metadata);
            score.Add("user_id", u.OKUserID.ToString());

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

            reqParams.Add("score", score);

            OKUploadBuffer buff = null;

            if (MetadataBuffer != null)
            {
                buff = new OKUploadBuffer()
                {
                    Bytes     = MetadataBuffer,
                    ParamName = "score[meta_doc]",
                    FileName  = "upload"
                };
            }

            Action <JSONObject, OKCloudException> handler = (responseObj, e) => {
                if (e == null)
                {
                    OKScore retScore = new OKScore(responseObj);
                    callback(retScore, null);
                }
                else
                {
                    callback(null, e);
                }
            };

            OKCloudAsyncRequest.Post("/scores", reqParams, buff, handler);
        }
Пример #2
0
 private static RestRequest BuildMultipartPostRequest(string path, RequestParams parameters, OKUploadBuffer upBuff)
 {
     RestRequest request = new RestRequest(path, Method.POST);
     request.AddHeader("Accepts", "application/json");
     request.AddFile(upBuff.ParamName, upBuff.Bytes, upBuff.FileName);
     if (parameters != null) {
         foreach (FormPair pair in FormPairs(parameters)) {
             request.AddParameter(pair.Name, pair.Value);
         }
     }
     return request;
 }
Пример #3
0
 public static OKServiceRequest MultipartPost(string path, RequestParams parameters, OKUploadBuffer upload, RequestHandler handler)
 {
     OKServiceRequest req = new OKServiceRequest(path, parameters, OKRestVerb.Post);
     req.Upload = upload;
     req.Perform(handler);
     return req;
 }
Пример #4
0
        public static OKServiceRequest MultipartPost(string path, RequestParams parameters, OKUploadBuffer upload, RequestHandler handler)
        {
            OKServiceRequest req = new OKServiceRequest(path, parameters, OKRestVerb.Post);

            req.Upload = upload;
            req.Perform(handler);
            return(req);
        }
Пример #5
0
        private static RestRequest BuildMultipartPostRequest(string path, RequestParams parameters, OKUploadBuffer upBuff)
        {
            RestRequest request = new RestRequest(path, Method.POST);

            request.AddHeader("Accepts", "application/json");
            request.AddFile(upBuff.ParamName, upBuff.Bytes, upBuff.FileName);
            if (parameters != null)
            {
                foreach (FormPair pair in FormPairs(parameters))
                {
                    request.AddParameter(pair.Name, pair.Value);
                }
            }
            return(request);
        }
        private static RestRequest BuildMultiPartPostRequest(string relativePath, Dictionary <string, object> requestParams, OKUploadBuffer upBuff)
        {
            RestRequest request = new RestRequest(relativePath, Method.POST);

            request.AddHeader("Accepts", "application/json");
            request.AddFile(upBuff.ParamName, upBuff.Bytes, upBuff.FileName);

            // This only handles one level of nesting! Fix me.
            foreach (var p1 in requestParams)
            {
                var v = p1.Value;
                var k = p1.Key;
                if (v.GetType() == typeof(Dictionary <string, object>))
                {
                    foreach (var p2 in (Dictionary <string, object>)v)
                    {
                        string paramKey = String.Format("{0}[{1}]", k, p2.Key);
                        request.AddParameter(paramKey, p2.Value);
                    }
                }
                else
                {
                    request.AddParameter(k, v);
                }
            }
            return(request);
        }
        public static void Post(string relativePath, Dictionary <string, object> requestParams, OKUploadBuffer upBuff, Action <JSONObject, OKCloudException> handler)
        {
            RestRequest request;

            if (upBuff == null)
            {
                request = BuildPostRequest(relativePath, requestParams);
            }
            else
            {
                request = BuildMultiPartPostRequest(relativePath, requestParams, upBuff);
            }

            Request(request, handler);
        }