public async Task <List <State> > GetStatesAsync(string filter = "") { filter = filter?.ToLower() ?? ""; var result = await _rest.GetAsync <JObject>("https://api.airtable.com/v0/app0RCW0xYP8RT3U9/Estados?api_key=keyhS9s7U3bGKSuml"); var states = result["records"].ToObject <List <State> >() .Where(s => s.Fields.Estado.ToLower().Contains(filter) || s.Fields.Capital.ToLower().Contains(filter)) .ToList(); return(states); }
public async Task PullAsync <T>() where T : EntityBase, new() { var modified = Connection.Table <T>().OrderByDescending(e => e.Modified).FirstOrDefault()?.Modified; var itens = await _client.GetAsync <List <T> >($"contacts?modified={modified?.ToString("o")}"); foreach (var remote in itens) { var local = Connection.Table <T>().SingleOrDefault(e => e.Id == remote.Id); remote.LocalId = local?.LocalId ?? 0; remote.Status = EntityStatus.Synchronized; Connection.InsertOrReplace(remote); } }
public CommitTree GetCommitInfo(BasicAuthentication authentication, string project, string repo, string branch, string commitId) { Logger.LogMessage($"Retrieving commit information for '{commitId}'"); var restHttpClient = new RestHttpClient(); var url = $"{authentication.AccountUrl}/{project}/_apis/git/repositories/{repo}/commits/{commitId}?api-version=1.0&versionType=branch&version={branch}"; CommitTree results; using (var response = restHttpClient.GetAsync <CommitTree>(authentication, url)) { results = response.Result; } return(results); }
public async void ThrowsExceptionOnError() { try { var item = await client.GetAsync <Todo>("todos/800"); throw new InvalidOperationException("Shouldn't get here!"); } //Use RestException's Request, Response or Content properties to determine how to handle the Exception catch (RestException ex) when(ex.Response?.StatusCode == HttpStatusCode.NotFound) { Console.WriteLine("Content not found."); } catch (RestException ex) { Console.WriteLine("Request failed, check out its content: "); Console.Write(ex.Content); throw; } }
public List <ItemDescriptor> GetFileList(BasicAuthentication authentication, string project, string repo, string branch, string rootPath, string fileExtension, bool fullRecursion) { var restHttpClient = new RestHttpClient(); var url = $"{authentication.AccountUrl}/{project}/_apis/git/repositories/{repo}/items?api-version=1.0&recursionLevel={(fullRecursion ? "Full" : "1")}&versionType=branch&version={branch}&scopePath={rootPath}"; var itemList = new List <ItemDescriptor>(); using (var response = restHttpClient.GetAsync <CollectionResult <ItemDescriptor> >(authentication, url)) { if (response.Result.Value.Count > 0) { foreach (var itemDescriptor in response.Result.Value) { if (!itemDescriptor.IsFolder && itemDescriptor.Path.EndsWith(fileExtension, System.StringComparison.InvariantCultureIgnoreCase)) { itemList.Add(itemDescriptor); } } } } return(itemList); }
/// <summary> /// Returns the object ID for the specified branch. /// </summary> /// <param name="authentication"></param> /// <param name="project"></param> /// <param name="repo"></param> /// <param name="branch"></param> /// <returns></returns> public string GetBranchObjectId(BasicAuthentication authentication, string project, string repo, string branch) { var restHttpClient = new RestHttpClient(); var url = $"{authentication.AccountUrl}/{project}/_apis/git/repositories/{repo}/refs/heads/{branch}?api-version=1.0"; var objectId = string.Empty; using (var response = restHttpClient.GetAsync <CollectionResult <Ref> >(authentication, url)) { if (response.Result.Value.Count > 0) { foreach (var branchItem in response.Result.Value) { if (branchItem.name.Equals($"refs/heads/{branch}", System.StringComparison.InvariantCultureIgnoreCase)) { objectId = branchItem.objectId; break; } } } } return(objectId); }
public async void GetAll() { var todos = await client.GetAsync <List <Todo> >("todos"); Assert.Equal(200, todos.Count); }