coin360api21 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -2
- data/lib/coin360api21.rb +40 -3
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdf8c3249c74d161b89d09134a49350618c7f46efebc074349020824c1924940
|
4
|
+
data.tar.gz: 72bb818d16fad5534003870332d64397ece4313b48e56b9abe462c304c73188a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6777b94b98b344ed277cafac4448143d4bce90a837611ac0d0af4046294284ebba7186fd416ea3890fb739ec5e29461834c905403cb2dcdf3ee5689612a5c917
|
7
|
+
data.tar.gz: c3790cf3b4a1fa22443c0d4a5e0c6b7bdc74c714553b4e51b36e64dc8c92646c3196b2ce84e49a6c70cf90be5edfd33f57479be16c29aace8ca82669a174dc8f
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
��X�U$�,���nz���m��,��/�Oj�]~��.��-K:x5��r���Ji#O鱪B�Oh@�<��������2䃘��+�'��Ob��P��V��AL�釞"���j�]\�(4Qud��%o��x�r��1c�a��a�����
|
1
|
+
g���G*�;.��E�l~ �����7�};�Q��Rq<��hmB��>�nX@��*OARp`�B�%H2�sF�\������H9���2
|
data/lib/coin360api21.rb
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
require 'json'
|
6
6
|
require 'excon'
|
7
7
|
require 'unichron'
|
8
|
+
require 'did_you_mean'
|
8
9
|
|
9
10
|
|
10
11
|
module Coin360Api21
|
@@ -31,8 +32,44 @@ module Coin360Api21
|
|
31
32
|
params << 'start=' + timeify(date_start) if date_start
|
32
33
|
params << 'end=' + timeify(date_end) if date_end
|
33
34
|
params << 'period=' + period if period
|
34
|
-
api_call "/coin/historical?%s" % [params.join('&')]
|
35
|
+
r = api_call "/coin/historical?%s" % [params.join('&')]
|
36
|
+
r.map {|x| OpenStruct.new x}
|
35
37
|
|
38
|
+
end
|
39
|
+
|
40
|
+
def info(coin=nil)
|
41
|
+
|
42
|
+
if not @info then
|
43
|
+
r = api_call "/info/currency"
|
44
|
+
@info = r.map {|x| OpenStruct.new x}
|
45
|
+
end
|
46
|
+
|
47
|
+
return @info unless coin
|
48
|
+
|
49
|
+
r = @info.find {|x| x.symbol.downcase == coin || x.name.downcase == coin}
|
50
|
+
|
51
|
+
return r if r
|
52
|
+
|
53
|
+
dym = DidYouMean::SpellChecker.new(dictionary: @info.flat_map \
|
54
|
+
{|x| [x.symbol, x.name]})
|
55
|
+
found = dym.correct(coin)
|
56
|
+
return unless found
|
57
|
+
|
58
|
+
raise "Did you mean? '%s'" % found.first
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
def latest(coin=:btc, convert: :usd)
|
63
|
+
|
64
|
+
params = ['coin=' + coin.to_s]
|
65
|
+
params << 'convert=' + convert.to_s
|
66
|
+
api_call "/coin/latest?%s" % [params.join('&')]
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
def price(coin=:btc)
|
71
|
+
r = latest(coin)
|
72
|
+
r.first.last['quotes']['USD']['price']
|
36
73
|
end
|
37
74
|
|
38
75
|
private
|
@@ -40,7 +77,7 @@ module Coin360Api21
|
|
40
77
|
def api_call(api_request)
|
41
78
|
|
42
79
|
response = Excon.get(@url_base + api_request)
|
43
|
-
JSON.parse(response.body)
|
80
|
+
JSON.parse(response.body) #
|
44
81
|
|
45
82
|
end
|
46
83
|
|
@@ -65,7 +102,7 @@ module Coin360Api21
|
|
65
102
|
def api_call(api_request)
|
66
103
|
|
67
104
|
response = Excon.get(@url_base + api_request)
|
68
|
-
JSON.parse(response.body)
|
105
|
+
OpenStruct.new JSON.parse(response.body)
|
69
106
|
|
70
107
|
end
|
71
108
|
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|