This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to be committed: new file: lib/DDG/Spice/WordOfTheDay.pm new file: share/spice/word_of_the_day/word_of_the_day.js new file: t/WordOfTheDay.t
- Loading branch information
1 parent
01383f2
commit 67c812b
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package DDG::Spice::WordOfTheDay; | ||
|
||
# ABSTRACT: Show the word of the day, provided by the Wornik API | ||
|
||
use DDG::Spice; | ||
|
||
spice is_cached => 1; | ||
spice proxy_cache_valid => "200 1d"; | ||
|
||
spice wrap_jsonp_callback => 1; | ||
|
||
# for testing, run: DDG_SPICE_WORDNIK_APIKEY=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5 duckpan server | ||
spice to => 'http://api.wordnik.com/v4/words.json/wordOfTheDay?api_key={{ENV{DDG_SPICE_WORDNIK_APIKEY}}}'; | ||
|
||
spice alt_to => { | ||
audio => { | ||
to => 'http://api.wordnik.com/v4/word.json/$1/audio?limit=10&useCanonical=false&api_key={{ENV{DDG_SPICE_WORDNIK_APIKEY}}}&callback={{callback}}', | ||
proxy_cache_valid => '418 1d' | ||
}, | ||
hyphenation => { | ||
to => 'http://api.wordnik.com/v4/word.json/$1/hyphenation?includeRelated=true&api_key={{ENV{DDG_SPICE_WORDNIK_APIKEY}}}&callback={{callback}}' | ||
}, | ||
pronunciation => { | ||
to => 'http://api.wordnik.com/v4/word.json/$1/pronunciations?limit=1&useCanonical=false&api_key={{ENV{DDG_SPICE_WORDNIK_APIKEY}}}&callback={{callback}}' | ||
}, | ||
reference => { | ||
to => 'http://api.wordnik.com/v4/word.json/$1/definitions?includeRelated=true&includeTags=true&limit=3&api_key={{ENV{DDG_SPICE_WORDNIK_APIKEY}}}&callback={{callback}}', | ||
proxy_cache_valid => '200 30d' | ||
} | ||
}; | ||
|
||
triggers start => | ||
'word of the day', | ||
'dictionary word of the day', | ||
'word of the day dictionary', | ||
'what is the word of the day'; | ||
|
||
handle remainder => sub { | ||
|
||
return unless $_ eq ''; | ||
|
||
return $_; | ||
}; | ||
|
||
1; |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(function (env) { | ||
"use strict"; | ||
env.ddg_spice_word_of_the_day = function(api_result){ | ||
|
||
if (!api_result || api_result.error) { | ||
return Spice.failed('word_of_the_day'); | ||
} | ||
|
||
Spice.add({ | ||
id: "word_of_the_day", | ||
name: "Answer", | ||
data: api_result, | ||
meta: { | ||
sourceUrl: 'https://www.wordnik.com/word-of-the-day', | ||
sourceName: 'Wordnik' | ||
}, | ||
normalize: function(item) { | ||
return { | ||
url: 'https://www.wordnik.com/word-of-the-day', | ||
title: api_result.word, | ||
subtitle: api_result.definitions[0].partOfSpeech, | ||
description: api_result.definitions[0].text | ||
}; | ||
}, | ||
templates: { | ||
group: 'info' | ||
} | ||
}); | ||
}; | ||
}(this)); |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/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::WordOfTheDay)], | ||
'word of the day' => test_spice( | ||
'/js/spice/word_of_the_day/', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::WordOfTheDay' | ||
), | ||
'dictionary word of the day' => test_spice( | ||
'/js/spice/word_of_the_day/', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::WordOfTheDay' | ||
), | ||
'word of the day dictionary' => test_spice( | ||
'/js/spice/word_of_the_day/', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::WordOfTheDay' | ||
), | ||
'what is the word of the day' => test_spice( | ||
'/js/spice/word_of_the_day/', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::WordOfTheDay' | ||
), | ||
'' => undef, | ||
'words of the day' => undef, | ||
'what is the word day' => undef, | ||
'word of the day in french' => undef, | ||
'gimme a word of the day' => undef, | ||
'I feel so wordy today.' => undef, | ||
); | ||
|
||
done_testing; | ||
|