Пример #1
0
        private Dictionary <string, object> BuildResultsForQueries <TQuery>(JsonObject jsonObject, IEnumerable <TQuery> queries)
            where TQuery : Query
        {
            var results = new Dictionary <string, object>();

            foreach (var query in queries)
            {
                object result;
                var    name = query.GetQueryName();

                if (query.IsFullJson())
                {
                    result = query.BuildResultFullJson(jsonObject);
                }
                else
                {
                    string json = jsonObject.Child(name);
                    result = query.BuildResult(json);
                }

                results.Add(name, result);
            }

            return(results);
        }
Пример #2
0
        internal ApiResult <TResult> Execute <TResult>(IApiAction <TResult> apiAction)
            where TResult : class
        {
            var request = new RestRequest("", apiAction.RequestMethod);

            request.AddParameter("action", apiAction.Action);

            var parameters = apiAction.BuildParameterList();

            foreach (var pair in parameters)
            {
                request.AddParameter(pair.Key, pair.Value);
            }

            var response = _client.Execute(request);

            var json       = JsonObject.Parse(response.Content);
            var actionJson = json.Object(apiAction.Action);

            var result = new ApiResult <TResult>
            {
                Result   = apiAction.BuildResult(actionJson),
                Response = response,
            };

            return(result);
        }
Пример #3
0
 public QueryResult BuildResult(JsonObject jsonObject)
 {
     return(new QueryResult
     {
         List = BuildResultsForQueries(jsonObject, ListQueries),
         Meta = BuildResultsForQueries(jsonObject, MetaQueries),
     });
 }
Пример #4
0
 public static Dictionary <string, string> ToDictionary(this JsonObject jsonObject)
 {
     return(jsonObject == null
                         ? new Dictionary <string, string>()
                         : new Dictionary <string, string>(jsonObject));
 }
Пример #5
0
 public static T ConvertTo <T>(this JsonObject jsonObject, Func <JsonObject, T> converFn)
 {
     return(jsonObject == null
                         ? default(T)
                         : converFn(jsonObject));
 }