From f3d1bc5f9d86300c42d6a57a9f60bd508bdf9bb4 Mon Sep 17 00:00:00 2001 From: Andinus Date: Wed, 17 Jun 2020 19:19:09 +0530 Subject: Use URI to encode the url for random_search I'll use this for everything eventually. Before this search terms like "rocky mountains" would break, also segments, query_keywords makes it easier. --- lib/UnsplashSource.pm | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/UnsplashSource.pm b/lib/UnsplashSource.pm index bce5c59..7704dc8 100644 --- a/lib/UnsplashSource.pm +++ b/lib/UnsplashSource.pm @@ -5,6 +5,7 @@ package UnsplashSource; use strict; use warnings; +use URI; use HTTP::Tiny; use Carp qw( croak carp ); @@ -42,11 +43,16 @@ sub get_random { sub random_search { my ( %options ) = @_; - my $url = "$api/"; - $url .= "featured/" if $options{featured}; - $url .= $options{resolution}; - $url .= "?"; - $url .= "$_," foreach ( @{$options{search}}); + + my $url = URI->new($api); + + my @segments; + push @segments, "featured" if $options{featured}; + push @segments, $options{resolution}; + $url->path_segments( @segments ); + + $url->query_keywords( \@{$options{search}} ); + return $http->head($url); } -- cgit