ctfc 0.3.3 → 0.4.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
- data/LICENSE +3 -0
- data/README.md +33 -19
- data/bin/ctfc +28 -11
- data/ctfc.gemspec +18 -7
- data/lib/ctfc/base.rb +15 -5
- data/lib/ctfc/version.rb +2 -1
- metadata +21 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d7f984c8d01fdb97f4540e23e244331f7b633d542a812137ba88333fea81c51
|
4
|
+
data.tar.gz: cf87ca5035df753c47613b9ebc9446583241bef10ed5cc6c50407f3e5594ebd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a0d314f9b292f1397d298f08b3d2af7184b65219dbb4e5e84fac85c72bc337e2d0eccce13f191c4ed39cee98d8f13884339eb7f4d2cb209f15d3fa1f91de872
|
7
|
+
data.tar.gz: 9ca4b6afa5b06d20b22a3646f4a2d5cbe017346c148432904a7224a4b66870b0040dee4910ac565688b534bc7c6b46c49d67f837bc5ca57e365f4594786806ae
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -18,7 +18,7 @@ Install from rubygems:
|
|
18
18
|
gem install ctfc
|
19
19
|
```
|
20
20
|
# How to run
|
21
|
-
- **Read documentation on:** https://rubydoc.info/gems/ctfc/
|
21
|
+
- **Read documentation on:** https://rubydoc.info/gems/ctfc/CTFC/Data
|
22
22
|
|
23
23
|
```bash
|
24
24
|
ruby bin/ctfc fiat_1 fiat_2 fiat_3
|
@@ -26,22 +26,24 @@ ruby bin/ctfc fiat_1 fiat_2 fiat_3
|
|
26
26
|
|
27
27
|
This command also accept multiple arguments:
|
28
28
|
|
29
|
-
- `--no-save` -
|
30
|
-
- `--no-print` -
|
31
|
-
- `--coins` -
|
32
|
-
- `--
|
29
|
+
- `--no-save` - do not save `.csv.` output
|
30
|
+
- `--no-print` - do not print terminal output
|
31
|
+
- `--coins` - coins to scrap (default: BTC, LTC, XMR, ETH, BCH, ZEC )
|
32
|
+
- `--loop` - repeat script N times (default 1)
|
33
|
+
- `--wait` - wait N seconds between loops (default 0)
|
34
|
+
- `--help` - help menu
|
33
35
|
|
34
36
|
|
35
37
|
# Script Examples
|
36
38
|
1 - Run script without arguments (default options)
|
37
39
|
|
38
|
-
|
40
|
+
```ruby
|
39
41
|
ruby bin/ctfc
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
=> return:
|
44
|
+
print EUR rates for default coins (BTC, LTC, XMR, ETH, BCH, ZEC)
|
45
|
+
do not save '.csv' table
|
46
|
+
```
|
45
47
|
|
46
48
|
|
47
49
|
2 - Add fiat currencies as arguments
|
@@ -55,7 +57,7 @@ ruby bin/ctfc eur usd rsd
|
|
55
57
|
-> './crypto_eur.csv', './crypto_usd.csv', './crypto_rsd.csv'
|
56
58
|
```
|
57
59
|
|
58
|
-
3 - Use `--no-save
|
60
|
+
3 - Use `--no-save`, `--no-print`, `--loop`, `--wait`
|
59
61
|
|
60
62
|
```ruby
|
61
63
|
ruby bin/ctfc eur --no-print --coins btc xmr ltc
|
@@ -69,7 +71,13 @@ ruby bin/ctfc rsd --no-save --coins btc xmr
|
|
69
71
|
|
70
72
|
=> return:
|
71
73
|
print RSD rates for BTC and XMR
|
72
|
-
|
74
|
+
|
75
|
+
|
76
|
+
# added in version 0.4.0
|
77
|
+
ruby bin/ctfc rsd --no-print --loop 1440 --wait 60
|
78
|
+
|
79
|
+
=> return:
|
80
|
+
save RSD rates without print, run each minute for 24 hours
|
73
81
|
```
|
74
82
|
|
75
83
|
|
@@ -81,37 +89,37 @@ ruby bin/ctfc rsd --no-save --coins btc xmr
|
|
81
89
|
# initialize Data class
|
82
90
|
@data = Ctfc.new :eur, save: false, print: false, coins: COINS
|
83
91
|
=> return Ctfc object to work with
|
84
|
-
|
92
|
+
-> #<Ctfc:0x000055b5c8b61a38 @coins=["BTC", "LTC", "XMR", "ETH", "BCH", "ZEC"], @fiat="EUR", @print=true, @save=true>
|
85
93
|
|
86
94
|
# execute request
|
87
95
|
@data.get
|
88
96
|
=> return Hash with upcase string coins as keys, and float prices
|
89
|
-
|
97
|
+
-> {"BTC"=>36760.11, "XMR"=>169.55, "LTC"=>114.4, "ETH"=>2746.22}
|
90
98
|
|
91
99
|
# now you can use ::Data instance methods
|
92
100
|
@data.response
|
93
101
|
=> return RestClient response to cryptocomare API
|
94
|
-
|
102
|
+
-> <RestClient::Response 200 "{\"RAW\":{\"BT...">
|
95
103
|
|
96
104
|
# check request url
|
97
105
|
@data.url
|
98
106
|
=> return Cryptocompare API url
|
99
|
-
|
107
|
+
-> "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=BTC&fsyms=LTC&fsyms=XMR&fsyms=ETH&fsyms=BCH&fsyms=ZEC&tsyms=EUR"
|
100
108
|
|
101
109
|
# name of csv table (saved in working directory)
|
102
110
|
@data.table
|
103
111
|
=> return '.csv' table name
|
104
|
-
|
112
|
+
-> 'ctfc_eur.csv'
|
105
113
|
|
106
114
|
# array of coins to work with
|
107
115
|
@data.coins
|
108
116
|
=> return coins for scrap, also allow setter method @data.coins = [...]
|
109
|
-
|
117
|
+
-> ['BTC', 'XMR', 'LTC', 'ETH']
|
110
118
|
|
111
119
|
# get all data about all coins (json api response)
|
112
120
|
@data.data
|
113
121
|
=> return all data returned by cryptocompare API
|
114
|
-
|
122
|
+
-> {"RAW"=>
|
115
123
|
{"BTC"=>
|
116
124
|
{"EUR"=>
|
117
125
|
{"TYPE"=>"5",
|
@@ -144,11 +152,17 @@ ruby bin/ctfc rsd --no-save --coins btc xmr
|
|
144
152
|
prices = Crypto.to :eur, coins: %w[BTC XMR]
|
145
153
|
```
|
146
154
|
|
155
|
+
# Tests
|
156
|
+
To run tests use `./check-syntax.sh`.
|
157
|
+
This command will run rubocop for code inspection, but with some errors hidden by `.rubocop_todo.yml`. Using check-syntax script, all test should pass.
|
158
|
+
|
159
|
+
|
147
160
|
# Contribution
|
148
161
|
Any contribution is highly appreciated, as long as you follow Code of Conduct.
|
149
162
|
|
150
163
|
- Fork repository
|
151
164
|
- Make your changes
|
165
|
+
- Write tests
|
152
166
|
- Submit pull request
|
153
167
|
|
154
168
|
# License
|
data/bin/ctfc
CHANGED
@@ -5,7 +5,8 @@ require_relative '../lib/ctfc'
|
|
5
5
|
require 'optimist'
|
6
6
|
|
7
7
|
opts = Optimist.options do
|
8
|
-
version "
|
8
|
+
version "Crypto To Fiat Currency\n".cyan.bold \
|
9
|
+
+ "Gem Version: #{CTFC::VERSION}"
|
9
10
|
|
10
11
|
banner ''
|
11
12
|
banner ' Enter fiat currencies with/out additional arguments:'
|
@@ -14,26 +15,42 @@ opts = Optimist.options do
|
|
14
15
|
banner ' ruby bin/ctfc eur usd --no-save --coins btc xmr ltc'
|
15
16
|
banner ''
|
16
17
|
|
17
|
-
opt :coins,
|
18
|
-
opt :no_save,
|
19
|
-
opt :no_print,
|
18
|
+
opt :coins, 'Set crypto coins', default: CTFC::CONFIG::COINS
|
19
|
+
opt :no_save, "Do not save '.csv' output"
|
20
|
+
opt :no_print, 'Do not print terminal output'
|
21
|
+
opt :loop, 'Run script N times', default: 1, type: :integer
|
22
|
+
opt :wait, 'Wait N seconds between loop', default: 0, type: :integer
|
20
23
|
end
|
21
24
|
|
22
25
|
save = opts[:no_save] ? false : true
|
23
26
|
print = opts[:no_print] ? false : true
|
24
27
|
|
28
|
+
@crypto = Ctfc.new
|
29
|
+
|
25
30
|
if ARGV.empty?
|
26
31
|
|
27
|
-
|
32
|
+
@crypto.get(:eur, save: false)
|
28
33
|
|
29
34
|
else
|
30
35
|
|
31
|
-
|
32
|
-
|
36
|
+
opts[:loop].times do
|
37
|
+
ARGV.each do |fiat|
|
38
|
+
next if opts.include?(fiat.downcase)
|
39
|
+
|
40
|
+
@crypto.get(fiat,
|
41
|
+
save: save,
|
42
|
+
print: print,
|
43
|
+
coins: opts.coins)
|
44
|
+
sleep 1 # wait between requests
|
45
|
+
end
|
46
|
+
|
47
|
+
# end if no `--loop` arg
|
48
|
+
next unless opts[:loop] > 1
|
49
|
+
|
50
|
+
# pause between loops
|
51
|
+
sleep opts[:wait]
|
33
52
|
|
34
|
-
|
35
|
-
|
36
|
-
print: print,
|
37
|
-
coins: opts.coins)
|
53
|
+
# clear screan - depending on OS
|
54
|
+
system 'clear' or system 'cls'
|
38
55
|
end
|
39
56
|
end
|
data/ctfc.gemspec
CHANGED
@@ -5,25 +5,35 @@ require_relative './lib/ctfc/version'
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'ctfc'
|
7
7
|
s.version = CTFC::VERSION
|
8
|
-
s.summary = '
|
9
|
-
s.description =
|
8
|
+
s.summary = 'Cryptocurrency to Fiat values, get data and save prices.'
|
9
|
+
s.description = <<~DESCRIPTION
|
10
|
+
Convert any cryptocurrency to any fiat value, export data to csv table.
|
11
|
+
Print colorized terminal output.
|
12
|
+
DESCRIPTION
|
10
13
|
|
11
14
|
s.license = 'MIT'
|
12
15
|
s.authors = 'alx3dev'
|
13
16
|
s.homepage = 'https://github.com/alx3dev/ctfc'
|
14
17
|
|
15
18
|
s.bindir = 'bin'
|
16
|
-
s.require_paths =
|
17
|
-
s.executables =
|
19
|
+
s.require_paths = 'lib'
|
20
|
+
s.executables = 'ctfc'
|
18
21
|
|
19
22
|
s.metadata['homepage_uri'] = 'https://github.com/alx3dev/ctfc'
|
20
23
|
s.metadata['source_code_uri'] = 'https://github.com/alx3dev/ctfc'
|
21
24
|
s.metadata['bug_tracker_uri'] = 'https://github.com/alx3dev/ctfc/issues'
|
22
|
-
s.metadata['documentation_uri'] = "https://rubydoc.info/gems/#{s.name}
|
25
|
+
s.metadata['documentation_uri'] = "https://rubydoc.info/gems/#{s.name}"
|
23
26
|
s.metadata['rubygems_mfa_required'] = 'true'
|
24
27
|
|
25
|
-
s.files = [
|
26
|
-
|
28
|
+
s.files = %w[ bin/ctfc
|
29
|
+
bin/console
|
30
|
+
lib/ctfc.rb
|
31
|
+
lib/ctfc/version.rb
|
32
|
+
lib/ctfc/base.rb
|
33
|
+
lib/ctfc/config.rb
|
34
|
+
LICENSE
|
35
|
+
README.md
|
36
|
+
ctfc.gemspec]
|
27
37
|
|
28
38
|
s.required_ruby_version = '>= 3.0.1'
|
29
39
|
|
@@ -34,4 +44,5 @@ Gem::Specification.new do |s|
|
|
34
44
|
s.add_development_dependency 'bundler', '~> 2.2.9'
|
35
45
|
s.add_development_dependency 'pry', '~> 0.14.1'
|
36
46
|
s.add_development_dependency 'rake', '~> 13.0.3'
|
47
|
+
s.add_development_dependency 'rspec', '~> 3.10.0'
|
37
48
|
end
|
data/lib/ctfc/base.rb
CHANGED
@@ -8,12 +8,20 @@ require 'csv'
|
|
8
8
|
require 'colorize'
|
9
9
|
require 'rest-client'
|
10
10
|
|
11
|
+
##
|
12
|
+
# Module **CTFC** keep everything together. **CTFC::CONFIG** module for default setup,
|
13
|
+
# and **CTFC::Data** class for actual request execution. For instance methods look
|
14
|
+
# at **CTFC::Data**, for class methods look at **Ctfc**.
|
15
|
+
#
|
16
|
+
# @see CTFC::Data
|
17
|
+
# @see Ctfc
|
18
|
+
#
|
11
19
|
module CTFC
|
12
20
|
##
|
13
21
|
# Data class keep all the logic to send request, receive response,
|
14
22
|
# and everything between. Class Ctfc extend CTFC::Data, for easier work.
|
15
23
|
#
|
16
|
-
# @note Instead of using CTFC::Data.new,
|
24
|
+
# @note Instead of using CTFC::Data.new, you can also call Ctfc.new
|
17
25
|
#
|
18
26
|
class Data
|
19
27
|
include CONFIG
|
@@ -25,7 +33,6 @@ module CTFC
|
|
25
33
|
|
26
34
|
##
|
27
35
|
# @example Initialization example
|
28
|
-
#
|
29
36
|
# @data = CTFC::Data.new :eur, save: true
|
30
37
|
#
|
31
38
|
# @param [Symbol] currency **Optional**. Define fiat currency.
|
@@ -35,7 +42,7 @@ module CTFC
|
|
35
42
|
# @option opts [Boolean] save **Optional**. Save `.csv` output.
|
36
43
|
# @option opts [Array] coins **Optional**. Define coins to scrap.
|
37
44
|
#
|
38
|
-
# @return [
|
45
|
+
# @return [Data] Data object to work with
|
39
46
|
#
|
40
47
|
def initialize(currency = :eur, opts = {})
|
41
48
|
@fiat = currency.to_s.upcase
|
@@ -45,17 +52,19 @@ module CTFC
|
|
45
52
|
end
|
46
53
|
|
47
54
|
##
|
48
|
-
# @example Get fiat prices for
|
55
|
+
# @example Get fiat prices for initialized config
|
49
56
|
#
|
50
57
|
# @data.get
|
51
58
|
#
|
52
|
-
# @example Get prices and change
|
59
|
+
# @example Get prices and change initialized config "on-the-fly"
|
53
60
|
#
|
54
61
|
# @data.get :usd, save: false, coins: %w[BTC XMR ETH]
|
55
62
|
#
|
56
63
|
# @param [Symbol || String] currency **Optional**. Change fiat currency and execute request.
|
57
64
|
# @param [Hash] opts **Optional**. Options hash to change config 'on-the-fly' - see #initialize.
|
58
65
|
#
|
66
|
+
# @return [Hash || false] Hash of coins and fiat values, or false if all requests fail
|
67
|
+
#
|
59
68
|
def get(currency = nil, opts = {})
|
60
69
|
@fiat = currency.to_s.upcase unless currency.nil?
|
61
70
|
@coins = opts[:coins] unless opts[:coins].nil?
|
@@ -141,6 +150,7 @@ module CTFC
|
|
141
150
|
else
|
142
151
|
do_rest_request
|
143
152
|
end
|
153
|
+
false
|
144
154
|
end
|
145
155
|
|
146
156
|
def process_data
|
data/lib/ctfc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ctfc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alx3dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -94,7 +94,23 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 13.0.3
|
97
|
-
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.10.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.10.0
|
111
|
+
description: |
|
112
|
+
Convert any cryptocurrency to any fiat value, export data to csv table.
|
113
|
+
Print colorized terminal output.
|
98
114
|
email:
|
99
115
|
executables:
|
100
116
|
- ctfc
|
@@ -117,7 +133,7 @@ metadata:
|
|
117
133
|
homepage_uri: https://github.com/alx3dev/ctfc
|
118
134
|
source_code_uri: https://github.com/alx3dev/ctfc
|
119
135
|
bug_tracker_uri: https://github.com/alx3dev/ctfc/issues
|
120
|
-
documentation_uri: https://rubydoc.info/gems/ctfc
|
136
|
+
documentation_uri: https://rubydoc.info/gems/ctfc
|
121
137
|
rubygems_mfa_required: 'true'
|
122
138
|
post_install_message:
|
123
139
|
rdoc_options: []
|
@@ -137,5 +153,5 @@ requirements: []
|
|
137
153
|
rubygems_version: 3.2.32
|
138
154
|
signing_key:
|
139
155
|
specification_version: 4
|
140
|
-
summary:
|
156
|
+
summary: Cryptocurrency to Fiat values, get data and save prices.
|
141
157
|
test_files: []
|