Norsk Orientering

Innlegg i Generelt > Access eventor via Perl

  • Thierry Matthey
    mandag 11 april 2011 klokken 23.02

    use LWP::UserAgent;
    use URI::https;
    use LWP::Protocol::https;
    use LWP::Authen::Basic;

    sub eventorApiCallGet2
    {
        my ( $url , $apikey, $username, $password) = @_;
        my $ua = LWP::UserAgent->new;
        if (defined($apikey) && $apikey ne "")
        {
            $ua->default_header(ApiKey =>  $apikey);
        }
        else
        {
            $ua->default_header(Username =>  $username);
            $ua->default_header(Password =>  $password);
        }
        $ua->agent("Perlmonky");
        $ua->timeout(10);
        my $u = "https://".EVENTOR_API_BASE_URL . $url;
        my $res = $ua->get($u );

        if ( !$res->is_success() )
        {
            return ("", $res->status_line);
        }
        return ($res->content, "");
    }

    sub eventorApiCallPost
    {
        my ( $url , $apikey, $username, $password, $data) = @_;
        my $ua = LWP::UserAgent->new;
        $ua->agent("Perlmonky");
        $ua->timeout(10);
        my $u = "https://".EVENTOR_API_BASE_URL . $url;
        my $res;
        if (defined($apikey) && $apikey ne "")
        {
            $res = $ua->post($u, ApiKey =>  $apikey, Content => $data);
        }
        else
        {
            $res = $ua->post($u, Username =>  $username, Password =>  $password, Content => $data);
        }

        if ( !$res->is_success() )
        {
            return ($res->status_line);
        }
        return ("");
    }

  • Thierry Matthey
    onsdag 30 mars 2011 klokken 16.21

    sub eventorApiCall
    {
        my ( $url ) = @_;
        my $ua = LWP::UserAgent->new;
        $ua->default_header(ApiKey => EVENTOR_API_KEY);
        $ua->agent("Perlmonky");
        $ua->timeout(10);
        my $u = "https://".EVENTOR_API_BASE_URL . $url;
        my $res = $ua->get($u );

        if ( !$res->is_success() ) {
            return $res->status_line;
        }
        return $res->content;
    }

Annonser

IOF Eventor