refactor login logout calls
[sgn.git] / lib / CXGN / BrAPI.pm
blob24b4c5aec7c2020c1e9520c1b24360b477c8a7df
1 package CXGN::BrAPI;
3 use Moose;
4 use Data::Dumper;
5 use CXGN::BrAPI::v1::Authentication;
6 use CXGN::BrAPI::v1::Calls;
8 has 'bcs_schema' => (
9 isa => 'Bio::Chado::Schema',
10 is => 'rw',
11 required => 1,
14 has 'metadata_schema' => (
15 isa => 'CXGN::Metadata::Schema',
16 is => 'rw',
17 required => 1,
20 has 'phenome_schema' => (
21 isa => 'CXGN::Phenome::Schema',
22 is => 'rw',
23 required => 1,
26 has 'version' => (
27 isa => 'Str',
28 is => 'rw',
29 required => 1,
32 has 'page_size' => (
33 isa => 'Int',
34 is => 'rw',
35 required => 1,
38 has 'page' => (
39 isa => 'Int',
40 is => 'rw',
41 required => 1,
44 has 'status' => (
45 isa => 'ArrayRef[Maybe[HashRef]]',
46 is => 'rw',
47 required => 1,
50 sub logout {
51 my $self = shift;
52 my $status = $self->status;
53 my $brapi_package = 'CXGN::BrAPI::'.$self->version().'::Authentication';
54 push @$status, { 'info' => "Loading $brapi_package" };
55 my $brapi_auth = $brapi_package->new({
56 bcs_schema => $self->bcs_schema,
57 status => $status
58 });
59 my $brapi_package_result = $brapi_auth->logout();
60 return $brapi_package_result;
63 sub login {
64 my $self = shift;
65 my $grant_type = shift;
66 my $password = shift;
67 my $username = shift;
68 my $client_id = shift;
69 my $status = $self->status;
71 my $brapi_package = 'CXGN::BrAPI::'.$self->version().'::Authentication';
72 push @$status, { 'info' => "Loading $brapi_package" };
73 my $brapi_auth = $brapi_package->new({
74 bcs_schema => $self->bcs_schema,
75 status => $status
76 });
77 my $brapi_package_result = $brapi_auth->login($grant_type, $password, $username, $client_id);
78 return $brapi_package_result;
81 sub calls {
82 my $self = shift;
83 my $datatype = shift;
84 my $status = $self->status;
86 my $brapi_package = 'CXGN::BrAPI::'.$self->version().'::Calls';
87 push @$status, { 'info' => "Loading $brapi_package" };
88 my $brapi_calls = $brapi_package->new({
89 status => $self->status
90 });
91 my $brapi_package_result = $brapi_calls->calls($datatype, $self->page_size, $self->page);
92 return $brapi_package_result;