Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
Creating WordOfTheDay spice.
Browse files Browse the repository at this point in the history
 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
tyleryasaka committed Jan 28, 2016
1 parent 01383f2 commit 67c812b
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
45 changes: 45 additions & 0 deletions lib/DDG/Spice/WordOfTheDay.pm
@@ -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;
30 changes: 30 additions & 0 deletions share/spice/word_of_the_day/word_of_the_day.js
@@ -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));
41 changes: 41 additions & 0 deletions t/WordOfTheDay.t
@@ -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;

0 comments on commit 67c812b

Please sign in to comment.