public async Task <List <Role> > FindAll(string token) { List <Role> list = new List <Role>(); HttpResponseMessage response = await _httpUtil.GetAsync(token, APIs.ROLE_URL); if (response == null || !response.IsSuccessStatusCode) { return(list); } string content = await response.Content.ReadAsStringAsync(); JArray jArray = JArray.Parse(content); foreach (JObject jObject in jArray) { if ((bool)jObject.GetValue(Keywords.ADMIN)) { continue; } string _id = jObject.GetValue(Keywords.ID).ToString(); string title = jObject.GetValue(Keywords.TITLE).ToString(); list.Add(new Role(_id, title, null, null)); } return(list); }
public async Task <List <Form> > FindForms(string token, string email, int page) { List <Form> list = new List <Form>(); string apiURI = APIs.FORM_URL + "?type=form&sort=-created&owner=" + email + "&limit=" + Configs.NUMBER_ROWS_PER_PAGE + "&skip=" + (page - 1) * Configs.NUMBER_ROWS_PER_PAGE + "&select=name,title,path,tags"; HttpResponseMessage response = await _httpUtil.GetAsync(token, apiURI); if (response == null || !response.IsSuccessStatusCode) { return(list); } string content = await response.Content.ReadAsStringAsync(); JArray jArray = JArray.Parse(content); foreach (JObject jObject in jArray) { string name = jObject.GetValue(Keywords.NAME).ToString(); string title = jObject.GetValue(Keywords.TITLE).ToString(); string path = jObject.GetValue(Keywords.PATH).ToString(); long amount = await _submissionService.CountSubmissions(token, path); FormControl formControl = await _formControlService.FindByPathForm(path); if (formControl == null) { return(list); } string start = formControl.Start; string expired = formControl.Expired; string assign = formControl.Assign; List <string> tags = new List <string>(); foreach (string tag in JArray.Parse(jObject.GetValue(Keywords.TAGS).ToString())) { tags.Add(tag); } int durationPercent = CalculateUtil.GetDurationPercent(start, expired); string typeProgressBar = CalculateUtil.GetTypeProgressBar(durationPercent); list.Add(new Form(name, title, path, amount, start, expired, tags, durationPercent, typeProgressBar, assign.Equals(Keywords.ANONYMOUS))); } return(list); }
public async Task <string> FindSubmissionsByPage(string token, string path, int page) { string apiURI = APIs.GetListSubmissionsURL(path) + "?select=data&limit=" + Configs.NUMBER_ROWS_PER_PAGE + "&skip=" + (page - 1) * Configs.NUMBER_ROWS_PER_PAGE; HttpResponseMessage response = await _httpUtil.GetAsync(token, apiURI); if (response == null || !response.IsSuccessStatusCode) { return("[]"); } string content = await response.Content.ReadAsStringAsync(); return(content); }
public async Task <bool> IsValidToken(string token) { HttpResponseMessage response = await _httpUtil.GetAsync(token, APIs.CURRENT_USER); if (response == null) { return(false); } return(response.IsSuccessStatusCode); }
public async Task <T> GetAsync <T>(string url, string accessToken) { var httpResponse = await _httpUtil.GetAsync(url, accessToken); httpResponse.EnsureSuccessStatusCode(); string stringResponse = await httpResponse.Content.ReadAsStringAsync(); var responseModel = JsonConvert.DeserializeObject <T>(stringResponse); return(responseModel); }
public async Task <string> GetWeather(string owmAPIKey, string idCity) { HttpResponseMessage response = await _httpUtil.GetAsync(APIs.GetWeather(owmAPIKey, idCity)); if (response == null || !response.IsSuccessStatusCode) { return("{}"); } string content = await response.Content.ReadAsStringAsync(); return(content); }
public async Task<Association> GetAssociationAsync(string word, int limit) { string responseString; try { responseString = await _httpUtil .GetAsync(string.Format(_settings.ApiTemplate, _settings.ApiKey, word, limit)); } catch (Exception ex) { throw new AssociationServiceException("Cannot get response from the API service", ex); } var responseModel = JsonConvert.DeserializeObject<ResponseModel>(responseString); return responseModel.Response.FirstOrDefault(); }
public async Task <IEnumerable <Product> > GetProductsAsync(string searchQuery) { string responseString; try { responseString = await _httpUtil .GetAsync(string.Format(_settings.ApiTemplate, searchQuery), _settings.ApiToken); } catch (Exception ex) { throw new ProductServiceException("Cannot get response from the eBay API service", ex); } var eBayItems = JsonConvert.DeserializeObject <ItemsSearchResponse>(responseString).ItemSummaries; var products = _mapper.Map <IEnumerable <Product> >(eBayItems); return(products ?? new List <Product>()); }
public async Task <string> FindUserDataById(string token, string path, string id) { string apiURI = APIs.GetListSubmissionsURL(Keywords.USER.ToLower()) + "/" + id; HttpResponseMessage response = await _httpUtil.GetAsync(token, apiURI); if (response == null || !response.IsSuccessStatusCode) { return("{}"); } string content = await response.Content.ReadAsStringAsync(); return(content); }
public async Task <string> FindGroupFieldByIdGroup(string token, string idGroup, string field) { string apiURI = APIs.GetListSubmissionsURL(Keywords.GROUP) + "?select=data&data.idGroup=" + idGroup; HttpResponseMessage response = await _httpUtil.GetAsync(token, apiURI); if (response == null || !response.IsSuccessStatusCode) { return(string.Empty); } string content = await response.Content.ReadAsStringAsync(); JArray jArray = JArray.Parse(content); if (jArray.Count == 0) { return(string.Empty); } JObject jObject = jArray.Children <JObject>().FirstOrDefault(); JObject dataObject = (JObject)jObject.GetValue(Keywords.DATA); return(dataObject.GetValue(field).ToString()); }