aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-06-17 19:19:09 +0530
committerAndinus <andinus@nand.sh>2020-06-17 19:19:09 +0530
commitf3d1bc5f9d86300c42d6a57a9f60bd508bdf9bb4 (patch)
treefe285cca7e64005be78b591969f932986fad2d78
parent335c080d974462c3795c5da0292157d7d4a72188 (diff)
downloadcrux-f3d1bc5f9d86300c42d6a57a9f60bd508bdf9bb4.tar.gz
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.
-rw-r--r--lib/UnsplashSource.pm16
1 files 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);
}