This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 940
Hearthstone Spice debut #1452
Merged
Merged
Hearthstone Spice debut #1452
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
95aaef0
Creation of the Hearthstone Spice
Akryum 92f0906
Fixed attribution github link in metadata
Akryum 52c2c8a
Added imageproxy, conditionnals and more comments (pull request feedb…
Akryum 403eab6
rebade
Akryum 3120a65
Fixed .travis.yml
Akryum b66f33d
Fixed css
Akryum 00f0909
Trailing comma in Hearthstone.t
Akryum c550d66
Now using info template, added trigger keyword blacklist
Akryum 6830586
Fixed .travis.yml again
Akryum a43aff9
Fixed Collectible field
Akryum 5ed7e14
Fixed icons vertical align
Akryum 91e5a34
Added regex guard
Akryum a5e510a
image_url is now optionnal; added more reg ex comments; changed sourc…
Akryum 08eb3ff
Caching is now 4 days.
Akryum 96e6758
Fixed comment
Akryum cde137a
Styling reworked and stats moved to info box.
Akryum a964a4c
Added css class 'tx-clr--lt' on flavor text.
Akryum 2802f56
Flavor text moved to subtitle property
Akryum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,51 @@ | ||
package DDG::Spice::Hearthstone; | ||
# ABSTRACT: Retrieve the card infos from Hearthstone game. | ||
|
||
use DDG::Spice; | ||
|
||
# Caching | ||
spice is_cached => 1; | ||
spice proxy_cache_valid => "200 4d"; | ||
|
||
# Metadata | ||
name "Hearthstone Card Search"; | ||
source "Bytevortex (Gamepedia Proxy)"; | ||
icon_url "http://eu.battle.net/hearthstone/static/images/icons/favicon.ico"; | ||
description "Get a preview of any Hearthstone card."; | ||
primary_example_queries "hearthstone leeroy jenkins", "hearthstone leeroy", "leeroy hearthstone", "hearthstone mirror"; | ||
category "entertainment"; | ||
topics "gaming"; | ||
code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Hearthstone.pm"; | ||
attribution github => ["https://github.com/Akryum", "Akryum"], | ||
twitter => "Akryum"; | ||
|
||
# Triggers | ||
triggers startend => "hearthstone"; | ||
|
||
# Target URL | ||
spice to => 'http://bytevortex.net/hearthstone.php?search=$1'; | ||
|
||
# JS Callback | ||
spice wrap_jsonp_callback => 1; | ||
|
||
# Keyword blacklist | ||
my $keyword_guard = qr/game|instruction|stoves|warcraft|deck|forum|wiki|reddit/; | ||
|
||
# Handle statement | ||
handle remainder => sub { | ||
|
||
# Guard against "no answer" | ||
return unless $_; | ||
|
||
# Keyword Blacklist | ||
return if (/$keyword_guard/); | ||
|
||
# Regex guard | ||
# Allows string similar to any Hearthstone card name: multiple words separated by spaces, commas or dashes. | ||
# The card name may also have dots, double dots, slashes or an exclamation mark (Those Blizzard devs). | ||
return $_ if (/^([a-z0-9':!\/,.-]+\s*)+$/i); | ||
|
||
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,7 @@ | ||
.zci--hearthstone b { | ||
font-weight: normal; | ||
} | ||
|
||
.zci--hearthstone i { | ||
font-style: normal; | ||
} |
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,5 @@ | ||
<div class="zci--hearthstone"> | ||
{{#if card_description}} | ||
<div class="zci--hearthstone--description">{{{card_description}}}</div> | ||
{{/if}} | ||
</div> |
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,107 @@ | ||
(function(env) { | ||
"use strict"; | ||
|
||
env.ddg_spice_hearthstone = function(api_result) { | ||
|
||
// Validate the response | ||
if(!api_result || api_result.error || !api_result.Has_name || !api_result.page) { | ||
return Spice.failed('hearthstone'); | ||
} | ||
|
||
// Infobox Labels | ||
var infoboxItems = { | ||
Has_card_type: "Type", | ||
Has_class: "Playable by", | ||
Has_mana_cost: { | ||
label: "Cost", | ||
icon: "http://hydra-media.cursecdn.com/hearthstone.gamepedia.com/8/8b/Mana_icon.png" | ||
}, | ||
Has_attack: { | ||
label: "Attack", | ||
icon: "http://hydra-media.cursecdn.com/hearthstone.gamepedia.com/f/fe/Attack_icon.png" | ||
}, | ||
Has_health: { | ||
label: "Health", | ||
icon: "http://hydra-media.cursecdn.com/hearthstone.gamepedia.com/1/17/Health_icon.png" | ||
}, | ||
Has_rarity: "Rarity", | ||
Is_part_of_set: "Set", | ||
Is_collectible: "Collectible" | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its it possible the API won't return one of any of the values above? |
||
|
||
// Render the response | ||
Spice.add({ | ||
id: "hearthstone", | ||
name: "Hearthstone", | ||
data: api_result, | ||
meta: { | ||
sourceName: "Hearthstone Gamepedia Wiki", | ||
sourceUrl: "http://hearthstone.gamepedia.com/" + api_result.page | ||
}, | ||
normalize: function(item) { | ||
|
||
// Infobox Heading | ||
var infoboxData = [{ | ||
heading: 'Card Details' | ||
}]; | ||
|
||
// Is collectible | ||
api_result.Is_collectible = (api_result.Is_collectible === "t" ? "Yes" : "No"); | ||
|
||
// Hero | ||
if(api_result.Has_class === "Any") { | ||
api_result.Has_class = "Any Hero"; | ||
} | ||
|
||
// InfoBox data | ||
$.each(infoboxItems, function(key, data) { | ||
var label, | ||
value; | ||
if(api_result[key]) { | ||
value = api_result[key]; | ||
if(data.label) { | ||
label = data.label; | ||
} else { | ||
label = data; | ||
} | ||
infoboxData.push({ | ||
label: label, | ||
value: value | ||
}); | ||
} | ||
}); | ||
|
||
// Normalized data | ||
var card = { | ||
title: item.Has_name, | ||
url: "http://hearthstone.gamepedia.com/" + item.page, | ||
infoboxData: infoboxData | ||
}; | ||
|
||
// Optionnal fields | ||
// Image | ||
if(item.image_url) { | ||
card.image = item.image_url; | ||
} | ||
|
||
// Description | ||
if(item.Has_description) { | ||
card.card_description = item.Has_description; | ||
} | ||
|
||
// Flavor text | ||
if(item.Has_flavor_text) { | ||
card.subtitle = item.Has_flavor_text; | ||
} | ||
|
||
return card; | ||
}, | ||
templates: { | ||
group: 'info', | ||
options: { | ||
content: Spice.hearthstone.hearthstone | ||
} | ||
} | ||
}); | ||
}; | ||
}(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,40 @@ | ||
#!/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::Hearthstone)], | ||
'hearthstone leeroy jenkins' => test_spice( | ||
'/js/spice/hearthstone/leeroy%20jenkins', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::Hearthstone' | ||
), | ||
'hearthstone leeroy' => test_spice( | ||
'/js/spice/hearthstone/leeroy', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::Hearthstone' | ||
), | ||
'leeroy hearthstone' => test_spice( | ||
'/js/spice/hearthstone/leeroy', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::Hearthstone' | ||
), | ||
'hearthstone mirror' => test_spice( | ||
'/js/spice/hearthstone/mirror', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::Hearthstone' | ||
), | ||
'hearthstone' => undef, | ||
'hearthstone heroes of warcraft' => undef, | ||
'hearthstone wood stoves' => undef, | ||
'hearthstone mage deck' => undef, | ||
'hearthstone tide_caller' => undef, | ||
'hearthstone tidecaller $' => undef | ||
); | ||
|
||
done_testing; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is it guarding against? It's a bit hard to tell from the regexp--could you add a comment that explains it. :)