coinstack 0.1.1
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 +7 -0
- data/.gitignore +10 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +20 -0
- data/Rakefile +2 -0
- data/bin/coinstack +6 -0
- data/bin/setup +8 -0
- data/coinstack.gemspec +35 -0
- data/coinstack.gif +0 -0
- data/lib/coinstack.rb +84 -0
- data/lib/coinstack/list.rb +70 -0
- data/lib/coinstack/version.rb +3 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3fc9adf944a0356227b00cfa4ca0590abf1bf2c0
|
4
|
+
data.tar.gz: 7aef0039f6196b0346aef2321be1164f41d49af6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e65d4f66df94261c77fd8345ef3c8ae2781a36a658e4feadf11827ea63854975aabec7a88e48127f60450aef66f5390247c845e7082d8d095e8820bf7fd9f7bf
|
7
|
+
data.tar.gz: 4c7c77271adb74d2d9c75fffa6120879e06292f45f067b1ee20c833e06f50624747b3b269c617af5dc20230e2f0521984cd954104303405ce1681729c4b9dc0f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 thomasboice
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Coinstack
|
2
|
+
|
3
|
+
Coinstack is a CLI for monitoring the value of your crypto portfolio.
|
4
|
+
It uses the coinmarketcap API, and will update the values every time it is checked.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
`gem install coinstack`
|
9
|
+
then type `coinstack` in your terminal, and press `1` to begin adding assets
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
type `coinstack` in your terminal, then press 1 to start adding assets.
|
14
|
+
|
15
|
+

|
16
|
+
|
17
|
+
## License
|
18
|
+
|
19
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
20
|
+
|
data/Rakefile
ADDED
data/bin/coinstack
ADDED
data/bin/setup
ADDED
data/coinstack.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'coinstack/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "coinstack"
|
8
|
+
spec.version = Coinstack::VERSION
|
9
|
+
spec.authors = ["tnorthb"]
|
10
|
+
spec.email = [""]
|
11
|
+
|
12
|
+
spec.summary = %q{Crypto portfolio monitoring CLI.}
|
13
|
+
spec.description = %q{View the value of your crypto portfolio.}
|
14
|
+
spec.homepage = "https://github.com/tnorthb/coinstack"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "bin"
|
30
|
+
spec.executables = ["coinstack"]
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
end
|
data/coinstack.gif
ADDED
Binary file
|
data/lib/coinstack.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'coinstack/version'
|
2
|
+
require 'highline'
|
3
|
+
require 'coinstack/list'
|
4
|
+
|
5
|
+
module Coinstack
|
6
|
+
# Defines functions the user directly interacts with.
|
7
|
+
class Interface
|
8
|
+
# TODO: Colorscheming, more prettifiers
|
9
|
+
attr_accessor :list,
|
10
|
+
:cli
|
11
|
+
def initialize
|
12
|
+
self.list = List.new
|
13
|
+
self.cli = HighLine.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def start
|
17
|
+
pretty_print_list if list.user_pairs.any?
|
18
|
+
|
19
|
+
loop do
|
20
|
+
cli.choose do |menu|
|
21
|
+
menu.choice('Add an asset') { prompt_add_asset }
|
22
|
+
menu.choice('Remove an asset') { prompt_remove_asset } # TODO
|
23
|
+
menu.choice('Exit') { cli.say('Goodbye!') || exit }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def pretty_print_list
|
29
|
+
total = 0
|
30
|
+
data = []
|
31
|
+
list.user_pairs.each do |symbol, amount|
|
32
|
+
value = (list.pairs[symbol.to_s]['price_usd'].to_f * amount).round(2)
|
33
|
+
data.push(symbol => value)
|
34
|
+
total += value
|
35
|
+
end
|
36
|
+
|
37
|
+
cli.say('Your Portfolio:')
|
38
|
+
data.push({}, { TOTAL: total.round(2).to_s }, {})
|
39
|
+
pretty_print(data)
|
40
|
+
end
|
41
|
+
|
42
|
+
def prompt_add_asset
|
43
|
+
to_add = { amount: nil, symbol: nil }
|
44
|
+
|
45
|
+
loop do
|
46
|
+
break if to_add[:symbol] == 'DONE'
|
47
|
+
if list.pairs[to_add[:symbol]] && to_add[:amount]
|
48
|
+
list.add(to_add)
|
49
|
+
to_add = { amount: nil, symbol: nil }
|
50
|
+
elsif list.pairs[to_add[:symbol]]
|
51
|
+
to_add[:amount] = cli.ask("Type the amount of #{to_add[:symbol]} you have.", Float)
|
52
|
+
else
|
53
|
+
to_add[:symbol] = cli.ask('Type the symbol of the asset to add, or type "done"').upcase
|
54
|
+
end
|
55
|
+
end
|
56
|
+
start
|
57
|
+
end
|
58
|
+
|
59
|
+
def prompt_remove_asset
|
60
|
+
symbol = cli.ask('Which symbol would you like removed?').upcase
|
61
|
+
list.remove(symbol)
|
62
|
+
start
|
63
|
+
end
|
64
|
+
|
65
|
+
ROW_LENGTH = 24
|
66
|
+
# Data should be an array of hashes,
|
67
|
+
# data[0] gets printed first and so on
|
68
|
+
def pretty_print(data)
|
69
|
+
data.each do |datum|
|
70
|
+
if datum.empty?
|
71
|
+
cli.say('-' * ROW_LENGTH)
|
72
|
+
else
|
73
|
+
datum.each do |key, value|
|
74
|
+
info_length = "#{key} #{value}".length
|
75
|
+
buffer = ' ' * [ROW_LENGTH - info_length, 0].max
|
76
|
+
row = key.to_s + buffer + '$' + value.to_s
|
77
|
+
|
78
|
+
cli.say(row)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'securerandom'
|
4
|
+
require 'json'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
module Coinstack
|
8
|
+
# Object for reading and writing our list
|
9
|
+
class List
|
10
|
+
attr_accessor :pairs, # hash of hashes like { btc: {}, ltc: {} }
|
11
|
+
:user_pairs # hash like { btc: 12 }
|
12
|
+
|
13
|
+
PAIRS_URI = URI('https://api.coinmarketcap.com/v1/ticker/')
|
14
|
+
DEFAULT_LOCATION = (File.dirname(__FILE__) + '/.coinstack-pairs').freeze
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
self.pairs = {}
|
18
|
+
update_pairs!
|
19
|
+
FileUtils.touch(DEFAULT_LOCATION) # Ensures it exists
|
20
|
+
self.user_pairs = YAML.load_file(DEFAULT_LOCATION) || {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def update_pairs!
|
24
|
+
res = Net::HTTP.get_response(PAIRS_URI)
|
25
|
+
raise "Could not update pairs! #{res.code}" unless res.is_a?(Net::HTTPSuccess)
|
26
|
+
raw_array = JSON.parse(res.body)
|
27
|
+
raw_array.each do |data|
|
28
|
+
pairs[data['symbol']] = data
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def add(info)
|
33
|
+
data = {}
|
34
|
+
data[info[:symbol]] = info[:amount]
|
35
|
+
user_pairs.merge!(data)
|
36
|
+
save!
|
37
|
+
end
|
38
|
+
|
39
|
+
def remove(symbol)
|
40
|
+
user_pairs.delete(symbol)
|
41
|
+
save!
|
42
|
+
end
|
43
|
+
|
44
|
+
def save!
|
45
|
+
File.open(DEFAULT_LOCATION, 'w') { |f| f.write user_pairs.to_yaml }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Object representing a single entry of the list
|
50
|
+
class Pair
|
51
|
+
attr_accessor :id,
|
52
|
+
:description,
|
53
|
+
:due_date,
|
54
|
+
:added_date,
|
55
|
+
:labels
|
56
|
+
|
57
|
+
def initialize(options = {})
|
58
|
+
options.each { |trait, value| public_send("#{trait}=", value) }
|
59
|
+
self.labels ||= []
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_s
|
63
|
+
description.to_s.capitalize + " | Due: #{due_date}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_h
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coinstack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- tnorthb
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: View the value of your crypto portfolio.
|
42
|
+
email:
|
43
|
+
- ''
|
44
|
+
executables:
|
45
|
+
- coinstack
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/coinstack
|
55
|
+
- bin/setup
|
56
|
+
- coinstack.gemspec
|
57
|
+
- coinstack.gif
|
58
|
+
- lib/coinstack.rb
|
59
|
+
- lib/coinstack/list.rb
|
60
|
+
- lib/coinstack/version.rb
|
61
|
+
homepage: https://github.com/tnorthb/coinstack
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata:
|
65
|
+
allowed_push_host: https://rubygems.org
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.6.4
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Crypto portfolio monitoring CLI.
|
86
|
+
test_files: []
|