summaryrefslogtreecommitdiffstats
path: root/lib/WWW/YNAB
diff options
context:
space:
mode:
Diffstat (limited to 'lib/WWW/YNAB')
-rw-r--r--lib/WWW/YNAB/Budget.pm42
-rw-r--r--lib/WWW/YNAB/ScheduledSubTransaction.pm48
-rw-r--r--lib/WWW/YNAB/ScheduledTransaction.pm98
3 files changed, 188 insertions, 0 deletions
diff --git a/lib/WWW/YNAB/Budget.pm b/lib/WWW/YNAB/Budget.pm
index 97d0d84..5a8bdee 100644
--- a/lib/WWW/YNAB/Budget.pm
+++ b/lib/WWW/YNAB/Budget.pm
@@ -98,6 +98,18 @@ has _transactions => (
}
);
+has _scheduled_transactions => (
+ traits => ['Array'],
+ is => 'ro',
+ isa => 'ArrayRef[WWW::YNAB::ScheduledTransaction]',
+ init_arg => 'scheduled_transactions',
+ lazy => 1,
+ builder => '_build_scheduled_transactions',
+ handles => {
+ scheduled_transactions => 'elements',
+ }
+);
+
has _ua => (
is => 'ro',
isa => 'WWW::YNAB::UA',
@@ -257,6 +269,36 @@ sub transaction {
$self->model_from_data('WWW::YNAB::Transaction', \%transaction);
}
+sub _build_scheduled_transactions {
+ my $self = shift;
+
+ my $data = $self->_ua->get("/budgets/${\$self->id}/scheduled_transactions");
+ [
+ map {
+ my %transaction = %$_;
+ my @subtransactions = map {
+ $self->model_from_data('WWW::YNAB::ScheduledSubTransaction', $_)
+ } @{ $transaction{subtransactions} };
+ $transaction{subtransactions} = \@subtransactions;
+ $self->model_from_data('WWW::YNAB::ScheduledTransaction', \%transaction)
+ } @{ $data->{data}{scheduled_transactions} }
+ ]
+}
+
+sub scheduled_transaction {
+ my $self = shift;
+ my ($id) = @_;
+
+ my $data = $self->_ua->get("/budgets/${\$self->id}/scheduled_transactions/$id");
+ my $transaction = $data->{data}{scheduled_transaction};
+ my %transaction = %$transaction;
+ my @subtransactions = map {
+ $self->model_from_data('WWW::YNAB::ScheduledSubTransaction', $_)
+ } @{ $transaction{subtransactions} };
+ $transaction{subtransactions} = \@subtransactions;
+ $self->model_from_data('WWW::YNAB::ScheduledTransaction', \%transaction);
+}
+
__PACKAGE__->meta->make_immutable;
no Moose;
diff --git a/lib/WWW/YNAB/ScheduledSubTransaction.pm b/lib/WWW/YNAB/ScheduledSubTransaction.pm
new file mode 100644
index 0000000..d275f4d
--- /dev/null
+++ b/lib/WWW/YNAB/ScheduledSubTransaction.pm
@@ -0,0 +1,48 @@
+package WWW::YNAB::ScheduledSubTransaction;
+use Moose;
+
+has id => (
+ is => 'ro',
+ isa => 'Str',
+ required => 1,
+);
+
+has scheduled_transaction_id => (
+ is => 'ro',
+ isa => 'Str',
+);
+
+has amount => (
+ is => 'ro',
+ isa => 'Int',
+);
+
+has memo => (
+ is => 'ro',
+ isa => 'Maybe[Str]',
+);
+
+has payee_id => (
+ is => 'ro',
+ isa => 'Maybe[Str]',
+);
+
+has category_id => (
+ is => 'ro',
+ isa => 'Maybe[Str]',
+);
+
+has transfer_account_id => (
+ is => 'ro',
+ isa => 'Maybe[Str]',
+);
+
+has deleted => (
+ is => 'ro',
+ isa => 'Bool',
+);
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;
diff --git a/lib/WWW/YNAB/ScheduledTransaction.pm b/lib/WWW/YNAB/ScheduledTransaction.pm
new file mode 100644
index 0000000..98c67f1
--- /dev/null
+++ b/lib/WWW/YNAB/ScheduledTransaction.pm
@@ -0,0 +1,98 @@
+package WWW::YNAB::ScheduledTransaction;
+use Moose;
+
+use Moose::Util::TypeConstraints qw(enum maybe_type);
+
+has id => (
+ is => 'ro',
+ isa => 'Str',
+ required => 1,
+);
+
+has date_first => (
+ is => 'ro',
+ isa => 'Str',
+);
+
+has date_next => (
+ is => 'ro',
+ isa => 'Str',
+);
+
+has frequency => (
+ is => 'ro',
+ isa => enum([qw(
+ never daily weekly everyOtherWeek twiceAMonth every4Weeks
+ monthly everyOtherMonth every3Months every4Months twiceAYear
+ yearly everyOtherYear
+ )]),
+);
+
+has amount => (
+ is => 'ro',
+ isa => 'Int',
+);
+
+has memo => (
+ is => 'ro',
+ isa => 'Maybe[Str]',
+);
+
+has flag_color => (
+ is => 'ro',
+ isa => maybe_type(enum([qw(red orange yellow green blue purple)])),
+);
+
+has account_id => (
+ is => 'ro',
+ isa => 'Str',
+);
+
+has payee_id => (
+ is => 'ro',
+ isa => 'Maybe[Str]',
+);
+
+has category_id => (
+ is => 'ro',
+ isa => 'Maybe[Str]',
+);
+
+has transfer_account_id => (
+ is => 'ro',
+ isa => 'Maybe[Str]',
+);
+
+has deleted => (
+ is => 'ro',
+ isa => 'Bool',
+);
+
+has account_name => (
+ is => 'ro',
+ isa => 'Str',
+);
+
+has payee_name => (
+ is => 'ro',
+ isa => 'Maybe[Str]',
+);
+
+has category_name => (
+ is => 'ro',
+ isa => 'Maybe[Str]',
+);
+
+has subtransactions => (
+ traits => ['Array'],
+ is => 'bare',
+ isa => 'ArrayRef[WWW::YNAB::ScheduledSubTransaction]',
+ handles => {
+ subtransactions => 'elements',
+ }
+);
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;