Esempio n. 1
0
 private static void ForRaw <T>(BaiduApiResponse <T> response, JObject respObj, bool keepRaw)
 {
     if (keepRaw)
     {
         response.Raw = respObj.ToString();
     }
 }
Esempio n. 2
0
        public static BaiduApiResponse <T> ToResponse <T>(this JObject respObj, string path, bool keepRaw = false)
        {
            var response = new BaiduApiResponse <T>();

            ForError(response, respObj);
            ForResult(response, respObj, path);
            ForRaw(response, respObj, keepRaw);
            return(response);
        }
Esempio n. 3
0
        private static void ForResult <T>(BaiduApiResponse <T> response, JObject respObj, string path = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                response.Result = respObj.ToObject <T>();
            }
            else
            {
                var    segments = path.Split('.');
                JToken target   = GetTargetByPath(respObj, segments);

                if (target != null)
                {
                    response.Result = target.ToObject <T>();
                }
            }
        }
Esempio n. 4
0
 private static void ForError <T>(BaiduApiResponse <T> response, JObject respObj)
 {
     if (respObj["error_code"] != null && (int)respObj["error_code"] > 0)
     {
         response.ErrorCode    = (int)respObj["error_code"];
         response.ErrorMessage = (string)respObj["error_msg"];
     }
     else if (respObj["err_no"] != null)
     {
         int errNo;
         if (int.TryParse((string)respObj["err_no"], out errNo))
         {
             if (errNo > 0)
             {
                 response.ErrorCode    = errNo;
                 response.ErrorMessage = (string)respObj["err_msg"];
             }
         }
     }
 }