Skip to content

Commit

Permalink
#3 Add some more examples and Synchronous versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Moening committed Aug 29, 2019
1 parent 1fe8f28 commit edda497
Show file tree
Hide file tree
Showing 12 changed files with 483 additions and 87 deletions.
38 changes: 36 additions & 2 deletions YNAB.SDK.Tests/YNAB_ExamplesShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,45 @@ public async Task Examples_RunSuccessfully() {
});
var budgetMonthId = "2019-08-01";
var budgetId = new Guid("14235236-8085-4cf6-9fa6-92c34ed44b0c");
var categoryId = new Guid("3b89df53-1869-4d2f-a636-d09eadc3f0ca");
// Act
// Assert
try {
await new BudgetList(_token).FetchBudgets();
await new BudgetMonth(_token).FetchBudgetMonth(budgetId, budgetMonthId);
var ble = new BudgetListExample(_token);
ble.Execute();
await ble.ExecuteAsync();

var bme = new BudgetMonthExample(_token);
bme.Execute(budgetId, budgetMonthId);
await bme.ExecuteAsync(budgetId, budgetMonthId);

var btc = new BulkTransactionCreate(_token);
// btc.Execute();
// await btc.ExecuteAsync();

var cbe = new CategoryBalanceExample(_token);
cbe.Execute(budgetId, categoryId);
await cbe.ExecuteAsync(budgetId, categoryId);

var cmt = new CreateMultipleTransactions(_token);
// cmt.Execute();
// await cmt.ExecuteAsync();

var ct = new CreateTransaction(_token);
// ct.Execute();
// await ct.ExecuteAsync();

var dre = new DeltaRequestExample(_token);
dre.Execute();
await dre.ExecuteAsync();

var ucb = new UpdateCategoryBudgeted(_token);
// ucb.Execute();
// await ucb.ExecuteAsync();

var ut = new UpdateTransaction(_token);
// ut.Execute();
// await ut.ExecuteAsync();
} catch (Exception ex) {
Assert.True(false, ex.Message);
}
Expand Down
35 changes: 0 additions & 35 deletions YNAB.SDK/examples/BudgetList.cs

This file was deleted.

61 changes: 61 additions & 0 deletions YNAB.SDK/examples/BudgetListExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using YNAB.SDK;
using System.Threading.Tasks;
using System;

namespace YNAB.SDK.Examples {
public class BudgetListExample {
private readonly API _ynabAPI;
public BudgetListExample(string accessToken)
{
_ynabAPI = new API(accessToken);
}

public async Task ExecuteAsync()
{
try {
var budgetResponse = await _ynabAPI.Budgets.GetBudgetsAsync();
var budgets = budgetResponse.Data.Budgets;
Console.WriteLine($"This user has {budgets.Count} budgets.");
Console.WriteLine(@"
===========
BUDGET LIST
===========
");
budgets.ForEach(budget => {
Console.WriteLine(
$"[id: {budget.Id}, name: {budget.Name}, lastModifiedOn: {budget.LastModifiedOn}]"
);
});
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
throw;
}
}

public void Execute()
{
try {
var budgetResponse = _ynabAPI.Budgets.GetBudgets();
var budgets = budgetResponse.Data.Budgets;
Console.WriteLine($"This user has {budgets.Count} budgets.");
Console.WriteLine(@"
===========
BUDGET LIST
===========
");
budgets.ForEach(budget => {
Console.WriteLine(
$"[id: {budget.Id}, name: {budget.Name}, lastModifiedOn: {budget.LastModifiedOn}]"
);
});
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
throw;
}
}
}
}
50 changes: 0 additions & 50 deletions YNAB.SDK/examples/BudgetMonth.cs

This file was deleted.

91 changes: 91 additions & 0 deletions YNAB.SDK/examples/BudgetMonthExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System.Threading.Tasks;
using System;

namespace YNAB.SDK.Examples {
public class BudgetMonthExample {
private readonly API _ynabAPI;
public BudgetMonthExample(string accessToken)
{
_ynabAPI = new API(accessToken);
}

public async Task ExecuteAsync(Guid budgetId, string monthId)
{
try {
var monthResponse = await _ynabAPI.Months.GetBudgetMonthAsync(budgetId.ToString(), DateTime.Parse(monthId));
var budgetMonth = monthResponse.Data.Month;
Console.WriteLine($@"
============
BUDGET MONTH
============
Month: ${budgetMonth.Month}
Note: ${budgetMonth.Note ?? ""}
Age Of Money: ${budgetMonth.AgeOfMoney}
Category Balances:
");
budgetMonth.Categories.ForEach(category => {
var balance = string.Format("{0:0.00}", Utils.ConvertMilliUnitsToCurrencyAmount(category.Balance, 2));
Console.WriteLine(
$" {category.Name} - ${balance}"
);
/*
Month: 2017-11-01
Note: Month Note here
Age Of Money: 103
Category Balances:
Medical - $50.00
Deferred Income SubCategory - $0.00
Immediate Income SubCategory - $0.00
Renter's/Home Insurance - $0.00
...
*/
});
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
throw;
}
}

public void Execute(Guid budgetId, string monthId)
{
try {
var monthResponse = _ynabAPI.Months.GetBudgetMonth(budgetId.ToString(), DateTime.Parse(monthId));
var budgetMonth = monthResponse.Data.Month;
Console.WriteLine($@"
============
BUDGET MONTH
============
Month: ${budgetMonth.Month}
Note: ${budgetMonth.Note ?? ""}
Age Of Money: ${budgetMonth.AgeOfMoney}
Category Balances:
");
budgetMonth.Categories.ForEach(category => {
var balance = string.Format("{0:0.00}", Utils.ConvertMilliUnitsToCurrencyAmount(category.Balance, 2));
Console.WriteLine(
$" {category.Name} - ${balance}"
);
/*
Month: 2017-11-01
Note: Month Note here
Age Of Money: 103
Category Balances:
Medical - $50.00
Deferred Income SubCategory - $0.00
Immediate Income SubCategory - $0.00
Renter's/Home Insurance - $0.00
...
*/
});
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
throw;
}
}
}
}

21 changes: 21 additions & 0 deletions YNAB.SDK/examples/BulkTransactionCreate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Threading.Tasks;

namespace YNAB.SDK.Examples
{
public class BulkTransactionCreate
{
private readonly API _ynabApi;
public BulkTransactionCreate(string accessToken)
{
_ynabApi = new API(accessToken);
}

private async Task ExecuteAsync() {
throw new NotImplementedException();
}
private void Execute() {
throw new NotImplementedException();
}
}
}
55 changes: 55 additions & 0 deletions YNAB.SDK/examples/CategoryBalanceExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Threading.Tasks;
using System;

namespace YNAB.SDK.Examples {
public class CategoryBalanceExample {
private readonly API _ynabAPI;
public CategoryBalanceExample(string accessToken)
{
_ynabAPI = new API(accessToken);
}

public async Task ExecuteAsync(Guid budgetId, Guid categoryId)
{
try {
var monthResponse = await _ynabAPI.Categories.GetCategoryByIdAsync(budgetId.ToString(), categoryId.ToString());
var category = monthResponse.Data.Category;
Console.WriteLine($@"
============
CATEGORY
============
Name: ${category.Name}
Budgeted: ${category.Budgeted}
Balance: ${category.Balance}
");
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
throw;
}
}

public void Execute(Guid budgetId, Guid categoryId)
{
try {
var monthResponse = _ynabAPI.Categories.GetCategoryById(budgetId.ToString(), categoryId.ToString());
var category = monthResponse.Data.Category;
Console.WriteLine($@"
============
CATEGORY
============
Name: ${category.Name}
Budgeted: ${category.Budgeted}
Balance: ${category.Balance}
");
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
throw;
}
}
}
}

21 changes: 21 additions & 0 deletions YNAB.SDK/examples/CreateMultipleTransactions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Threading.Tasks;

namespace YNAB.SDK.Examples
{
public class CreateMultipleTransactions
{
private readonly API _ynabApi;
public CreateMultipleTransactions(string accessToken)
{
_ynabApi = new API(accessToken);
}

private async Task ExecuteAsync() {
throw new NotImplementedException();
}
private void Execute() {
throw new NotImplementedException();
}
}
}
Loading

0 comments on commit edda497

Please sign in to comment.