has
rest_endpoint
=> (
is
=>
'ro'
,
isa
=>
'Str'
);
sub
search {
my
(
$self
,
$parameters
) =
@_
;
my
$response
= makeRequest(
$self
->{rest_endpoint},
"/Blast/search"
,
$parameters
,
"POST"
);
return
Report_HTML_DB::Models::Services::BaseResponse->thaw(
$response
);
}
sub
fancy {
my
(
$self
,
$blast
) =
@_
;
my
$response
= makeRequest(
$self
->{rest_endpoint},
"/Blast/fancy"
,
\%{ {
blast
=>
$blast
} },
"POST"
);
return
Report_HTML_DB::Models::Services::BaseResponse->thaw(
$response
);
}
sub
makeRequest {
my
(
$rest_endpoint
,
$action
,
$parameters
,
$method
) =
@_
;
my
$user_agent
= LWP::UserAgent->new;
my
$url
=
""
;
if
(
$method
eq
"GET"
) {
$url
=
$rest_endpoint
.
$action
.
"?"
. stringifyParameters(
$parameters
);
my
$request
= HTTP::Request->new(
GET
=>
$url
);
$request
->header(
'Content-Type'
=>
'application/json'
);
my
$response
=
$user_agent
->request(
$request
);
return
$response
->content;
}
elsif
(
$method
eq
"POST"
) {
$url
=
$rest_endpoint
.
$action
;
my
$request
= HTTP::Request->new(
"POST"
,
$url
);
$request
->content( encode_json(
$parameters
) );
$request
->header(
'Content-Type'
=>
'application/json'
,
'Accept'
=>
'application/json'
);
my
$response
=
$user_agent
->request(
$request
);
return
$response
->content;
}
}
sub
stringifyParameters {
my
(
$parameters
) =
@_
;
my
$result
=
""
;
foreach
my
$key
(
keys
%{
$parameters
} ) {
$result
.=
"$key="
.
$parameters
->{
$key
} .
"&"
;
}
chop
(
$result
);
return
$result
;
}
1;