public void DeleteCheckItem(string checkItemId)
        {
            string uri = string.Format(DeleteCheckItemFormat, ScenesManager.Instance.CurrentBranchId, checkItemId, apiKey, apiToken);

            UnityHTTP.Request request = new UnityHTTP.Request("DELETE", uri);
            request.synchronous = true;
            request.Send();
        }
        public void CheckItemOn(string checkItemId, string checkItemName, bool itemChecked)
        {
            string uri = string.Format(CardChecklistsUpdateFormat, ProjectSettings.Instance.TrelloSettings.CardId, ScenesManager.Instance.CurrentBranchId, checkItemId, apiKey, apiToken, itemChecked.ToString().ToLower(), checkItemName);

            UnityHTTP.Request request = new UnityHTTP.Request("PUT", uri);
            request.synchronous = true;
            request.Send();
        }
 public void Update()
 {
     while (requests.Count > 0)
     {
         UnityHTTP.Request request = (Request)requests.Dequeue();
         request.completedCallback(request);
     }
 }
        public string CreateCheckItem(string checkItemName)
        {
            string uri         = string.Format(CreateCheckItemFormat, ScenesManager.Instance.CurrentBranchId, checkItemName, apiKey, apiToken);
            string checkItemId = string.Empty;

            UnityHTTP.Request request = new UnityHTTP.Request("POST", uri);
            request.synchronous = true;
            request.Send(c => {
                Dictionary <string, object> dictionary = Json.Deserialize(c.response.Text) as Dictionary <string, object>;
                checkItemId = dictionary["id"] as string;
            });
            return(checkItemId);
        }
        /// <summary>
        /// Gets a ready request containing a GET
        /// </summary>
        /// <returns>The GET request that is already being sent</returns>
        /// <param name="events">Event to send in the GET</param>
        /// <param name="ids">The row id</param>
        /// <param name="oversize">If the event list is oversize</param>
        protected UnityHTTP.Request GetGETRequest(Dictionary <string, object> eventDict)
        {
            // Add STM to event
            eventDict.Add(Constants.SENT_TIMESTAMP, Utils.GetTimestamp().ToString());

            // Build the event
            string url = this.collectorUri + Utils.ToQueryString(eventDict);

            UnityHTTP.Request httpRequest = new UnityHTTP.Request(UnityHTTP.Enums.RequestType.GET, url);
            httpRequest.synchronous = this.synchronous;

            return(httpRequest);
        }
        public string CreateChecklist(string checklistName)
        {
            string uri         = string.Format(CreateChecklistFormat, ProjectSettings.Instance.TrelloSettings.CardId, checklistName, apiKey, apiToken);
            string checklistId = string.Empty;

            UnityHTTP.Request request = new UnityHTTP.Request("POST", uri);
            request.synchronous = true;
            request.Send(c => {
                UnityEngine.Debug.Log(c.response.Text);
                Dictionary <string, object> dictionary = Json.Deserialize(c.response.Text) as Dictionary <string, object>;
                checklistId = dictionary["id"] as string;
            });
            return(checklistId);
        }
        // --- Helpers

        /// <summary>
        /// Gets a ready request containing a POST
        /// </summary>
        /// <returns>The POST request that is already being sent</returns>
        /// <param name="events">Events to send in the post</param>
        /// <param name="ids">The row ids</param>
        /// <param name="oversize">If the event list is oversize</param>
        protected UnityHTTP.Request GetPOSTRequest(List <Dictionary <string, object> > events)
        {
            // Add STM to event
            AddSentTimeToEvents(events);

            // Build the event
            SelfDescribingJson sdj = new SelfDescribingJson(Constants.SCHEMA_PAYLOAD_DATA, events);

            byte[]            data        = Utils.StringToBytes(sdj.ToString());
            UnityHTTP.Request httpRequest = new UnityHTTP.Request(UnityHTTP.Enums.RequestType.POST, this.collectorUri, data);
            httpRequest.AddHeader("Content-Type", Constants.POST_CONTENT_TYPE);
            httpRequest.synchronous = this.synchronous;

            return(httpRequest);
        }
예제 #8
0
        /// <summary>
        /// <para>Client performs an initial HTTP POST to obtain a SessionId (sid) assigned to a client, followed
        ///  by the heartbeat timeout, connection closing timeout, and the list of supported transports.</para>
        /// <para>The tansport and sid are required as part of the ws: transport connection</para>
        /// </summary>
        /// <param name="uri">http://localhost:3000</param>
        /// <returns>Handshake object with sid value</returns>
        /// <example>DownloadString: 13052140081337757257:15:25:websocket,htmlfile,xhr-polling,jsonp-polling</example>
        protected void requestHandshake(Uri uri, Action<SocketIOHandshake> callback)
        {
            string value = string.Empty;
            string errorText = string.Empty;
            SocketIOHandshake handshake = null;

            UnityHTTP.Request request = new UnityHTTP.Request("get", string.Format("{0}://{1}:{2}/socket.io/1/{3}", uri.Scheme, uri.Host, uri.Port, uri.Query));
            request.Send(req => {
                if (request.response != null) {
                    value = request.response.Text;
                }
                if (string.IsNullOrEmpty(value))
                    errorText = "Did not receive handshake string from server";
                if (string.IsNullOrEmpty(errorText))
                    handshake = SocketIOHandshake.LoadFromString(value);
                else
                {
                    handshake = new SocketIOHandshake();
                    handshake.ErrorMessage = errorText;
                }
                callback(handshake);
            });
        }
예제 #9
0
        private void performRequest(string method, Hashtable parameters = null, Action <RestifizerResponse> callback = null)
        {
            Debug.Log("(" + method.ToUpper() + ") " + Path);
            UnityHTTP.Request someRequest;

            string url      = Path;
            string queryStr = "";

            // paging
            if (PageNumber != -1)
            {
                if (queryStr.Length > 0)
                {
                    queryStr += "&";
                }
                queryStr += "per_page=" + PageNumber;
            }
            if (PageSize != -1)
            {
                if (queryStr.Length > 0)
                {
                    queryStr += "&";
                }
                queryStr += "page=" + PageSize;
            }

            // filtering
            if (filterParams != null && filterParams.Count > 0)
            {
                if (queryStr.Length > 0)
                {
                    queryStr += "&";
                }
                string filterValue = JSON.JsonEncode(filterParams);
                queryStr += "filter=" + filterValue;
            }

            // extra params
            if (extraQuery != null && extraQuery.Count > 0)
            {
                foreach (string key in extraQuery.Keys)
                {
                    if (queryStr.Length > 0)
                    {
                        queryStr += "&";
                    }
                    queryStr += key + "=" + extraQuery[key];
                }
            }

            if (queryStr.Length > 0)
            {
                url += "?" + queryStr;
            }


            // Handle authentication
            if (this.authType == AuthType.Client)
            {
                if (parameters == null)
                {
                    parameters = new Hashtable();
                }
                parameters.Add("client_id", restifizerParams.GetClientId());
                parameters.Add("client_secret", restifizerParams.GetClientSecret());

                someRequest = new UnityHTTP.Request(method, url, parameters);
            }
            else if (this.authType == AuthType.Bearer)
            {
                if (parameters == null)
                {
                    someRequest = new UnityHTTP.Request(method, url);
                }
                else
                {
                    someRequest = new UnityHTTP.Request(method, url, parameters);
                }
                someRequest.SetHeader("Authorization", restifizerParams.GetAccessToken());
            }
            else
            {
                if (parameters == null)
                {
                    someRequest = new UnityHTTP.Request(method, url);
                }
                else
                {
                    someRequest = new UnityHTTP.Request(method, url, parameters);
                }
            }

            // Handle Content-Type
            if (this.contentType != "")
            {
                someRequest.SetHeader("Content-Type", this.contentType);
            }

            string tag = this.Tag;

            // Perform request
            someRequest.Send((request) => {
                if (request.response == null)
                {
                    RestifizerError error = RestifizerErrorFactory.Create(-1, null, tag);
                    if (errorHandler != null)
                    {
                        bool propagateResult = !errorHandler.onRestifizerError(error);
                        if (propagateResult)
                        {
                            callback(null);
                        }
                    }
                    else
                    {
                        callback(null);
                    }
                    return;
                }
                bool result           = false;
                object responseResult = JSON.JsonDecode(request.response.Text, ref result);
                if (!result)
                {
                    RestifizerError error = RestifizerErrorFactory.Create(-2, request.response.Text, tag);
                    if (errorHandler != null)
                    {
                        bool propagateResult = !errorHandler.onRestifizerError(error);
                        if (propagateResult)
                        {
                            callback(null);
                        }
                    }
                    else
                    {
                        callback(null);
                    }
                    return;
                }

                bool hasError = request.response.status >= 300;
                if (hasError)
                {
                    RestifizerError error = RestifizerErrorFactory.Create(request.response.status, responseResult, tag);
                    Debug.LogError(((Hashtable)responseResult)["response"] + " (" + request.uri + ")");
                    if (errorHandler != null)
                    {
                        bool propagateResult = !errorHandler.onRestifizerError(error);
                        if (propagateResult)
                        {
                            callback(new RestifizerResponse(request, error, tag));
                        }
                    }
                    else
                    {
                        callback(new RestifizerResponse(request, error, tag));
                    }
                }
                else if (responseResult is ArrayList)
                {
                    callback(new RestifizerResponse(request, (ArrayList)responseResult, tag));
                }
                else if (responseResult is Hashtable)
                {
                    callback(new RestifizerResponse(request, (Hashtable)responseResult, tag));
                }
                else
                {
                    Debug.LogWarning("Unsupported type in response: " + responseResult.GetType());
                    callback(null);
                }
            });
        }