crypto_val 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
  SHA1:
3
- metadata.gz: 94ab7c7da8be8b0a4a3204d92438acfd6ee9859c
4
- data.tar.gz: a3b4cc9ad0bca88b896a63cf114115fe0183ee24
3
+ metadata.gz: f46af8c596ff1f4c7d2325e7a49c7a86337ccd70
4
+ data.tar.gz: 9378b6951a07107ef657dd105297dcc183339e08
5
5
  SHA512:
6
- metadata.gz: edefe54a285a2bbcaac0ebca703629d6073f8be825c5c1d76e02595fc202387a7d76aff3820dc672b6dcde074d7a76874303fa95e49f075b4162b39d71a5b315
7
- data.tar.gz: 3f51e2d50c333e4395282783a1873a2662529323ea472af35b49921ca8bf6b789d1aeb0aee60ba60bebcfb13ebe3afd06334298fe660a17e0d4d2039e77d08dc
6
+ metadata.gz: f125f6a1774759aafd676241a5ad1a9f4b67dfc00533d93b78145bfef584712a4a0aa6bc8fc0c3e635e0cd68f49b2d9de65b1bb81f2ce1a08440a3108553ef6c
7
+ data.tar.gz: 91dcd006fc8ea805b4626b2791f8a0e19f3414388b4413f8ce962f050f7bc535bf50612d3233743d919bf8234efd643f6a7e6829aa6e8c5f2366334a8a7df08d
data/.travis.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.5
4
- before_install: gem install bundler -v 1.13.2
3
+ - 2.2.7
4
+ - 2.3.4
5
+ - 2.4.1
6
+ before_install: gem install bundler -v 1.15.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 - 08092017
4
+ * Adds functionality for listing all Cryptocurrencies
5
+
6
+ ## 0.1.0 - 01092017
7
+ * Initial release
8
+
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  CryptoVal is a Ruby gem that fetches the latest value of a Cryptocurrency. In addition, it also provides exchange rate conversion for several currencies.
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/cryptoval.svg)](https://badge.fury.io/rb/cryptoval)
5
+ [![Gem Version](https://badge.fury.io/rb/crypto_val.svg)](https://badge.fury.io/rb/crypto_val)
6
6
  [![Build Status](https://travis-ci.org/marvs/cryptoval.png)](https://travis-ci.org/marvs/cryptoval)
7
7
 
8
8
  ## Installation
@@ -59,6 +59,21 @@ This returns the date and the current exchange rate:
59
59
 
60
60
  `{:source_currency=>"USD", :target_currency=>"PHP", :date=>#<Date: 2017-08-24 ((2457990j,0s,0n),+0s,2299161j)>, :rate=>51.08}`
61
61
 
62
+ ### List All Cryptocurrencies
63
+
64
+ You can also fetch a list of cryptocurrencies and get their symbol and name.
65
+
66
+ `CryptoVal::List.fetch`
67
+
68
+ This returns an array of hashes, like the following:
69
+
70
+ `[{:symbol=>"IND", :name=>"Indorse"}, {:symbol=>"PGL", :name=>"Prospectors"}]`
71
+
72
+ Each hash contains the following data:
73
+
74
+ * symbol - the coin symbol of the Cryptocurrency
75
+ * name - the name of the Cryptocurrency
76
+
62
77
  ## Development
63
78
 
64
79
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/crypto_val.rb CHANGED
@@ -6,6 +6,9 @@ require "crypto_val/crypto_exchange/cryptonator"
6
6
  require "crypto_val/fiat_exchange"
7
7
  require "crypto_val/fiat_exchange/fixer"
8
8
  require "crypto_val/latest"
9
+ require "crypto_val/list"
10
+ require "crypto_val/list/crypto_compare"
11
+ require "crypto_val/list/crypto_coin_charts"
9
12
 
10
13
  module CryptoVal
11
14
  end
@@ -0,0 +1,27 @@
1
+ module CryptoVal
2
+ class List
3
+ # Gets all cryptocurrency name and symbols
4
+
5
+ def initialize opts={}
6
+ @list_klass = opts[:list_klass] || CryptoVal::List::CryptoCompare
7
+ end
8
+
9
+ def fetch
10
+ formatted
11
+ end
12
+
13
+ def self.fetch opts={}
14
+ new(opts).fetch
15
+ end
16
+
17
+ private
18
+
19
+ def default_data
20
+ @default_data ||= @list_klass.fetch
21
+ end
22
+
23
+ def formatted
24
+ @formatted ||= default_data.map{|d| { symbol: d[:symbol], name: d[:name] } }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,52 @@
1
+ module CryptoVal
2
+ class List::CryptoCoinCharts
3
+
4
+ def fetch
5
+ format_response
6
+ end
7
+
8
+ def self.fetch
9
+ new.fetch
10
+ end
11
+
12
+ private
13
+
14
+ def base_url
15
+ "https://api.cryptocoincharts.info"
16
+ end
17
+
18
+ def url
19
+ "#{base_url}/listCoins"
20
+ end
21
+
22
+ def response
23
+ @response ||= get_response
24
+ end
25
+
26
+ def get_response
27
+ uri = URI.parse(url)
28
+ http = Net::HTTP.new(uri.host, uri.port)
29
+ http.use_ssl = true
30
+ request = Net::HTTP::Get.new(uri.request_uri)
31
+ http.request(request).body
32
+ end
33
+
34
+ def parsed
35
+ @parsed ||= JSON.parse(response)
36
+ end
37
+
38
+ def format_response
39
+ list = []
40
+ parsed.each do |data|
41
+ if data.is_a?(Hash)
42
+ list << {
43
+ symbol: data["id"].upcase,
44
+ name: data["name"]
45
+ }
46
+ end
47
+ end
48
+ list
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,56 @@
1
+ module CryptoVal
2
+ class List::CryptoCompare
3
+
4
+ def fetch
5
+ format_response
6
+ end
7
+
8
+ def self.fetch
9
+ new.fetch
10
+ end
11
+
12
+ private
13
+
14
+ def base_url
15
+ "https://www.cryptocompare.com"
16
+ end
17
+
18
+ def url
19
+ "#{base_url}/api/data/coinlist"
20
+ end
21
+
22
+ def response
23
+ @response ||= get_response
24
+ end
25
+
26
+ def get_response
27
+ uri = URI.parse(url)
28
+ http = Net::HTTP.new(uri.host, uri.port)
29
+ http.use_ssl = true
30
+ request = Net::HTTP::Get.new(uri.request_uri)
31
+ http.request(request).body
32
+ end
33
+
34
+ def parsed
35
+ @parsed ||= JSON.parse(response)
36
+ end
37
+
38
+ def format_response
39
+ list = []
40
+ parsed["Data"].keys.each do |key|
41
+ data = parsed["Data"][key]
42
+ if data.is_a?(Hash)
43
+ logo = data["ImageUrl"].to_s.empty? ? "" : "#{base_url}#{data["ImageUrl"]}"
44
+ list << {
45
+ symbol: data["Name"],
46
+ name: data["CoinName"],
47
+ logo: logo,
48
+ algorithm: data["Algorithm"]
49
+ }
50
+ end
51
+ end
52
+ list
53
+ end
54
+
55
+ end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module CryptoVal
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crypto_val
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
  - Marvin Baltazar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-01 00:00:00.000000000 Z
11
+ date: 2017-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".travis.yml"
63
+ - CHANGELOG.md
63
64
  - CODE_OF_CONDUCT.md
64
65
  - Gemfile
65
66
  - Gemfile.lock
@@ -74,6 +75,9 @@ files:
74
75
  - lib/crypto_val/fiat_exchange.rb
75
76
  - lib/crypto_val/fiat_exchange/fixer.rb
76
77
  - lib/crypto_val/latest.rb
78
+ - lib/crypto_val/list.rb
79
+ - lib/crypto_val/list/crypto_coin_charts.rb
80
+ - lib/crypto_val/list/crypto_compare.rb
77
81
  - lib/crypto_val/version.rb
78
82
  homepage: https://github.com/marvs/cryptoval
79
83
  licenses: