Bitcoin Spice #320
Bitcoin Spice #320
Changes from 3 commits
7bf6d2c
4efafd4
f14f604
8e64522
1ddb309
3dfcd5a
ff5eabb
6539b77
7ece2e1
826aeac
2e7dd37
66c89d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package DDG::Spice::Bitcoin; | ||
|
||
use DDG::Spice; | ||
|
||
primary_example_queries "bitcoin"; | ||
secondary_example_queries "bitcoin eur", "bitcoin cny"; | ||
description "Get Bitcoin Exchange Rate"; | ||
name "Bitcoin"; | ||
source "http://blockchain.info"; | ||
code_url "https://github.com/duckduckgo/zeroclickinfo-spice/blob/master/lib/DDG/Spice/Bitcoin.pm"; | ||
topics "economy_and_finance"; | ||
category "conversions"; | ||
|
||
attribution github => ['https://github.com/jmg','Juan Manuel García'], | ||
email => ['jmg.utn@gmail.com','Juan Manuel García']; | ||
|
||
spice to => 'http://blockchain.info/ticker'; | ||
spice wrap_jsonp_callback => 1; | ||
|
||
triggers any => "bitcoin", "bit coin"; | ||
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. What do you think about adding "bitcoin exchange", "bit coin exchange" here? 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. Ah, "bitcoin market", too. But I'm not sure how common that is. 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. Added "bitcoin exchange", "bit coin exchange" :) |
||
|
||
handle remainder => sub { | ||
|
||
return $_; | ||
}; | ||
|
||
1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#spice_bitcoin .spice_pane { | ||
display: inline-block; | ||
width: 40%; | ||
vertical-align: top; | ||
margin: 10px 10px; | ||
font-size: 24px; | ||
} | ||
|
||
#spice_bitcoin .spice_pane span { | ||
font-weight: bold; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{{title}}: <span>{{symbol}}{{price}}</span> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
function ddg_spice_bitcoin (api_result) { | ||
|
||
if (!api_result) return; | ||
|
||
var DEFAULT_CURRENCY = "USD"; | ||
|
||
var query = DDG.get_query(); | ||
var params = query.split(/\s+/g); | ||
|
||
if (params.length > 1) { | ||
var currency = params[1].toUpperCase(); | ||
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. What if I search "jpy bitcoin"? 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. This doesn't contemplate that case so it will return the amount in dollars as it's default when it doesn't recognize the currency. But maybe we can search for the currency parameter either on the first or on the second position inside the query array. Would that work? 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. That sounds reasonable. I think having "jpy bitcoin" and "bitcoin jpy" both working would be great. :) 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. Great! I improved it. Now it searches through all the parameters array so you put the currency anywhere on the query string and you'll get the right answer. All "jpy bitcoin", "bitcoin jpy", "get bitcoin jpy", "bitcoin convert jpy", etc will work. 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. Awesome! |
||
} else { | ||
var currency = DEFAULT_CURRENCY; | ||
} | ||
|
||
var prices = api_result[currency]; | ||
if (!prices) { | ||
prices = api_result[DEFAULT_CURRENCY]; | ||
} | ||
|
||
var buy = { | ||
price: prices.buy.toFixed(2), | ||
symbol: prices.symbol, | ||
title: "Buy" | ||
} | ||
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. Small nitpick: Semicolon to be consistent. :) 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. Sorry about those, I just ran jslint to ensure consistency :) |
||
|
||
var sell = { | ||
price: prices.sell.toFixed(2), | ||
symbol: prices.symbol, | ||
title: "Sell" | ||
} | ||
|
||
Spice.render({ | ||
header1 : "Bitcoin Exchange Prices", | ||
source_name : "Blockchain", | ||
spice_name : "bitcoin", | ||
source_url : 'http://markets.blockchain.info/', | ||
force_favicon_url : "http://blockchain.info/favicon.ico", | ||
|
||
template_frame : "twopane", | ||
template_options : { | ||
left : { template: "bitcoin", data: buy }, | ||
right : { template: "bitcoin", data: sell }, | ||
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. Trailing comma. |
||
}, | ||
force_no_fold : true, | ||
force_big_header : true | ||
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. You can add 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. Sorry, it might be better to use "http://blockchain.info/favicon.ico" since they are the provider. 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. Yeah, no problem. Just did it! |
||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use DDG::Test::Spice; | ||
|
||
ddg_spice_test( | ||
[qw( DDG::Spice::Bitcoin )], | ||
'bitcoin' => test_spice( | ||
'/js/spice/bitcoin/', | ||
call_type => 'include', | ||
caller => 'DDG::Spice::Bitcoin' | ||
), | ||
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. Add tests please for all the different variations. :) 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. Will do! 👍 |
||
); | ||
|
||
done_testing; | ||
|
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.
We can probably add
triggers start => "bitcoin exchange in"
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.
Yeah, I've no problem. But would the triggers any => "bitcoin", "bit coin", "bitcoin exchange", "bit coin exchange" also work? Or you think it's better to just trigger it when the query starts explicitly with "bitcoin exchange in"?
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.
Oh weird. Looks like when I added
triggers start => "bitcoin exchange in"
, some trigger words intriggers any
stopped working. It might be a bug. But for now, having bothtriggers start => "bitcoin exchange in"
andtriggers startend => "bitcoin", ...
should work for our purposes here. :)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.
Yeah, I tried and wasn't working well so didn't know if this was the bug or "triggers start" and "triggers any" couldn't be together. Will use triggers start => "bitcoin exchange in" and triggers startend => "bitcoin" then.
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.
Nice.
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.
Maybe I could open a bug for the weird behavior of "trigger any" and "trigger start" working togheter
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.
@jmg this is actually a known bug -- we're working on it :)