View | Details | Raw Unified | Return to bug 37526
Collapse All | Expand All

(-)a/Koha/ERM/EUsage/UsageDataProvider.pm (-10 / +27 lines)
Lines 174-184 sub harvest_sushi { Link Here
174
    $self->{report_type} = $args->{report_type};
174
    $self->{report_type} = $args->{report_type};
175
    $self->{begin_date}  = $args->{begin_date};
175
    $self->{begin_date}  = $args->{begin_date};
176
    $self->{end_date}    = $args->{end_date};
176
    $self->{end_date}    = $args->{end_date};
177
    my $url     = $self->_build_url_query;
177
    my $url      = $self->_build_url_query;
178
    my $request = HTTP::Request->new( 'GET' => $url );
178
    my $response = _handle_sushi_request($url);
179
    my $ua      = LWP::UserAgent->new;
180
    $ua->agent( 'Koha/' . Koha::version() );
181
    my $response = $ua->simple_request($request);
182
179
183
    my $result   = decode_json( $response->decoded_content );
180
    my $result   = decode_json( $response->decoded_content );
184
181
Lines 278-287 sub test_connection { Link Here
278
    $url .= '&requestor_id=' . $self->requestor_id if $self->requestor_id;
275
    $url .= '&requestor_id=' . $self->requestor_id if $self->requestor_id;
279
    $url .= '&api_key=' . $self->api_key           if $self->api_key;
276
    $url .= '&api_key=' . $self->api_key           if $self->api_key;
280
277
281
    my $request = HTTP::Request->new( 'GET' => $url );
278
    my $response = _handle_sushi_request($url);
282
    my $ua      = LWP::UserAgent->new;
283
    $ua->agent( 'Koha/' . Koha::version() );
284
    my $response = $ua->simple_request($request);
285
279
286
    if ( $response->{_rc} >= 400 ) {
280
    if ( $response->{_rc} >= 400 ) {
287
        my $message = $response->{_msg};
281
        my $message = $response->{_msg};
Lines 525-530 sub _counter_file_size_too_large { Link Here
525
    return 0;
519
    return 0;
526
}
520
}
527
521
522
=head3 _handle_sushi_response
523
524
Creates and sends the request based on a provided url
525
Also handles any redirects
526
527
=cut
528
529
sub _handle_sushi_request {
530
    my ($url) = @_;
531
532
    my $request = HTTP::Request->new( 'GET' => $url );
533
    my $ua      = LWP::UserAgent->new;
534
    $ua->agent( 'Koha/' . Koha::version() );
535
    my $response = $ua->simple_request($request);
536
537
    if ( $response->is_redirect ) {
538
        my $redirect_url = $response->header('Location');
539
        $redirect_url = URI->new_abs( $redirect_url, $url );
540
        $response     = $ua->get($redirect_url);
541
    }
542
543
    return $response;
544
}
545
528
=head3 _type
546
=head3 _type
529
547
530
=cut
548
=cut
531
- 

Return to bug 37526