From 420a084a2d6d28b4ece2f369c881965fe5ea89b8 Mon Sep 17 00:00:00 2001 From: Andinus Date: Tue, 30 Jun 2020 12:05:05 +0530 Subject: use URI to build $url --- lib/UnsplashSource.pm | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/UnsplashSource.pm b/lib/UnsplashSource.pm index 7704dc8..e4c26aa 100644 --- a/lib/UnsplashSource.pm +++ b/lib/UnsplashSource.pm @@ -58,9 +58,16 @@ sub random_search { sub user_random { my ( %options ) = @_; - my $url = "$api/user/$options{user}/"; - $url .= "likes/" if $options{user_likes}; - $url .= $options{resolution}; + + my $url = URI->new($api); + + my @segments; + push @segments, "user"; + push @segments, $options{user}; + push @segments, "likes" if $options{user_likes}; + push @segments, $options{resolution}; + $url->path_segments( @segments ); + return $http->head($url); } @@ -73,14 +80,20 @@ sub collection { sub fixed { my ( %options ) = @_; + croak "Cannot use daily & weekly together" if $options{daily} and $options{weekly}; - my $url = "$api/"; - $url .= "user/$options{user}/" if $options{user}; - $url .= "daily/" if $options{daily}; - $url .= "weekly/" if $options{weekly}; - $url .= "?"; - $url .= "$_," foreach ( @{$options{search}}); + + my $url = URI->new($api); + + my @segments; + push @segments, "user/$options{user}" if $options{user}; + push @segments, "daily" if $options{daily}; + push @segments, "weekly" if $options{weekly}; + $url->path_segments( @segments ); + + $url->query_keywords( \@{$options{search}} ); + return $http->head($url); } -- cgit 1.4.1-2-gfad0