coin360api21 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a834ea56c7e8155f4116fa5fe39d95c015060b12ed592292ca85b7f77a3e22b
4
- data.tar.gz: 5d989ae646416a9b6970d1004d4418f4e4a2c0d79c2ea15d85c32ec5099953a5
3
+ metadata.gz: bdf8c3249c74d161b89d09134a49350618c7f46efebc074349020824c1924940
4
+ data.tar.gz: 72bb818d16fad5534003870332d64397ece4313b48e56b9abe462c304c73188a
5
5
  SHA512:
6
- metadata.gz: 3d6fc3919159c226faf3db3f446dc29f1195f5b898ef472ad2a2d719a4abfb115e8b477f1e05596d6fcc02864dbf7e90c9bba125004971784eba360b7bbe5249
7
- data.tar.gz: 95902115381648c630cc076f4003f9a85440b8f1b5ef5a001492c6186ac724264c9cfffdfffaf801e2673d04a4d930a187ae98ceeebb84bd62176747898f785a
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
- $ 0��e�"|�W�Ҟ6(����.<��7���A.a8���t9��s�*�)H�8w�ni"eY�g�F��;�]����B)߶m��y��j�� ={(i�VeZ0;[�n�*�HE��#P>�LxA�O������?�4��|�.�B)x�����S����L��u�V)���ׯ�#}8���g�7�����r�s^)f)6���HtB=>� ]��*�����_D}
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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coin360api21
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file