JSONValidator: Init v1

master
sdua 2016-07-21 21:31:53 +00:00
parent 6e4d73b847
commit 3c4ad30c4d
2 changed files with 22 additions and 40 deletions

View File

@ -1,8 +1,5 @@
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
# ABSTRACT: An Interactive JSON Validation Tool
use DDG::Goodie;
use strict;
@ -10,42 +7,30 @@ 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';
triggers any => 'json validation', 'json validator';
# 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',
return '',
structured_answer => {
id => "json_validator",
data => {
title => 'My Instant Answer Title',
subtitle => 'My Subtitle',
# image => 'http://website.com/image.png',
title => 'JSON Validator',
subtitle => 'Enter your JSON below and click on the button to check if it\'s valid'
},
templates => {
group => 'text',
# options => {
#
# }
item => 0,
options => {
content => 'DDH.json_validator.content'
}
}
};
};

View File

@ -14,20 +14,22 @@ zci is_cached => 1;
sub build_structured_answer {
my @test_params = @_;
return 'plain text response',
return '',
structured_answer => {
id => "json_validator",
data => {
title => 'My Instant Answer Title',
subtitle => 'My Subtitle',
# image => 'http://website.com/image.png',
title => 'JSON Validator',
subtitle => 'Enter your JSON below and click on the button to check if it\'s valid'
},
templates => {
group => 'text',
# options => {
#
# }
item => 0,
options => {
content => 'DDH.json_validator.content'
}
}
};
}
@ -37,13 +39,8 @@ 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,
'json validator' => build_test(),
);
done_testing;