about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-06-30 12:05:05 +0530
committerAndinus <andinus@nand.sh>2020-06-30 12:05:05 +0530
commit420a084a2d6d28b4ece2f369c881965fe5ea89b8 (patch)
tree83094c78ff3a03cc6a4fde83a5d16ebfe07027f6
parente44c733de809c533fc104d302d71949942498d70 (diff)
downloadcrux-420a084a2d6d28b4ece2f369c881965fe5ea89b8.tar.gz
use URI to build $url
-rw-r--r--lib/UnsplashSource.pm31
1 files 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);
 }