Permalink
Browse files

Merge pull request #62 from duckduckgo/jag/web/missing-api-keys

DuckPAN/Web: Default to DDG's endpoint if API key is missing.
  • Loading branch information...
2 parents c02cedc + 5a3c1fc commit c9b58e0d624b338db8157c09b56ba7be44aa258b @moollaza moollaza committed Mar 5, 2014
Showing with 9 additions and 0 deletions.
  1. +9 −0 lib/App/DuckPAN/Web.pm
View
@@ -128,7 +128,16 @@ sub request {
}
# Make sure we replace "${dollar}" with "$".
$to =~ s/\$\{dollar\}/\$/g;
+
+ # Check if environment variables (most likely the API key) is missing.
+ # If it is missing, switch to the DDG endpoint.
+ if(defined $rewrite->missing_envs) {
+ $to = 'https://duckduckgo.com' . $request->request_uri;
+ # Display the URL that we used.
+ print "\nAPI key not found. Using DuckDuckGo's endpoint:\n";
+ }
p($to);
+
my $res = $self->ua->request(HTTP::Request->new(
GET => $to,
[ $rewrite->accept_header ? ("Accept", $rewrite->accept_header) : () ]

0 comments on commit c9b58e0

Please sign in to comment.