-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3 Add some more examples and Synchronous versions
- Loading branch information
Jake Moening
committed
Aug 29, 2019
1 parent
1fe8f28
commit edda497
Showing
12 changed files
with
483 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.