static public RaqnResponse FromJson(string _json) { fsData _res_fsdata = fsJsonParser.Parse(_json); if (!_res_fsdata.IsDictionary) { return(null); } Dictionary <string, fsData> _dict = _res_fsdata.AsDictionary; if (!_dict.ContainsKey("status") || !_dict.ContainsKey("msg") || !_dict.ContainsKey("data")) { return(null); } string _res_status = _dict["status"].AsString; List <RaqnMsg> _res_msg = new List <RaqnMsg>(); if (_dict["msg"].IsList) { foreach (fsData _fsmsg in _dict["msg"].AsList) { RaqnMsg _msg = null; RaqnSerializer.Instance.TryDeserialize <RaqnMsg>(_fsmsg, ref _msg); if (_msg != null) { _res_msg.Add(_msg); } } } Dictionary <string, fsData> _res_data = new Dictionary <string, fsData>(); if (_dict["data"].IsDictionary) { _res_data = _dict["data"].AsDictionary; } RaqnResponse _res = new RaqnResponse(_res_status, _res_msg, _res_data); return(_res); }
protected void _UpdateFromResponse(RaqnResponse _res) { string _auth; RaqnApiSession _session; RaqnPlaySession _playSession; if (_res.TryGetData <string>("_auth", out _auth)) { this.auth = _auth; } if (_res.TryGetData <RaqnApiSession>("_session", out _session)) { this.session = _session; } if (_res.TryGetData <RaqnPlaySession>("_playsession", out _playSession)) { this.playSession = _playSession; } }
public IEnumerator SendRequest(RaqnRequest _req) { if (auth != null) { _req.SetAuth(auth); } //_req.OnSuccess += this.UpdateFromResponse; string _url = endpoint + _req.GetUri(); if (debug) { Debug.Log("Making Api Request to Url = " + _url + "\n" + _req.GetSerializedBody(true)); } string _str = _req.GetSerializedBody(); byte[] _body = Encoding.UTF8.GetBytes(_str); UnityWebRequest _web_req = new UnityWebRequest(_url, UnityWebRequest.kHttpVerbPOST); UploadHandlerRaw _uh = new UploadHandlerRaw(_body); _uh.contentType = "application/json"; _web_req.uploadHandler = _uh; _web_req.downloadHandler = new DownloadHandlerBuffer(); _web_req.SetRequestHeader("Content-Type", "application/json"); yield return(_web_req.Send()); if (_web_req.isNetworkError) { ResponseFailure(_req, "LOCAL_ERR_CONNECTION"); yield break; } string _json = _web_req.downloadHandler.text; if (debug) { Debug.Log("Received response. Returned " + _json); } RaqnResponse _res = RaqnResponse.FromJson(_json); if (_res == null) { ResponseFailure(_req, "LOCAL_ERR_PARSING"); yield break; } _UpdateFromResponse(_res); if (ResponseStatus.IsError(_res.status)) { if (_req.OnError != null) { string _err_code = _res.status; if (_res.GetMessageCode() != "") { _err_code = _res.GetMessageCode(); } _req.OnError(_err_code); } } else if (_req.OnSuccess != null) { _req.OnSuccess(_res); } }