示例#1
0
 protected BaseApiController(IRepository <TEntity> repository, IEntityExpressionsBuilder entityExpressionsBuilder,
                             IApiQuery apiQuery, IApiHelper apiHelper)
 {
     EntityRepository         = repository ?? throw new ArgumentNullException(nameof(repository));
     EntityExpressionsBuilder = entityExpressionsBuilder ?? throw new ArgumentNullException(nameof(entityExpressionsBuilder));
     ApiQuery  = apiQuery ?? throw new ArgumentNullException(nameof(apiQuery));
     ApiHelper = apiHelper ?? throw new ArgumentNullException(nameof(apiHelper));
 }
示例#2
0
        protected IRestRequest PrepareRequest(string resourceUrl, IApiQuery query = null)
        {
            query = query ?? new ApiQuery();

            var request = new RestRequest(resourceUrl, HttpRetrievalMethod, DataFormat.Json);

            request.AddParameter(CONTENT_TYPE_TEXT_PLAIN, query.GetQueryString(), ParameterType.RequestBody);

            return(request);
        }
        public async Task<TApiQueryResult> Query<TApiQueryResult>(IApiQuery<TApiQueryResult> query)
        {
            if (String.IsNullOrEmpty(query.ApiKey))
                query.ApiKey = _options.ApiKey;

            if (String.IsNullOrEmpty(query.ApiKey))
                throw new Exception("Api key required.");

            return await _webClient.Query(query);
        }
示例#4
0
        public async Task <TApiQueryResult> Query <TApiQueryResult>(IApiQuery <TApiQueryResult> query)
        {
            using (var webClient = new System.Net.WebClient())
            {
                webClient.QueryString = query.Parameters.Aggregate(new NameValueCollection(),
                                                                   (seed, current) => {
                    seed.Add(current.Key, current.Value);
                    return(seed);
                });
                var json = await webClient.DownloadStringTaskAsync(QUERY_URL);

                return(_deserializer.Deserialize <TApiQueryResult>(json));
            }
        }
示例#5
0
        public IEnumerable <GameEngine> GetGameEngines(IApiQuery query = null)
        {
            IRestRequest req = PrepareRequest(RESOURCE_GAME_ENGINES, query);

            var gameEnginesResponse = _restClient.Post <List <GameEngine> >(req);

            Exception exception = BuildExceptionForResponse(gameEnginesResponse);

            if (exception != null)
            {
                throw exception;
            }

            return(gameEnginesResponse?.Data);
        }
示例#6
0
        public async Task <IEnumerable <GameEngineLogo> > GetGameEngineLogosAsync(IApiQuery query = null)
        {
            IRestRequest req = PrepareRequest(RESOURCE_GAME_ENGINE_LOGOS, query);

            var response = await _restClient.ExecutePostAsync <List <GameEngineLogo> >(req);

            Exception exception = BuildExceptionForResponse(response);

            if (exception != null)
            {
                throw exception;
            }

            return(response?.Data);
        }
示例#7
0
        public async Task <TApiQueryResult> Query <TApiQueryResult>(IApiQuery <TApiQueryResult> query)
        {
            using (var webClient = new System.Net.WebClient())
            {
                webClient.QueryString = query.Parameters.Aggregate(new NameValueCollection(),
                                                                   (seed, current) => {
                    seed.Add(current.Key, current.Value);
                    return(seed);
                });
                using (var stream = await webClient.OpenReadTaskAsync(QUERY_URL))
                {
                    var result = _deserializer.Deserialize <TApiQueryResult>(stream);

                    return(result);
                }
            }
        }
示例#8
0
 public NoteFileController(IRepository <NoteFile> repository, IEntityExpressionsBuilder entityExpressionsBuilder,
                           IApiQuery apiQuery, IApiHelper apiHelper, INoteFileService noteFileService) : base(repository, entityExpressionsBuilder, apiQuery, apiHelper)
 {
     _noteFileService = noteFileService;
 }
示例#9
0
 public CategoryController(IRepository <NoteCategory> repository, IEntityExpressionsBuilder entityExpressionsBuilder,
                           IApiQuery apiQuery, IApiHelper apiHelper) : base(repository, entityExpressionsBuilder, apiQuery, apiHelper)
 {
 }
示例#10
0
 public ApiHelper(IApiQuery apiQuery)
 {
     _apiQuery = apiQuery;
 }
示例#11
0
 public ApiHelper(IApiQuery apiQuery, IOptions <RestApiOptions> options)
 {
     _apiQuery          = apiQuery ?? throw new ArgumentNullException(nameof(apiQuery));
     _showFullErrorInfo = options.Value.ApiException.ShowFullErrorInfo;
 }