blade_coin 0.1.4 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9aa5fb1920b1f37da206bcaefd234a47ec50636a4325c038f9d3a1144414092
4
- data.tar.gz: cc9ca4737659577b831f44026f5d23f7425e4c7da11e5b1759d537e345859ba9
3
+ metadata.gz: 5e7da4b013c6afc2aad595f73eaa1d86f5fef77d8512abfe83d3ab220d3b7eb8
4
+ data.tar.gz: 12306f4736d2d6d27014fe4e41f662079edf5a349d31c1c6abbb1c9c4730a96d
5
5
  SHA512:
6
- metadata.gz: 86378bdcb31a3c7fb9031b78022d7a7105c156140fe6244728689ae5fd8a6eb70fd4495f59aecb8c5aebaa5cb1b56c148e5049c1099765216cab8a381c429d09
7
- data.tar.gz: 76eaf2912cb79830d69e4c13acc848b241fd86be0c02eae0d0e16a30f784e54a1610eabca3ffe6430ea8043f102c38581cc0188461e4810d32464dd781c38818
6
+ metadata.gz: d6add65fadf9bf62c1527a49bd25e3ee337d2883559185b6e68721b70e1990b1c60b5ba1ce8ec8443fc012a1e182743ba1c1a083097b143aa9000cd1eb2c9966
7
+ data.tar.gz: 20139aeb0bc18ed941392ed8433d856212da010648c5a1b38f6a73c9ccf5c26102f56c45b61b5f545236ecf637b82cabcd29d0229210065cab35341df5e17d0c
data/README.md CHANGED
@@ -4,25 +4,22 @@ command line coin
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
8
-
9
- ```ruby
10
- gem 'blade_coin'
11
- ```
12
-
13
- And then execute:
7
+ $ gem install blade_coin
14
8
 
15
- $ bundle
9
+ ## Usage
16
10
 
17
- Or install it yourself as:
11
+ To check the top 10 cryptocurrencies ranked by their market cap, simply enter
12
+ ```
13
+ $ coin
14
+ ```
18
15
 
19
- $ gem install blade_coin
16
+ Result Output Example:
20
17
 
21
- If there is an error, execute:
18
+ ![](./top_10.png)
22
19
 
23
- $ gem install rainbow
20
+ ## Options
24
21
 
25
- ## Usage
22
+ ### Find specific coin(s)
26
23
 
27
24
  like `btc`
28
25
 
@@ -36,15 +33,33 @@ BTC_USDT
36
33
  66065.69
37
34
  ```
38
35
 
39
- ## Development
36
+ ### Find top coin(s)
40
37
 
41
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+ You can use the `-t` (or `--top`) with the index to find the top n cryptocurrencies ranked by their market cap.
42
39
 
43
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
+ ```
41
+ $ coin -t 50 // find top 50
42
+ ```
43
+
44
+ ### CLI
45
+
46
+ You can quickly query the symbol you want to search for
47
+
48
+ ```
49
+ coin-cli
50
+ ```
51
+
52
+ ### Show option menu
53
+
54
+ You can use the `-h` (or `--help`) to find all valid options of coin
55
+
56
+ ```
57
+ $ coin -h
58
+ ```
44
59
 
45
60
  ## Contributing
46
61
 
47
- Bug reports and pull requests are welcome on GitHub at https://github.com/sai1024/blade_coin. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gith-u-b/blade_coin. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
48
63
 
49
64
  ## License
50
65
 
data/bin/coin CHANGED
@@ -3,25 +3,22 @@
3
3
  require_relative '../lib/blade/coin'
4
4
 
5
5
  help = <<HELP
6
- coin: Translate tools in the command line
7
- $ coin symbol
8
- $ coin
6
+ coin: 💰 A cryptocurrency price monitoring tools in the command line
7
+ $ coin symbol Find specific coin(s), eg: coin btc
8
+ $ coin To check the top 10 cryptocurrencies ranked by their market cap
9
+ $ coin -t [top] To query and display the number of cryptocurrencies ranked by market cap based on the 'top' parameter you input
10
+ $ coin-cli Coin's CLI, you can quickly query the symbol you want to search for
9
11
  > enter the loop mode, ctrl+c to exit
10
12
  HELP
11
13
 
12
14
  if ARGV.empty?
13
- begin
14
- loop do
15
- print '> '
16
- input = gets.chomp
17
- next if input == ''
18
- puts Blade::Coin.new(input).result
19
- end
20
- rescue Interrupt
21
- puts 'bye bye'
22
- end
15
+ puts Blade::Coin.new('').get_top_markets
23
16
  elsif %w{-h --help}.any? { |c| ARGV.include? c }
24
17
  puts help
18
+ elsif %w{-t --top}.any? { |c| ARGV.include? c }
19
+ index = ARGV.index('-t') || ARGV.index('--top')
20
+ top = ARGV[index + 1].to_i
21
+ puts Blade::Coin.new('').get_top_markets(top)
25
22
  else
26
23
  puts Blade::Coin.new(ARGV.join(' ')).result
27
24
  end
data/bin/coin-cli ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/blade/coin'
4
+
5
+ if ARGV.empty?
6
+ begin
7
+ loop do
8
+ print '> '
9
+ input = gets.chomp
10
+ next if input == ''
11
+ puts Blade::Coin.new(input).result
12
+ end
13
+ rescue Interrupt
14
+ puts 'bye bye'
15
+ end
16
+ else
17
+ puts Blade::Coin.new(ARGV.join(' ')).result
18
+ end
data/blade_coin.gemspec CHANGED
@@ -9,13 +9,12 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["sai"]
10
10
  spec.email = ["rubyer1993@gmail.com"]
11
11
 
12
- spec.summary = "blade coin, like query btc price."
13
- spec.description = "blade coin, like query btc price."
12
+ spec.summary = "A cryptocurrency price monitoring tool"
13
+ spec.description = "A cryptocurrency price monitoring tool, you can run 'coin -h' for more help, or read the 'README.md'."
14
14
  spec.homepage = "https://github.com/gith-u-b/blade_coin"
15
15
  spec.license = "MIT"
16
-
17
- # Specify which files should be added to the gem when it is released.
18
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
+ spec.add_dependency 'rainbow', "~> 2.1.0"
17
+ spec.add_dependency 'terminal-table', '~> 3.0', '>= 3.0.2'
19
18
 
20
19
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
20
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -1,5 +1,5 @@
1
1
  module Blade
2
2
  module Coin
3
- VERSION = "0.1.4"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
data/lib/blade/coin.rb CHANGED
@@ -2,6 +2,7 @@ require "uri"
2
2
  require "net/http"
3
3
  require "json"
4
4
  require "rainbow/ext/string"
5
+ require "terminal-table"
5
6
 
6
7
  module Blade
7
8
  class Coin
@@ -12,20 +13,61 @@ module Blade
12
13
 
13
14
  def query_for_hash
14
15
  query_url = get_mxc_single_market(@coin)
15
- result_json = Net::HTTP.get(URI(query_url))
16
- @result_hash = JSON.parse(result_json)
16
+ @result_hash = make_http_request(query_url)
17
17
  end
18
18
 
19
19
  def get_mxc_single_market(coin)
20
20
  "https://www.mexc.com/open/api/v2/market/ticker?symbol=#{coin}_USDT"
21
21
  end
22
22
 
23
+ def get_top_markets(top = 10)
24
+ query_url = "https://api.coincap.io/v2/assets?limit=#{top}"
25
+ result_json = make_http_request(query_url)
26
+ data = result_json[:data]
27
+
28
+ timestamp = result_json[:timestamp] / 1000 rescue ''
29
+ formatted_time = Time.at(timestamp).strftime("%I:%M:%S %p")
30
+ puts green_colorize("Data source from coincap.io at #{formatted_time}")
31
+
32
+ display_market_data(data)
33
+ end
34
+
35
+ def display_market_data(data)
36
+ title = '💰Wishing you prosperity and wealth(恭喜发财)💰'.color(226)
37
+ table = Terminal::Table.new(title: "\e[33m#{title}\e[0m") do |t|
38
+ t.headings = [orange_colorize('Rank'), orange_colorize('Coin'), orange_colorize('Price (USD)'), orange_colorize('ChangePercent24Hr'), orange_colorize('Vwap24Hr'), orange_colorize('Market Cap (USD)')]
39
+ t.rows = data.map do |d|
40
+ [
41
+ green_colorize(d[:rank] || 0),
42
+ green_colorize(d[:symbol] || 0),
43
+ green_colorize(format("%.4f", d[:priceUsd].to_f)),
44
+ yellow_colorize(format("%.2f", d[:changePercent24Hr].to_f)),
45
+ yellow_colorize(format("%.2f", d[:vwap24Hr].to_f)),
46
+ green_colorize(format("%.4f", d[:marketCapUsd].to_f))
47
+ ]
48
+ end
49
+ end
50
+ table
51
+ end
52
+
53
+ def green_colorize(str)
54
+ colorize(str, :green)
55
+ end
56
+
57
+ def orange_colorize(str)
58
+ colorize(str, :orange)
59
+ end
60
+
61
+ def yellow_colorize(str)
62
+ colorize(str, :yellow)
63
+ end
64
+
23
65
  def usdt_result
24
- return [] unless @result_hash["data"]
66
+ return [] unless @result_hash[:data]
25
67
  lines = []
26
- data = @result_hash["data"][0]
27
- lines << data["symbol"].color(:red)
28
- lines << data["last"].color(:green)
68
+ data = @result_hash[:data][0]
69
+ lines << data[:symbol].color(:red)
70
+ lines << data[:last].color(:green)
29
71
  lines << ""
30
72
  end
31
73
 
@@ -34,5 +76,14 @@ module Blade
34
76
  output << usdt_result
35
77
  output.flatten
36
78
  end
79
+
80
+ def make_http_request(url)
81
+ response = Net::HTTP.get_response(URI(url))
82
+ JSON.parse(response.body, symbolize_names: true)
83
+ end
84
+
85
+ def colorize(str, color)
86
+ str.color(color) rescue ''
87
+ end
37
88
  end
38
89
  end
data/top_10.png ADDED
Binary file
metadata CHANGED
@@ -1,15 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blade_coin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-15 00:00:00.000000000 Z
11
+ date: 2023-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rainbow
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: terminal-table
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 3.0.2
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '3.0'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 3.0.2
13
47
  - !ruby/object:Gem::Dependency
14
48
  name: bundler
15
49
  requirement: !ruby/object:Gem::Requirement
@@ -52,11 +86,13 @@ dependencies:
52
86
  - - "~>"
53
87
  - !ruby/object:Gem::Version
54
88
  version: '3.0'
55
- description: blade coin, like query btc price.
89
+ description: A cryptocurrency price monitoring tool, you can run 'coin -h' for more
90
+ help, or read the 'README.md'.
56
91
  email:
57
92
  - rubyer1993@gmail.com
58
93
  executables:
59
94
  - coin
95
+ - coin-cli
60
96
  - console
61
97
  - setup
62
98
  extensions: []
@@ -71,11 +107,13 @@ files:
71
107
  - README.md
72
108
  - Rakefile
73
109
  - bin/coin
110
+ - bin/coin-cli
74
111
  - bin/console
75
112
  - bin/setup
76
113
  - blade_coin.gemspec
77
114
  - lib/blade/coin.rb
78
115
  - lib/blade/coin/version.rb
116
+ - top_10.png
79
117
  homepage: https://github.com/gith-u-b/blade_coin
80
118
  licenses:
81
119
  - MIT
@@ -98,5 +136,5 @@ requirements: []
98
136
  rubygems_version: 3.2.32
99
137
  signing_key:
100
138
  specification_version: 4
101
- summary: blade coin, like query btc price.
139
+ summary: A cryptocurrency price monitoring tool
102
140
  test_files: []