JSONValidator: Init

master
sdua 2016-07-21 20:47:14 +00:00
parent d8d27026db
commit 6e4d73b847
5 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,53 @@
package DDG::Goodie::JSONValidator;
# ABSTRACT: Write an abstract here
# Start at http://docs.duckduckhack.com/walkthroughs/calculation.html if
# you are new to instant answer development
use DDG::Goodie;
use strict;
use warnings;
zci answer_type => 'jsonvalidator';
# Caching - http://docs.duckduckhack.com/backend-reference/api-reference.html#caching`
zci is_cached => 1;
# Triggers - http://docs.duckduckhack.com/walkthroughs/calculation.html#triggers
triggers any => 'triggerword', 'trigger phrase';
# Handle statement
handle remainder => sub {
my $remainder = $_;
# Optional - Guard against no remainder
# I.E. the query is only 'triggerWord' or 'trigger phrase'
#
# return unless $remainder;
# Optional - Regular expression guard
# Use this approach to ensure the remainder matches a pattern
# I.E. it only contains letters, or numbers, or contains certain words
#
# return unless qr/^\w+|\d{5}$/;
return 'plain text response',
structured_answer => {
data => {
title => 'My Instant Answer Title',
subtitle => 'My Subtitle',
# image => 'http://website.com/image.png',
},
templates => {
group => 'text',
# options => {
#
# }
}
};
};
1;

View File

@ -0,0 +1,10 @@
/**
* Created with DuckDuckHack.
* User: sdua
* Date: 2016-07-21
* Time: 08:46 PM
* To change this template use Tools | Templates.
*/
define(function() {
return {};
});

View File

@ -0,0 +1,10 @@
/**
* Created with DuckDuckHack.
* User: sdua
* Date: 2016-07-21
* Time: 08:46 PM
* To change this template use Tools | Templates.
*/
define(function() {
return {};
});

49
t/JSONValidator.t Normal file
View File

@ -0,0 +1,49 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'jsonvalidator';
zci is_cached => 1;
# Build a structured answer that should match the response from the
# Perl file.
sub build_structured_answer {
my @test_params = @_;
return 'plain text response',
structured_answer => {
data => {
title => 'My Instant Answer Title',
subtitle => 'My Subtitle',
# image => 'http://website.com/image.png',
},
templates => {
group => 'text',
# options => {
#
# }
}
};
}
# Use this to build expected results for your tests.
sub build_test { test_zci(build_structured_answer(@_)) }
ddg_goodie_test(
[qw( DDG::Goodie::JSONValidator )],
# At a minimum, be sure to include tests for all:
# - primary_example_queries
# - secondary_example_queries
'example query' => build_test('query'),
# Try to include some examples of queries on which it might
# appear that your answer will trigger, but does not.
'bad example query' => undef,
);
done_testing;