blade_coin 0.1.5 → 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: 4df8a430869db6a54ce2766261f5fd8b4b6a785d1709c854d45730b5822715e7
4
- data.tar.gz: ee3507db16d010ad63cda2f3e2f0a7de092613028b68cb72a218469f69e2ac62
3
+ metadata.gz: 5e7da4b013c6afc2aad595f73eaa1d86f5fef77d8512abfe83d3ab220d3b7eb8
4
+ data.tar.gz: 12306f4736d2d6d27014fe4e41f662079edf5a349d31c1c6abbb1c9c4730a96d
5
5
  SHA512:
6
- metadata.gz: 849e2a566b7cc5051407a6fca6400d6e0dd8a109ff47c392395146bd68921889f8ec74b5de2233e86f27ab2908892ca063a81af57b69fc233970cdc5321dd598
7
- data.tar.gz: 86efdbb9831d6f56ab202e115f0d4bcff26f2d0078ed9043a99a8c64ed09603e135b47cb7ef3d079f7b9a53e6b5199ee60148ff6897eed77fbb8f43c0105c117
6
+ metadata.gz: d6add65fadf9bf62c1527a49bd25e3ee337d2883559185b6e68721b70e1990b1c60b5ba1ce8ec8443fc012a1e182743ba1c1a083097b143aa9000cd1eb2c9966
7
+ data.tar.gz: 20139aeb0bc18ed941392ed8433d856212da010648c5a1b38f6a73c9ccf5c26102f56c45b61b5f545236ecf637b82cabcd29d0229210065cab35341df5e17d0c
data/README.md CHANGED
@@ -4,21 +4,22 @@ command line coin
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ $ gem install blade_coin
8
8
 
9
- ```ruby
10
- gem 'blade_coin'
11
- ```
9
+ ## Usage
12
10
 
13
- And then execute:
11
+ To check the top 10 cryptocurrencies ranked by their market cap, simply enter
12
+ ```
13
+ $ coin
14
+ ```
14
15
 
15
- $ bundle
16
+ Result Output Example:
16
17
 
17
- Or install it yourself as:
18
+ ![](./top_10.png)
18
19
 
19
- $ gem install blade_coin
20
+ ## Options
20
21
 
21
- ## Usage
22
+ ### Find specific coin(s)
22
23
 
23
24
  like `btc`
24
25
 
@@ -32,15 +33,33 @@ BTC_USDT
32
33
  66065.69
33
34
  ```
34
35
 
35
- ## Development
36
+ ### Find top coin(s)
37
+
38
+ You can use the `-t` (or `--top`) with the index to find the top n cryptocurrencies ranked by their market cap.
36
39
 
37
- 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.
40
+ ```
41
+ $ coin -t 50 // find top 50
42
+ ```
38
43
 
39
- 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).
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
+ ```
40
59
 
41
60
  ## Contributing
42
61
 
43
- 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.
44
63
 
45
64
  ## License
46
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,14 +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
- spec.add_dependency 'rainbow'
17
-
18
- # Specify which files should be added to the gem when it is released.
19
- # 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'
20
18
 
21
19
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
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.5"
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blade_coin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sai
@@ -14,16 +14,36 @@ dependencies:
14
14
  name: rainbow
15
15
  requirement: !ruby/object:Gem::Requirement
16
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'
17
34
  - - ">="
18
35
  - !ruby/object:Gem::Version
19
- version: '0'
36
+ version: 3.0.2
20
37
  type: :runtime
21
38
  prerelease: false
22
39
  version_requirements: !ruby/object:Gem::Requirement
23
40
  requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '3.0'
24
44
  - - ">="
25
45
  - !ruby/object:Gem::Version
26
- version: '0'
46
+ version: 3.0.2
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: bundler
29
49
  requirement: !ruby/object:Gem::Requirement
@@ -66,11 +86,13 @@ dependencies:
66
86
  - - "~>"
67
87
  - !ruby/object:Gem::Version
68
88
  version: '3.0'
69
- 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'.
70
91
  email:
71
92
  - rubyer1993@gmail.com
72
93
  executables:
73
94
  - coin
95
+ - coin-cli
74
96
  - console
75
97
  - setup
76
98
  extensions: []
@@ -85,11 +107,13 @@ files:
85
107
  - README.md
86
108
  - Rakefile
87
109
  - bin/coin
110
+ - bin/coin-cli
88
111
  - bin/console
89
112
  - bin/setup
90
113
  - blade_coin.gemspec
91
114
  - lib/blade/coin.rb
92
115
  - lib/blade/coin/version.rb
116
+ - top_10.png
93
117
  homepage: https://github.com/gith-u-b/blade_coin
94
118
  licenses:
95
119
  - MIT
@@ -112,5 +136,5 @@ requirements: []
112
136
  rubygems_version: 3.2.32
113
137
  signing_key:
114
138
  specification_version: 4
115
- summary: blade coin, like query btc price.
139
+ summary: A cryptocurrency price monitoring tool
116
140
  test_files: []