The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Cookbook

Some examples of how to use the client.

Recipies

Authenticate Yourself

Make sure you've enabled the Developer flag in your Wing user account and requested an API key. Then you can authenticate like this:

my $session = $wing->post('session', {
   username    => 'me',
   password    => '123qwe',
   api_key_id  => 'abcdefghijklmnopqrztuz',
});

Checking for Success

All Wing::Client requests will throw an Ouch exception in the case of a failed lookup, or if the remote Wing server returned an error code.

Anything can fail

Since any request can return an exception, you'll need to eval all requests.

my $session = eval {
    $wing->post('session', {
        username    => 'me',
        password    => '123qwe',
        api_key_id  => 'abcdefghijklmnopqrztuz',
    });
};

Trapping and processing

You can use a combination of Ouch's trapping mechanisms to handle errors

if (kiss 440) {
    say "Wrong username and password combination";
    exit 1;
}
else (hug) { #Catch all other errors
    say "Pigs are flying someplace, check the server-side code";
    exit 2;
}
else {
   say "It worked";
}
#Continue knowing that $session has valid data in it.