/// <summary> /// Sends request on Ebenit API. /// </summary> /// <param name="url">Target URL</param> /// <param name="message">Message to be send. The final message will be created by MessageCreateFinal method.</param> /// <param name="result">ApiRequestResult object which will contain the result of request.</param> /// <returns></returns> public IEnumerator send(string url, object message, ref ApiRequestResult result) { string message_final = messageCreateFinal(message); if (string.IsNullOrEmpty(message_final)) { return(null); } return(send(url, message_final, ref result)); }
/// <summary> /// Parses fields into the result object. /// </summary> /// <param name="message">Message to be parsed.</param> /// <param name="result">ApiRequestResult object into which the parsed parameters will be saved.</param> /// <returns>True/False - True if the parsing was successful; False - otherwise</returns> public bool parseResponse(string message, ref ApiRequestResult result) { if (string.IsNullOrEmpty(message) || result == null) { return(false); } try { var response = JsonUtility.FromJson <ApiRequestResponse>(message); if (response != null) { result.setId(response.id); bool success = false; if (response.results != null) { success = response.results.success; } result.setSuccess(success); bool auth_error = true; bool auth_user_error = true; if (response.errors != null) { auth_error = response.errors.auth; auth_user_error = response.errors.authUser; } result.setAuthError(auth_error); result.setAuthUserError(auth_user_error); string message_wo_signature = getMessageWithoutSignature(message); string hmac = ApiRequest.hmac(message_wo_signature, m_token); if (!string.IsNullOrEmpty(hmac)) { result.setVerified(hmac.Equals(response.signature)); } return(true); } } catch (Exception) { return(false); } return(false); }
public override void handleResponse(UnityWebRequest request, object result_output = null) { if (result_output != null && result_output is ApiRequestResult) { ApiRequestResult result = (ApiRequestResult)result_output; if (request.isNetworkError || request.isHttpError || request.downloadedBytes == 0) { result.setWwwError(true); } else { result.setWwwError(false); result.setResponseSource(request.downloadHandler.text); result.setResponseDecoded(decodeBase64(result.pt_response_source)); parseResponse(result.pt_response_decoded, ref result); } result.setDone(true); } }
/// <summary> /// Sends request on Ebenit API. /// </summary> /// <param name="url">Target URL</param> /// <param name="message">Message to be send.</param> /// <param name="result">ApiRequestResult object which will contain the result of request.</param> /// <returns></returns> public IEnumerator send(string url, string message, ref ApiRequestResult result) { return(this.sendRequest(url, Encoding.UTF8, message, p_content_type, m_timeout, result)); }
// ---------------------------- // private methods - end // ---------------------------- // ---------------------------- // public methods - start // ---------------------------- /// <summary> /// Parses fields into the result object. /// </summary> /// <param name="message">Message to be parsed in Base64 string.</param> /// <param name="result">ApiRequestResult object into which the parsed parameters will be saved.</param> /// <returns>True/False - True if the parsing was successful; False - otherwise</returns> public bool parseResponseBase64(string message, ref ApiRequestResult result) { return(parseResponse(decodeBase64(message), ref result)); }