public RestifizerResponse(HTTP.Request request, RestifizerError error, string tag) { this.Status = request.response.status; this.HasError = true; this.Error = error; this.Request = request; this.Tag = tag; }
public RestifizerResponse(int status, RestifizerError error, string tag) { this.Status = status; this.HasError = true; this.Error = error; this.Tag = tag; }
bool Restifizer.IErrorHandler.onRestifizerError(Restifizer.RestifizerError restifizerError) { Debug.Log("Restifizer: ERROR = " + restifizerError); return(true); }
private void performRequest(string method, Hashtable parameters = null, Action <RestifizerResponse> callback = null) { HTTP.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 HTTP.Request(method, url, parameters); } else if (this.authType == AuthType.Bearer) { if (parameters == null) { someRequest = new HTTP.Request(method, url); } else { someRequest = new HTTP.Request(method, url, parameters); } someRequest.SetHeader("Access-Token", restifizerParams.GetAccessToken()); } else { if (parameters == null) { someRequest = new HTTP.Request(method, url); } else { someRequest = new HTTP.Request(method, url, parameters); } } // Set Request Keys someRequest.SetHeader(SConstants.RequestTokenKey, restifizerParams.GetRequestKey()); 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; Debug.Log("Response Text: " + request.response.Text); 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); 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); } }); }