public MainWindow() { InitializeComponent(); client = new HarvestClient("HavestApiClient") { ClientId = "<ClientId>", ClientSecret = "<ClientSecret>", RedirectUri = new Uri("http://redirect/url"), }; webBrowser.Source = client.BuildAuthorizationUrl(); webBrowser.Navigating += async(s, e) => { if (client.IsRedirectUri(e.Uri)) { e.Cancel = true; try { await client.AuthorizeAsync(e.Uri); await ApiSample(client); } catch { webBrowser.Source = client.BuildAuthorizationUrl(); } } }; }
public static HarvestClient Create() { var client = HarvestClient.FromAccessToken("TestClient", "<access token>"); client.DefaultAccountId = null; return(client); }
public static HarvestClient CreateFromHarvestEntry(string clientId, string name, string address) { var result = new HarvestClient(); result.ClientId = clientId; result.Name = name; result.Address = address; return result; }
public async System.Threading.Tasks.Task ApiSample(HarvestClient harvestClient) { await harvestClient.RefreshTokenAsync(); var proj = await harvestClient.GetProjectAssignmentsAsync(); Debugger.Break(); }
public void Initialize() { var config = new ConfigurationBuilder() .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) .AddUserSecrets <HarvestClientTests>() .Build(); UserConfig uc = config.Get <UserConfig>(); harvestClient = new HarvestClient(uc.harvestAccountId, uc.harvestPersonalAccessToken); }
public async Task <bool> VerifyConfiguration() { try { var token = Environment.GetEnvironmentVariable(HARVEST_DEVELOPER_TOKEN); if (String.IsNullOrWhiteSpace(token)) { throw new NotSupportedException( $"Must set environment variable {HARVEST_DEVELOPER_TOKEN}, see https://id.getharvest.com/developers to get one"); } client = HarvestClient.FromAccessToken("SunnyHarvestTool", token); var accounts = await client.GetAccountsAsync(); if (accounts == null || accounts.Accounts == null) { throw new NotSupportedException("Empty accounts package"); } if (accounts.Accounts.Length > 1) { throw new NotSupportedException("Do not handle multiple accounts yet"); } Console.WriteLine($"Using Account {accounts.Accounts[0].Id}={accounts.Accounts[0].Name}"); client.DefaultAccountId = accounts.Accounts[0].Id; me = await client.GetMe(); if (me == null) { throw new Exception("unexpected null result"); } Console.WriteLine($"Logged in as {me.FirstName} {me.LastName} ({me.Id})"); ReadMapFiles(); return(true); } catch (Exception ex) { Console.Error.WriteLine($"Could not verify configuration - {ex.Message}"); return(false); } }
public void HarvestClientTest_Fail() { var harvestClient = new HarvestClient("8587589", "aisdgoisgduasduhapdh"); }