rubitcoin 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -3
- data/lib/rubitcoin/version.rb +1 -1
- data/lib/rubitcoin.rb +10 -9
- data/test/test_Rubitcoin.rb +19 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 894a2c1e3537f7e22797e0e1d6d73e4bab6e486e
|
4
|
+
data.tar.gz: 10f364b27d1c85f106cba467391ada58522f5811
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: baf301e0f0ba9dcd96efb30990f36f5b058e3166c41396ad88a8858ff73b24a26484446c4857e29439f86c3e552fee9bdd45116c6cd51768035717e9e4e1b67c
|
7
|
+
data.tar.gz: 1f358f3650c74564b80bea8965de8cf31869b442d1905f3dc08a2e8505edaf2fc155e8752b8cf886fa770c42eb5219fe2e471646de14cf1fa1eab8574bd1aa78
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Rubitcoin
|
2
2
|
|
3
|
-
|
3
|
+
Super simple Bitcoin ticker.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,10 +18,18 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install rubitcoin
|
20
20
|
|
21
|
-
##
|
21
|
+
## How to
|
22
22
|
|
23
|
-
|
23
|
+
```rb
|
24
|
+
require 'rubitcoin'
|
24
25
|
|
26
|
+
Rubitcoin.fetch
|
27
|
+
#=> {:high=>223.15, :last=>208.39, :timestamp=>1421461371.0, :bid=>207.95, :vwap=>210.62, :volume=>32705.34241534, :low=>198.04, :ask=>208.21}
|
28
|
+
|
29
|
+
Rubitcoin.high
|
30
|
+
#=> 223.15
|
31
|
+
|
32
|
+
```
|
25
33
|
## Contributing
|
26
34
|
|
27
35
|
1. Fork it ( https://github.com/[my-github-username]/Rubitcoin/fork )
|
data/lib/rubitcoin/version.rb
CHANGED
data/lib/rubitcoin.rb
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
require 'json'
|
3
|
-
|
3
|
+
require 'pry'
|
4
4
|
class Rubitcoin
|
5
|
-
END_POINT = "https://
|
5
|
+
END_POINT = "https://btc-e.com/api/3/ticker"
|
6
6
|
class << self
|
7
|
-
def fetch
|
8
|
-
Hash.[] raw_fetch.map { |k, v| [k.to_sym, v.to_f] }
|
7
|
+
def fetch(currency=:usd)
|
8
|
+
Hash.[] raw_fetch(currency).map { |k, v| [k.to_sym, v.to_f] }
|
9
9
|
end
|
10
10
|
|
11
|
-
%w|high low
|
12
|
-
define_method(mth) do
|
13
|
-
raw_fetch[mth].to_f
|
11
|
+
%w|high low avg vol vol_cur last buy sell updated|.each do |mth|
|
12
|
+
define_method(mth) do |currency=:usd|
|
13
|
+
raw_fetch(currency)[mth].to_f
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
|
-
def raw_fetch
|
19
|
-
JSON.load open END_POINT
|
18
|
+
def raw_fetch(currency)
|
19
|
+
rslt = JSON.load open "#{END_POINT}/btc_#{currency}"
|
20
|
+
rslt.values.first
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
data/test/test_Rubitcoin.rb
CHANGED
@@ -1,14 +1,27 @@
|
|
1
1
|
require 'minitest_helper'
|
2
2
|
|
3
3
|
class TestRubitcoin < MiniTest::Unit::TestCase
|
4
|
-
def
|
4
|
+
def test_usd
|
5
5
|
assert_instance_of Hash, Rubitcoin.fetch
|
6
6
|
assert_instance_of Float, Rubitcoin.high
|
7
|
-
assert_instance_of Float, Rubitcoin.
|
8
|
-
assert_instance_of Float, Rubitcoin.
|
9
|
-
assert_instance_of Float, Rubitcoin.
|
10
|
-
assert_instance_of Float, Rubitcoin.volume
|
7
|
+
assert_instance_of Float, Rubitcoin.avg
|
8
|
+
assert_instance_of Float, Rubitcoin.vol
|
9
|
+
assert_instance_of Float, Rubitcoin.vol_cur
|
11
10
|
assert_instance_of Float, Rubitcoin.last
|
12
|
-
assert_instance_of Float, Rubitcoin.
|
11
|
+
assert_instance_of Float, Rubitcoin.buy
|
12
|
+
assert_instance_of Float, Rubitcoin.sell
|
13
|
+
assert_instance_of Float, Rubitcoin.updated
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_rur
|
17
|
+
assert_instance_of Hash, Rubitcoin.fetch(:rur)
|
18
|
+
assert_instance_of Float, Rubitcoin.high(:rur)
|
19
|
+
assert_instance_of Float, Rubitcoin.avg(:rur)
|
20
|
+
assert_instance_of Float, Rubitcoin.vol(:rur)
|
21
|
+
assert_instance_of Float, Rubitcoin.vol_cur(:rur)
|
22
|
+
assert_instance_of Float, Rubitcoin.last(:rur)
|
23
|
+
assert_instance_of Float, Rubitcoin.buy(:rur)
|
24
|
+
assert_instance_of Float, Rubitcoin.sell(:rur)
|
25
|
+
assert_instance_of Float, Rubitcoin.updated(:rur)
|
13
26
|
end
|
14
27
|
end
|