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

NAME

WebService::Pixabay - Perl 5 interface to Pixabay API.

VERSION

version 2.1.0

SYNOPSIS

        use strict;
        use warnings;

        use WebService::Pixabay;
    use Data::Dumper 'Dumper';
        
        my $pix = WebService::Pixabay->new(api_key => 'secret');
        
        # default searches
        my $img1 = $pix->image_search;
        my $vid1 = $pix->video_search;
        
        # print JSON structure using Data::Dumper's 'Dumper'
    print Dumper($img1) . "\n";
    print Dumper($vid1) . "\n";
        
        ###################################################
        # The parameters of the method have the same name #
        # and default values as in Pixabay API docs       #
        ###################################################

        # example custom image search and printing
        my $cust_img = $pix->image_search(
                q => 'cats dog',
                lang => 'es',
                response_group => 'high_resolution',
                image_type => 'illustration',
                category => 'animals',
                safesearch => 'true',
                order => 'latest',
                page => 2,
                per_page => 5,
                pretty => 'true'
        );

    print Dumper($cust_img) . "\n";

        # -or with video_search-

        # example custom video search and printing
        my $cust_vid = $pix->video_search(
                q => 'tree',
                lang => 'en',
                pretty => 'false',
                page => 3,
                order => 'popular'
        );

    print Dumper($cust_vid) . "\n";

        # Handling specific hashes and arrays of values from the image_search JSON
        # example retrieving webformatURL from each arrays
        my @urls = undef;
        
        foreach my $url (@{$cust_img->{hits}}) {

                # now has link of photo urls (non-preview photos)
                push(@urls, $url->{webformatURL});              
        }
        
        print $urls[3] . "\n"; # image URL in the fourth row

        # Getting a specific single hash or array value from video_search JSON
        print $cust_vid->{hits}[0]{medium}{url} . "\n";

SEE ALSO

Pixabay API documentations

Moo

Function::Parameters

Test::More

WebService::Client

LWP::Online

Data::Printer

AUTHOR

faraco <skelic3@gmail.com>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2017 by faraco.

This is free software, licensed under:

  The GNU General Public License, Version 3, June 2007