Last active
February 16, 2017 11:13
-
-
Save moollaza/0f935d1b11eb66f1f2e8 to your computer and use it in GitHub Desktop.
Revisions
-
moollaza revised this gist
Nov 30, 2015 . No changes.There are no files selected for viewing
-
moollaza revised this gist
Nov 25, 2015 . No changes.There are no files selected for viewing
-
moollaza created this gist
Nov 25, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ package DDG::Spice::RandomPerson; use DDG::Spice; spice is_cached => 0; spice proxy_cache_valid => "418 1d"; spice wrap_jsonp_callback => 1; spice to => 'http://api.randomuser.me/'; triggers start => 'random person'; # spice to => 'http://api.randomuser.me/?gender=$1'; # triggers start => 'random'; # sub random_gender { # my @genders = ("male", "female"); # my $random_gender = $genders[rand @genders]; # return $random_gender; # } handle remainder_lc => sub { return "" unless $_; return; # my $remainder = $_; # my $gender; # # srand(); # $gender = $1 if $remainder =~ m/(female|male)/; # $gender = random_gender() if $remainder =~ m/person|user/; # return unless $gender; # return $gender; }; 1; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ #!/usr/bin/env perl use strict; use warnings; use Test::More; use DDG::Test::Spice; spice is_cached => 1; ddg_spice_test( [qw( DDG::Spice::RandomPerson)], 'random person' => test_spice( '/js/spice/random_person/', call_type => 'include', caller => 'DDG::Spice::RandomPerson', is_cached => 0 ), 'random people' => undef, 'random' => undef ); done_testing; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ (function (env) { "use strict"; env.ddg_spice_random_person = function(api_result){ if (!api_result) { return Spice.failed('random_person'); } Spice.add({ id: "random_person", name: "Answer", data: api_result.results, meta: { sourceName: "RandomUser", sourceUrl: 'http://randomuser.me' }, normalize: function(item) { return { title: item.user.name.first + " " + item.user.name.last, subtitle: item.user.email, image: item.user.picture.medium, record_data: item.user, record_keys: [ "username", "password", "dob", "phone" ] }; }, templates: { group: 'info', options: { content: 'record', moreAt: true } } }); }; }(this));