From 48dccca7faad149af777135ee4ce487e759fc750 Mon Sep 17 00:00:00 2001 From: PJ Hampton Date: Fri, 30 Jun 2017 01:53:16 +0100 Subject: [PATCH] Cryptocurrency: Swap out external endpoint for proxy endpoint. (#3350) * Swap out external endpoint for proxy endpoint. * Fix alto * Update the api call. --- lib/DDG/Spice/Cryptocurrency.pm | 8 ++++++++ share/spice/cryptocurrency/cryptocurrency.js | 10 ++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/DDG/Spice/Cryptocurrency.pm b/lib/DDG/Spice/Cryptocurrency.pm index f6f53a9019..34f24e072c 100644 --- a/lib/DDG/Spice/Cryptocurrency.pm +++ b/lib/DDG/Spice/Cryptocurrency.pm @@ -96,6 +96,14 @@ spice wrap_jsonp_callback => 1; spice is_cached => 0; spice proxy_cache_valid => "200 1m"; +spice alt_to => { + cryptonator => { + from => '([^/]+)/([^/]*)', + to => 'https://api.cryptonator.com/api/full/$1-$2', + wrap_jsonp_callback => 0, + } +}; + # This function converts things like "us dollars" to the standard "usd". sub getCode { my $input = shift; diff --git a/share/spice/cryptocurrency/cryptocurrency.js b/share/spice/cryptocurrency/cryptocurrency.js index 00e82ae7e9..d6700ad7fb 100644 --- a/share/spice/cryptocurrency/cryptocurrency.js +++ b/share/spice/cryptocurrency/cryptocurrency.js @@ -101,12 +101,14 @@ Converter.fromCurrency = from; } - var endpoint = "https://api.cryptonator.com/api/full/" + from + "-" + to; - $.get(endpoint, function(payload) { - Converter.rate = parseFloat(payload.ticker.price); + var endpoint = "/js/spice/cryptonator/" + from + "/" + to; + + $.getJSON(endpoint, function(payload) { + var response = payload; + Converter.rate = parseFloat(response.ticker.price); Converter.calculateRate(); Converter.updateMoreAtLink(to, from); - Converter.updateChangeRate(payload.ticker.change); + Converter.updateChangeRate(response.ticker.change); }); },