Document-eSign-Docusign

 view release on metacpan or  search on metacpan

lib/Document/eSign/Docusign/sendRequest.pm  view on Meta::CPAN

EOF
        if ( defined $params->{documents} ) {
            for my $doc ( @{ $params->{documents} } ) {
                open( my $fh, "<", $doc->{name} )
                  or
                  croak( "Unable to open file: " . $doc->{name} . " :: " . $! );
                $doc->{name} =~ s/^.*(\\|\/)//;
                local $/ = '';
                my $pdf = <$fh>;
                $multipart .= <<"EOF";
--snipsnip
Content-Type: application/pdf
Content-Disposition: file; filename="$doc->{name}"; documentid="$doc->{documentId}"

$pdf
EOF
                close $fh;
            }
            $multipart .= <<"EOF";
--snipsnip--

EOF
        }

    }

    if ( $method eq 'GET' ) {

        if ( defined $query_params ) {
            my $uri_with_params = URI->new($uri);
            $uri_with_params->query_form($query_params);
            $response = $ua->get($uri_with_params);
        }
        else {
            $response = $ua->get($uri);
        }

    }
    elsif ( $method eq 'POST' ) {

        $response =
          $ua->post( $uri, Content => $multipart || $jsonparams || $params );

    }
    elsif ( $method eq 'PUT' ) {

        $response =
          $ua->put( $uri, Content => $multipart || $jsonparams || $params );

    }
    elsif ( $method eq 'DELETE' ) {
        $response = $ua->delete($uri);
    }
    else {
        return { error =>
              "An undefined method was used, only use GET, POST, PUT, or DELETE"
        };
    }

    if ( $method =~ /GET|POST/ && $response->is_success ) {
        return $json->decode( $response->decoded_content );
    }
    elsif ( $response->is_success )
    {    #Calls that simply do something and are not expected to return data.
        return { Status => $response->status_line };
    }

    return { error => $response->status_line };

}

1;



( run in 1.465 second using v1.01-cache-2.11-cpan-ceb78f64989 )