SYNOPSIS

my $search = WebService::OurWorldInData::Search->new();

my $gdp = $search->query('gdp');
for my $chart ( $gdp->{results}->@* ) {
    say $chart->{title};
}

my @urls = $search->extract_urls($gdp);

DESCRIPTION

Queries the Our World in Data Search api for charts or pages. The Search object can be created with the following attributes:

q - query text used when the query method is called with no arguments
type - either charts (default) or pages
page - page number for pagination
hitsPerPage - number of results per page
countries - (charts only) filter results based on countries (separated by ~)
topics - (charts only) topic name for filtering charts
requireAllCountries - boolean (only if countries provided)

Refine search query as described by the OWiD Search API. eg.

my $nato_fr = WebService::OurWorldInData::Search->new(
                countries => 'Canada~France~Belgium',
                );
$nato_fr->hitsPerPage(50);
$nato_fr->require_all_countries(1);

extract_urls

Provided as a utility function, it takes the response as an argument and returns a list of urls extracted from the results.

NOTES

I haven't deconstructed the response from the Search endpoint. Your results are a list of hashrefs in the data structure. Let me know if you'd like a smoother api.

TODO

Add a next_page function to continue fetching results. This may need to store current page in a SearchResponse object.

SEE ALSO