my
$modname
=
"lendingclub-perl-module"
;
my
$modver
=
"0.1.0"
;
$LendingClub::API::VERSION
=
'0.1.0'
;
my
$ua
= LWP::UserAgent->new();
$ua
->agent(
"${modname}/${modver}"
);
$ua
->timeout(1);
$ua
->default_header(
'Accept'
=>
"application/json"
);
my
%lcapi
= (
version
=>
"v1"
);
$lcapi
{urls}{api}{accounts_url} =
$lcapi
{urls}{api_url}.
"/accounts"
;
$lcapi
{urls}{api}{loans_url} =
$lcapi
{urls}{api_url}.
"/loans"
;
$lcapi
{urls}{api}{loans}{listing} =
$lcapi
{urls}{api}{loans_url}.
"/listing"
;
my
$o
= new Hash::Flatten();
sub
new
{
my
(
$class
,
$investor_id
,
$api_key
) =
@_
;
my
$self
= ( {} );
croak(
"api_key not defined"
)
if
( !
defined
(
$api_key
) );
croak(
"investor_id not defined"
)
if
( !
defined
(
$investor_id
) );
$lcapi
{urls}{api}{accounts}{investor_id} =
$lcapi
{urls}{api}{accounts_url}.
"/"
.
$investor_id
;
$lcapi
{urls}{api}{accounts}{availablecash} =
$lcapi
{urls}{api}{accounts}{investor_id}.
"/availablecash"
;
$lcapi
{urls}{api}{accounts}{summary} =
$lcapi
{urls}{api}{accounts}{investor_id}.
"/summary"
;
$lcapi
{urls}{api}{accounts}{notes} =
$lcapi
{urls}{api}{accounts}{investor_id}.
"/notes"
;
$lcapi
{urls}{api}{accounts}{detailednotes} =
$lcapi
{urls}{api}{accounts}{investor_id}.
"/detailednotes"
;
$lcapi
{urls}{api}{accounts}{portfolios} =
$lcapi
{urls}{api}{accounts}{investor_id}.
"/portfolios"
;
$lcapi
{urls}{api}{accounts}{orders} =
$lcapi
{urls}{api}{accounts}{investor_id}.
"/orders"
;
$ua
->default_header(
'Authorization'
=>
$api_key
);
return
bless
(
$self
,
$class
);
}
sub
available_cash
{
my
(
$self
) =
@_
;
return
$self
->_json_get(
$lcapi
{urls}{api}{accounts}{availablecash} )->{availableCash};
}
sub
summary
{
my
(
$self
) =
@_
;
return
$o
->unflatten(
$self
->_json_get(
$lcapi
{urls}{api}{accounts}{summary} ) );
}
sub
notes_owned
{
my
(
$self
) =
@_
;
return
$o
->unflatten(
$self
->_json_get(
$lcapi
{urls}{api}{accounts}{notes} ) );
}
sub
detailed_notes_owned
{
my
(
$self
) =
@_
;
return
$o
->unflatten(
$self
->_json_get(
$lcapi
{urls}{api}{accounts}{detailednotes} ) );
}
sub
portfolios_owned
{
my
(
$self
) =
@_
;
return
$o
->unflatten(
$self
->_json_get(
$lcapi
{urls}{api}{accounts}{portfolios} ) );
}
sub
listed_loans
{
my
(
$self
,
$showAll
) =
@_
;
return
$o
->unflatten(
$self
->_json_get(
$lcapi
{urls}{api}{loans}{listing} ) );
}
sub
_json_get
{
my
(
$self
,
$url
) =
@_
;
return
decode_json
$ua
->get(
$url
)->decoded_content();
}
sub
_json_post
{
my
(
$self
,
$url
) =
@_
;
return
decode_json
$ua
->post(
$url
,
$self
->{post_message} )->decoded_content();
}
sub
TRACE {}
1;
=pod
=head1 TODO
=over 4
=item * Add comprehensive unit tests to module distribution
=item * Add client error handling
=item * Fix any bugs that anybody reports
=item * Write better documentation. Always
write
better documentation
=back
=head1 SEE ALSO
=head1 VERSION
$Id
: API.pm,v 0.1.0 2014/06/08 09:08:00 CRYPTOGRA Exp $
=head1 AUTHOR
Michael W. Renz, C<< <cryptographrix+cpan at gmail.com> >>