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

Commit

Permalink
Merge branch 'resteamspecial' of https://github.com/killerfish/zerocl…
Browse files Browse the repository at this point in the history
…ickinfo-spice into jag/steam-special
  • Loading branch information
jagtalon committed Sep 26, 2014
2 parents beb4114 + 8fcb32a commit 3d459f3
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/DDG/Spice/Steam/ListSpecials.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package DDG::Spice::Steam::ListSpecials;
# ABSTRACT: Fetch the Steam Special Details

use DDG::Spice;

attribution github => ["https://github.com/killerfish", "Usman Raza"],
twitter => ["https://twitter.com/f1shie", "Usman Raza"];

spice to => 'http://store.steampowered.com/api/appdetails?appids=$1';

triggers any => "///***never trigger***///";

spice wrap_jsonp_callback => 1;

handle remainder => sub {
return $_ if $_;
return;
};

1;
25 changes: 25 additions & 0 deletions lib/DDG/Spice/Steam/Specials.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package DDG::Spice::Steam::Specials;
# ABSTRACT: Fetch Steam Specials at Steam store.

use DDG::Spice;

name "steam";
source "http://store.steampowered.com";
description "Get featured games on sale at Steam store";
primary_example_queries "steam specials";
category "special";
topics "gaming","entertainment";
icon_url "/i/store.steampowered.com.ico";
code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Steam/Specials.pm";
attribution github => ["https://github.com/killerfish", "Usman Raza"],
twitter => ["https://twitter.com/f1shie", "Usman Raza"];

triggers startend => "steam special", "steam specials", "steam store", "steam offers", "steam offer";
spice to => 'http://store.steampowered.com/api/featuredcategories';
spice proxy_cache_valid => "200 60m";
spice wrap_jsonp_callback => 1;

handle remainder => sub {
return '';
};
1;
22 changes: 22 additions & 0 deletions share/spice/steam/specials/buy.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Originial price: {{original_price}} <br>
Savings: {{discount}} <br>
{{#if rating}}
Metascore: {{rating}} <br>
{{/if}}
{{#if genre}}
Genre: {{genre}}
{{/if}} <br>
Supported Platforms:
{{#if platforms.windows}}
Windows
{{/if}}
{{#if platforms.mac}}
<span class="detail__separator"> | </span> Mac
{{/if}}
{{#if platforms.linux}}
<span class="detail__separator"> | </span> Linux
{{/if}}
<br>
<a href="{{url}}" class="btn btn--primary">
More at Steam
</a>
16 changes: 16 additions & 0 deletions share/spice/steam/specials/steam_specials.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.zci--specials .tile__media__img {
height: 100%;
}
.zci--specials .tile__media .tile__media__img {
max-height: 100%;
}
.zci--specials .tile__media {
height: 9.3em;
}
.zci--specials p {
padding-top: 0.25em;
padding-bottom: 0.25em;
}
.zci--specials .btn.btn--primary {
margin-top: 1em;
}
111 changes: 111 additions & 0 deletions share/spice/steam/specials/steam_specials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
(function(env) {
"use strict";

// Prevent jQuery from appending "_={timestamp}" in our url when we use $.getScript.
// If cache was set to false, it would be calling /js/spice/steam/list_specials/hello?_=12345
// and that's something that we don't want.
$.ajaxSetup({ cache: true });
var queryexec;

// Fetch our json and pass to getScript
env.ddg_spice_steam_specials = function(api_result) {
if(!api_result) {
return Spice.failed('specials');
}

var idarray = api_result.specials.items;
queryexec = encodeURIComponent($.map(idarray, function(elem) {
return elem.id;
}).join(","));
$.getScript("/js/spice/steam/list_specials/" + queryexec);
};

env.ddg_spice_steam_list_specials = function(api_result) {
if (!api_result) {
return Spice.failed('specials');
}

var query = decodeURIComponent(queryexec);

// Extract our query
var gameids = query.split(",");
var results = [];
var j = 0;
var genre = [];

// Organize data to display
for(var i = 0; i < gameids.length; i++) {
if(api_result[gameids[i]].success == true) { //successfully fetched information on game

results.push(api_result[gameids[i]].data.price_overview);
results[j].url = "http://store.steampowered.com/app/"+api_result[gameids[i]].data.steam_appid;
results[j].dev = api_result[gameids[i]].data.developers[0];
results[j].name = api_result[gameids[i]].data.name;
results[j].image = api_result[gameids[i]].data.header_image;

if(api_result[gameids[i]].data.metacritic) {
results[j].metacritic = api_result[gameids[i]].data.metacritic.score;
}

if(api_result[gameids[i]].data.genres) {
$.each(api_result[gameids[i]].data.genres, function(index, value) {
genre.push(value.description);
});
results[j].genre = genre.join(", ");
}

results[j].platforms = api_result[gameids[i]].data.platforms;
for (var platform in results[j].platforms) {
if(results[j].platforms[platform] == "No") {
delete results[j].platforms[platform];
}
}

//results[j].ss = (api_result[gameids[i]].data.screenshots).slice(0,4); //screenshots maybe used in future
genre = [];
j++;
}
}


// Return if not able to retrieve information for any game
if(!results.length) {
return Spice.failed('specials');
}

Spice.add({
id: "specials",
name: "Steam Specials",
data: results,
meta: {
itemType: "Specials",
sourceUrl: 'http://store.steampowered.com/search/?specials=1',
sourceName: 'Steam'
},
normalize: function(item) {
console.log(item.dev);
return {
image: item.image,
img: item.image,
heading: item.name,
url: item.url,
price: "USD $" + (item.final/100),
brand: item.dev,
rating: item.metacritic,
original_price: "USD $" + (item.initial/100),
discount: item.discount_percent + "%"
};
},
templates: {
group: 'products',
options: {
buy: Spice.steam_specials.buy,
rating: false
}
},
onShow: function() {
Spice.getDOM('specials').find(".tile__body").hide();
}
});
};
}(this));
28 changes: 28 additions & 0 deletions t/Steam.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;
use DDG::Test::Spice;

ddg_spice_test(
[qw(
DDG::Spice::Steam::Specials
)],
'steam specials' => test_spice(
"/js/spice/steam/specials/",
call_type => 'include',
caller => 'DDG::Spice::Steam::Specials'
),
'steam offers' => test_spice(
"/js/spice/steam/specials/",
caller => 'DDG::Spice::Steam::Specials'
),

# Do not trigger on these queries
'steam iron' => undef,
'steam press' => undef,
);

done_testing;

0 comments on commit 3d459f3

Please sign in to comment.