Skip to content

Commit

Permalink
resolve #3 - add missing attributes to objects
Browse files Browse the repository at this point in the history
Transaction and Merchant objects now have attributes that map to
the available values from the live Mondo API. update tests, pod,
and the emulator to reflect above changes

bump VERSION and Changes for CPAN release
  • Loading branch information
leejo committed May 28, 2016
1 parent 6916f1d commit 6a66241
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 89 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,3 +14,4 @@ cover_db
end_to_end.sh
examples/
.DS_Store
live_testing/
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
Revision history for Business-Mondo

0.04 2015-05-28
- Add missing attributes to Transaction and Merchant objects (GH #3)

0.03 2015-05-22
- Kwalitee improvements

Expand Down
2 changes: 1 addition & 1 deletion lib/Business/Mondo.pm
Expand Up @@ -11,7 +11,7 @@ Business::Mondo - Perl library for interacting with the Mondo API
=head1 VERSION
0.03
0.04
=head1 DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion lib/Business/Mondo/Currency.pm
Expand Up @@ -17,7 +17,7 @@ use Moo::Role;
use Types::Standard qw/ :all /;
use Data::Currency;

has currency => (
has [ qw/ currency local_currency / ] => (
is => 'ro',
isa => Maybe[InstanceOf['Data::Currency']],
coerce => sub {
Expand Down
19 changes: 17 additions & 2 deletions lib/Business/Mondo/Merchant.pm
Expand Up @@ -31,12 +31,17 @@ The Merchant class has the following attributes (with their type).
emoji (Str)
name (Str)
category (Str)
online (Bool)
atm (Bool)
disable_feedback (Bool)
address (Business::Mondo::Address)
created (DateTime)
updated (DateTime)
metadata (HashRef)
Note that if a HashRef or Str is passed to ->address it will be coerced
into a Business::Mondo::Address object. When a Str is passed to ->created
this will be coerced to a DateTime object.
or ->updated these will be coerced to a DateTime object.
=cut

Expand All @@ -45,6 +50,16 @@ has [ qw/ id group_id logo emoji name category / ] => (
isa => Str,
);

has [ qw/ metadata / ] => (
is => 'ro',
isa => HashRef,
);

has [ qw/ online atm disable_feedback / ] => (
is => 'ro',
isa => Bool,
);

has address => (
is => 'ro',
isa => Maybe[InstanceOf['Business::Mondo::Address']],
Expand All @@ -63,7 +78,7 @@ has address => (
},
);

has created => (
has [ qw/ created updated / ] => (
is => 'ro',
isa => Maybe[InstanceOf['DateTime']],
coerce => sub {
Expand Down
10 changes: 3 additions & 7 deletions lib/Business/Mondo/Resource.pm
Expand Up @@ -80,18 +80,14 @@ sub to_hash {

delete( $hash{client} );

foreach my $k ( qw/ created settled / ) {
if ( $hash{$k} ) {
$hash{$k} = $hash{$k}->iso8601;
}
}

if ( blessed( $hash{currency} ) ) {
$hash{currency} = $hash{currency}->code;
}

foreach my $k ( keys %hash ) {
if ( my $blessed = blessed( $hash{$k} ) ) {
if ( ref( $hash{$k} ) eq 'DateTime' ) {
$hash{$k} = $hash{$k}->iso8601;
} elsif ( my $blessed = blessed( $hash{$k} ) ) {
next if $blessed =~ /Boolean/;
$hash{$k} = $hash{$k}->to_hash;
}
Expand Down
26 changes: 19 additions & 7 deletions lib/Business/Mondo/Transaction.pm
Expand Up @@ -28,41 +28,53 @@ use DateTime::Format::DateParse;
The Transaction class has the following attributes (with their type).
id (Str)
account_id (Str)
category (Str)
dedupe_id (Str)
description (Str)
notes (Str)
scheme (Str)
account_balance (Int)
amount (Int)
local_amount (Int)
counterparty (HashRef)
metadata (HashRef)
is_load (Bool)
originator (Bool)
merchant (Business::Mondo::Merchant)
currency (Data::Currency)
local_currency (Data::Currency)
created (DateTime)
updated (DateTime)
settled (DateTime)
attachments (ArrayRef[Business::Mondo::Attachment])
Note that if a HashRef or Str is passed to ->merchant it will be coerced
into a Business::Mondo::Merchant object. When a Str is passed to ->currency
this will be coerced to a Data::Currency object, and when a Str is passed
to ->created / ->settled this will be coerced to a DateTime object.
/ ->local_currency this will be coerced to a Data::Currency object, and
when a Str is passed to ->created / ->updated / ->settled this will be
coerced to a DateTime object.
=cut

has [ qw/ id description notes / ] => (
has [ qw/
id account_id category dedupe_id description notes scheme
/ ] => (
is => 'ro',
isa => Str,
);

has [ qw/ account_balance amount / ] => (
has [ qw/ account_balance amount local_amount / ] => (
is => 'ro',
isa => Int,
);

has [ qw/ metadata / ] => (
has [ qw/ counterparty metadata / ] => (
is => 'ro',
isa => HashRef,
);

has [ qw/ is_load / ] => (
has [ qw/ is_load originator / ] => (
is => 'ro',
isa => Bool,
);
Expand Down Expand Up @@ -113,7 +125,7 @@ has attachments => (
},
);

has [ qw/ created settled / ] => (
has [ qw/ created updated settled / ] => (
is => 'ro',
isa => Maybe[InstanceOf['DateTime']],
coerce => sub {
Expand Down
2 changes: 1 addition & 1 deletion lib/Business/Mondo/Version.pm
Expand Up @@ -15,7 +15,7 @@ use warnings;

use Moo::Role;

$Business::Mondo::VERSION = '0.03';
$Business::Mondo::VERSION = '0.04';
$Business::Mondo::API_VERSION = 'v1';
$Business::Mondo::API_URL = 'https://api.getmondo.co.uk';

Expand Down
114 changes: 77 additions & 37 deletions mondo_emulator.pl
Expand Up @@ -263,60 +263,100 @@ sub _transactions {

return [
{
"account_balance" => 13013,
"amount" => -510,
"created" => "2015-08-22T12:20:18Z",
"currency" => "GBP",
"description" => "THE DE BEAUVOIR DELI C LONDON GBR",
"id" => "tx_00008zIcpb1TB4yeIFXMzx",
"merchant" => $expand eq 'merchant'
? _merchant()
: "merch_00008zIcpbAKe8shBxXUtl",
"merchant" => undef,
"counterparty" => {},
"local_amount" => 10000,
"id" => "1",
"created" => "2016-04-22T12:35:55.563Z",
"is_load" => Mojo::JSON::true,
"updated" => "2016-04-28T20:15:35.043Z",
"notes" => "",
"dedupe_id" => "5529515640563",
"description" => "Initial top up",
"attachments" => [],
"metadata" => $metadata,
"notes" => "Salmon sandwich 🍞",
"is_load" => Mojo::JSON::false,
"settled" => '2015-08-23T12:20:18Z',
"attachments" => [ $attachment,$attachment ],
"account_balance" => 10000,
"originator" => Mojo::JSON::false,
"scheme" => "gps_mastercard",
"amount" => 10000,
"settled" => "2016-04-22T12:35:55.563Z",
"account_id" => "acc_0000000000000000000001",
"local_currency" => "GBP",
"category" => "mondo"
},
{
"account_balance" => 12334,
"amount" => -679,
"created" => "2015-08-23T16:15:03Z",
"amount" => -1433,
"settled" => "2016-04-24T23:00:00.5Z",
"originator" => Mojo::JSON::false,
"account_balance" => 8565,
"scheme" => "gps_mastercard",
"category" => "cash",
"account_id" => "acc_0000000000000000000001",
"local_currency" => "CHF",
"id" => "2",
"created" => "2016-04-23T09:22:44.12Z",
"currency" => "GBP",
"description" => "VUE BSL LTD ISLINGTON GBR",
"id" => "tx_00008zL2INM3xZ41THuRF3",
"counterparty" => {},
"merchant" => $expand eq 'merchant'
? _merchant()
: "merch_00008zIcpbAKe8shBxXUtl",
: "merch_0000000000000000000001",
"local_amount" => -2000,
"description" => "BCV VILLARS/OLL. 2 Villars-sur-O CHE",
"dedupe_id" => "565726953219015109",
"attachments" => [ $attachment,$attachment ],
"metadata" => $metadata,
"notes" => "",
"is_load" => Mojo::JSON::false,
"settled" => '2015-08-23T12:20:18Z',
"category" => "eating_out",
"attachments" => [ $attachment,$attachment ],
"updated" => "2016-04-25T09:50:56.605Z",
"notes" => ""
},
];
}

sub _merchant {

return {
"address" => {
"address" => "98 Southgate Road",
"city" => "London",
"country" => "GB",
"latitude" => 51.54151,
"longitude" => -0.08482400000002599,
"postcode" => "N1 3JD",
"region" => "Greater London"
"merchant" => {
"emoji" => "💵",
"updated" => "2016-04-23T09:22:45.005Z",
"online" => Mojo::JSON::false,
"category" => "cash",
"metadata" => {
"suggested_tags" => "#money #ATM #cashpoint #cash ",
"google_places_id" => "ChIJzXdG2omVjkcRqXc-9o1QxZI",
"foursquare_category" => "ATM",
"foursquare_id" => "",
"foursquare_website" => "",
"suggested_name" => "Caixa 24 Horas",
"foursquare_category_icon" => "https://ss3.4sqi.net/img/categories_v2/shops/financial_88.png",
"google_places_icon" => "https://maps.gstatic.com/mapfiles/place_api/icons/bank_dollar-71.png",
"google_places_name" => "UBS",
"created_for_merchant" => "merch_0000000000000000000001",
"created_for_transaction" => "1",
"twitter_id" => "",
"website" => ""
},
"disable_feedback" => Mojo::JSON::false,
"atm" => Mojo::JSON::true,
"logo" => "",
"group_id" => "grp_0000000000000000000001",
"id" => "merch_0000000000000000000001",
"name" => "ATM",
"created" => "2016-04-23T09:22:45.005Z",
"address" => {
"country" => "CHE",
"city" => "Villars-sur-o",
"longitude" => 7.076864,
"address" => "",
"region" => "",
"formatted" => "Villars-sur-o, 1884, Switzerland",
"latitude" => 46.3118929,
"approximate" => Mojo::JSON::false,
"zoom_level" => 17,
"short_formatted" => "Villars-sur-o, 1884, Switzerland",
"postcode" => "1884"
}
},
"created" => "2015-08-22T12:20:18Z",
"group_id" => "grp_00008zIcpbBOaAr7TTP3sv",
"id" => "merch_00008zIcpbAKe8shBxXUtl",
"logo" => "https://pbs.twimg.com/profile_images/527043602623389696/68_SgUWJ.jpeg",
"emoji" => "🍞",
"name" => "The De Beauvoir Deli Co.",
"category" => "eating_out"
};
}

Expand Down
2 changes: 1 addition & 1 deletion t/004_end_to_end_LIVE.t
Expand Up @@ -15,7 +15,7 @@ plan skip_all => "MONDO_ENDTOEND_LIVE required"

# this is an "end to end" test - it will call the Mondo API
# using the details defined in the ENV variables below.
my ( $token,$url,$skip_cert ) = @ENV{qw/
my ( $token,$url ) = @ENV{qw/
MONDO_TOKEN
MONDO_URL
/};
Expand Down

0 comments on commit 6a66241

Please sign in to comment.