public void CreateClient_ShouldThrowException_WhenJsonSerializationSettingsFactory_Is_Null() { Assert.Throws <ArgumentNullException>(() => ApiClientFactory <ITestApi> .Create("http://www.test.com/api", () => { return(new MockHttpMessageHandler()); }, null)); }
private ApiV3LegacyDataTypeResolver() { var apiClient = ApiClientFactory.Create(BuffettCodeApiVersion.Version3, Configuration.GetInstance().ApiKey); var parser = ApiResponseParserFactory.Create(BuffettCodeApiVersion.Version3); // 適当にAPI をたたいて description を取得する var quarter = parser.Parse( DataTypeConfig.Quarter, apiClient.Get(DataTypeConfig.Quarter, quarterParameter, false, false, true) ); var daily = parser.Parse( DataTypeConfig.Daily, apiClient.Get(DataTypeConfig.Daily, dayParameter, false, false, true) ); // quarter を優先で map を作る foreach (string name in quarter.GetPropertyNames()) { mappingTable[name] = DataTypeConfig.Quarter; } foreach (string name in daily.GetPropertyNames().Where(name => !mappingTable.ContainsKey(name))) { mappingTable[name] = DataTypeConfig.Daily; } }
public void SingleApplicationResponse_Parsed_Successfully() { int expectedApplicationCount = 1; var apiClient = ApiClientFactory.Create(ApiClientTypes.Mock); List <DataModel.Application> applications = apiClient.GetSingleApplication(DataModel.MedicalInstitutions.NovaSoutheastern, "2018", "21070028"); Assert.AreEqual(expectedApplicationCount, applications.Count, "Application count not as expected"); }
public BuffettCodeApiTaskProcessor(BuffettCodeApiVersion version) { client = ApiClientFactory.Create(version, config.ApiKey); parser = ApiResponseParserFactory.Create(version); var tierResolver = PeriodSupportedTierResolver.Create(client, parser); taskHelper = new ApiTaskHelper(tierResolver); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); Application["apiClient"] = ApiClientFactory.Create(ApiClientTypes.Mock); Application["amcasRepository"] = new AmcasRepository(); }
public void CreateClient_ShouldReturnCorrectConcreteClient_With_Given_URL() { var isExecuted = false; var client = ApiClientFactory <ITestApi> .Create("http://www.test.com/api", () => { isExecuted = true; return(new MockHttpMessageHandler()); }, ApiConfiguration.DefaultJsonSerializationSettingsFactory); Assert.True(client is ITestApi); Assert.True(isExecuted); }
/// <summary> /// Execute example /// </summary> /// <param name="cancellationToken">The cancellation token</param> /// <returns>The task</returns> public async Task Execute(CancellationToken cancellationToken) { var factory = new ApiClientFactory(_options); var client = factory.Create <ListValuesV1Request, ListValuesV1Response>(); var request = ApiRequest.Create(new ListValuesV1Request()); var response = await client .Execute(request, cancellationToken) .ThrowIfFailed() .ConfigureAwait(Await.Default); Require.NotNull(response, nameof(response)); }
public AppViewModel() { m_Client = ApiClientFactory.Create(ApiToken); SelectedBudget = new Budget { Name = "Default" }; Budgets = new List <Budget> { SelectedBudget }; InitializeCommand = new AsyncCommand(Initialize, () => !m_IsInitialized); }
public void CreateTest() { // v2 var clientV2 = ApiClientFactory.Create(BuffettCodeApiVersion.Version2, BuffettCodeApiKeyConfig.TestApiKey); Assert.IsInstanceOfType(clientV2, typeof(BuffettCodeApiV2Client)); Assert.AreEqual(clientV2.GetApiKey(), BuffettCodeApiKeyConfig.TestApiKey); // v3 var clientV3 = ApiClientFactory.Create(BuffettCodeApiVersion.Version3, BuffettCodeApiKeyConfig.TestApiKey); Assert.IsInstanceOfType(clientV3, typeof(BuffettCodeApiV3Client)); Assert.AreEqual(clientV3.GetApiKey(), BuffettCodeApiKeyConfig.TestApiKey); // api key validation error Assert.ThrowsException <ValidationError>(() => ApiClientFactory.Create(BuffettCodeApiVersion.Version2, "dummy")); Assert.ThrowsException <ValidationError>(() => ApiClientFactory.Create(BuffettCodeApiVersion.Version3, "dummy")); }
public static async Task Main(string[] args) { try { HttpClientHandler httpClientHandler = new HttpClientHandler(); //httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; string token = await GetAccessToken(); var api = ApiClientFactory.Create(token, () => new HttpClient(httpClientHandler)); var budgetsResponse = await api.GetBudgets(); var budgets = budgetsResponse.Data.Budgets; if (budgets.Count == 0) { throw new InvalidOperationException("No budgets found!"); } Console.WriteLine($"Found {budgets.Count} budgets!"); Console.WriteLine(); budgets.ToList().ForEach(b => Console.WriteLine(b.Name)); Console.WriteLine(); var budget = budgets.FirstOrDefault(x => x.Name == "Dev Budget"); Console.WriteLine($"Reading budget {budget.Name} ({budget.Id})"); Console.WriteLine(); var accountsResponse = await api.GetAccounts(budget.Id); var accounts = accountsResponse.Data.Accounts; Console.WriteLine($"Found {accounts.Count} accounts!"); Console.WriteLine(); var account = accounts.OrderByDescending(x => x.Balance).FirstOrDefault(); Console.WriteLine($"Reading account {account.Name} ({account.Id}) with balance {account.Balance.YnabIntToDecimal()}"); Console.WriteLine(); var transactionsResponse = await api.GetTransactionsByAccount(budget.Id, account.Id); var transactions = transactionsResponse.Data.Transactions; Console.WriteLine($"Found {transactions.Count} transactions!"); Console.WriteLine(); transactions.ToList().ForEach(x => Console.WriteLine($"{x.Id} | {x.PayeeName} | {x.CategoryName} | {x.Memo} | {x.Amount.YnabIntToDecimal():C2} | {x.FlagColor}")); transactions = new List <Transaction> { new Transaction { PayeeName = "Test1", Amount = Convert.ToInt32(108.41 * 1000), Memo = "This is test 1", AccountId = account.Id, Date = new DateTime(2018, 01, 15), Cleared = ClearedStatus.Cleared }, new Transaction { PayeeName = "Test2", Amount = Convert.ToInt32(208.42 * 1000), Memo = "This is test 2", AccountId = account.Id, Date = new DateTime(2018, 02, 15), Cleared = ClearedStatus.Uncleared }, new Transaction { PayeeName = "Test3", Amount = Convert.ToInt32(308.43 * 1000), Memo = "This is test 3", AccountId = account.Id, Date = new DateTime(2018, 03, 15), Cleared = ClearedStatus.Uncleared } }; Console.WriteLine($"Posting {transactions.Count} transactions ..."); PostBulkTransactions bulk = new PostBulkTransactions { Transactions = transactions }; var result = await api.PostBulkTransactions(budget.Id, bulk); Console.WriteLine("Duplicate import IDs: " + string.Join(", ", result.Data.Bulk.DuplicateImportIds)); Console.WriteLine("Transaction IDs: " + string.Join(", ", result.Data.Bulk.TransactionIds)); Console.WriteLine("Posting a single transaction ..."); TransactionBody post = new TransactionBody { Transaction = new Transaction { PayeeName = "Test123", Amount = Convert.ToInt32(123.45 * 1000), Memo = "This is test 123", AccountId = account.Id, Date = new DateTime(2018, 01, 23), Cleared = ClearedStatus.Cleared } }; var t = (await api.PostTransaction(budget.Id, post)).Data.Transaction; Console.WriteLine($"Posted Transaction with ID {t.Id}."); t.Memo = "updated through PUT"; await api.PutTransaction(budget.Id, t.Id, new TransactionBody { Transaction = t }); var payeesResponse = await api.GetPayees(budget.Id); var payees = payeesResponse.Data.Payees; Console.WriteLine($"Found {payees.Count} payees!"); Console.WriteLine(); payees.ToList().ForEach(p => Console.WriteLine($"{p.Id} | {p.Name}")); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } Console.WriteLine(); Console.WriteLine("Press Enter to exit ..."); Console.ReadLine(); }
public void CreateClient_ShouldThrowException_WhenMessageHandlerFactory_Is_Null() { Assert.Throws <ArgumentNullException>(() => ApiClientFactory <ITestApi> .Create("http://www.test.com/api", null, ApiConfiguration.DefaultJsonSerializationSettingsFactory)); }