rcbp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f3feb2501f215fd9e7d814c0a1bff7a6b9fd92c
4
+ data.tar.gz: 4ec1ab92e3f51bc2514db40b2154231efe11510d
5
+ SHA512:
6
+ metadata.gz: d238ac1207362358a00c945545866f03fba67ff5ef8de67e7b87de4d57b3b2837c10cedaedc2f3f9b58f3c867075df84cd0cacf74a33a9eb4182042416c89989
7
+ data.tar.gz: 43ae74b486ce04a7842478907676384bf83b09f1b2be6161822e4e8a806275eca0bbf1a5cab818ccc22703ce90d1a495c98a909333b3bd6905cc7ff2bd719a34
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .Gemfile.swp
16
+ .rcbp.swp
17
+ .rcbp.gemspec.swp
18
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rcbp.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Nicholas Weggen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # rcbp – Simple Ruby CLI for fetching prices from Coinbase
2
+
3
+ This is a personal project for learning Ruby. It fetches current BTC/USD prices from Coinbase through its json API.
4
+ It is inspired by [btcl](https://github.com/jawerty/btcl), which lets you retrieve market prices from *bitcoincharts*.
5
+
6
+ `rcbp` lists spot, buy and sell prices. You can access the different prices through `rcbp spot`, `rcbp buy` and `rcbp sell`.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/rcbp ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rcbp"
4
+
5
+ class RCBP < Thor
6
+ desc "list", "List spot, buy, and sell price"
7
+ def list
8
+ time = Time.now.strftime("%H:%M:%S")
9
+ puts "\nCurrent prices on Coinbase:\n"\
10
+ "(#{time})\n\n"\
11
+ "---\n\n"\
12
+ "Spot: " + blue(getSpotPrice) + "\n"\
13
+ "Buy: #{getBuyPrice}\n"\
14
+ "Sell: #{getSellPrice}\n\n"
15
+ end
16
+
17
+ desc "spot", "Get the spot price"
18
+ def spot
19
+ puts getSpotPrice
20
+ end
21
+
22
+ desc "buy", "Get the buy price"
23
+ def buy
24
+ puts getBuyPrice
25
+ end
26
+
27
+ desc "sell", "Get the sell price"
28
+ def sell
29
+ puts getSellPrice
30
+ end
31
+
32
+ default_task :list
33
+ end
34
+
35
+ RCBP.start
data/lib/rcbp.rb ADDED
@@ -0,0 +1,39 @@
1
+ require "open-uri"
2
+ require 'net/http'
3
+ require "json"
4
+ require "thor"
5
+
6
+ def getPrice(url)
7
+ amount = String.new
8
+ currency = String.new
9
+
10
+ open(url) do |d|
11
+ json = JSON.parse(d.read)
12
+ amount = json["amount"]
13
+ currency = json["currency"]
14
+ end
15
+
16
+ return "#{amount} #{currency}"
17
+ end
18
+
19
+ def getSpotPrice
20
+ return getPrice("https://api.coinbase.com/v1/prices/spot_rate")
21
+ end
22
+
23
+ def getBuyPrice
24
+ return getPrice("https://api.coinbase.com/v1/prices/buy?qty=1")
25
+ end
26
+
27
+ def getSellPrice
28
+ return getPrice("https://api.coinbase.com/v1/prices/sell?qty=1")
29
+ end
30
+
31
+ # Text in der Console färben
32
+ def colorize(text, color_code)
33
+ "\e[#{color_code}m#{text}\e[0m"
34
+ end
35
+
36
+ def red(text); colorize(text, 31); end
37
+ def green(text); colorize(text, 32); end
38
+ def blue(text); colorize(text, 34); end
39
+
@@ -0,0 +1,3 @@
1
+ module Rcbp
2
+ VERSION = "0.0.1"
3
+ end
data/rcbp.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rcbp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rcbp"
8
+ spec.version = Rcbp::VERSION
9
+ spec.authors = ["Nicholas Weggen"]
10
+ spec.email = ["nweggen@gmail.com"]
11
+ spec.summary = %q{Simple CLI for fetching Coinbase BTC prices.}
12
+ spec.description = %q{Ruby CLI that fetches spot, buy and sell prices from the Coinbase json API.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ["rcbp"]
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency "json", "~> 1.8.2"
24
+ spec.add_dependency "thor", "~> 0.19.1"
25
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rcbp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nicholas Weggen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-20 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.19.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.19.1
69
+ description: Ruby CLI that fetches spot, buy and sell prices from the Coinbase json
70
+ API.
71
+ email:
72
+ - nweggen@gmail.com
73
+ executables:
74
+ - rcbp
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/rcbp
84
+ - lib/rcbp.rb
85
+ - lib/rcbp/version.rb
86
+ - rcbp.gemspec
87
+ homepage: ''
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.5
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Simple CLI for fetching Coinbase BTC prices.
111
+ test_files: []