chg 0.1.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 +7 -0
- checksums.yaml.gz.sig +0 -0
- data/.gitignore +8 -0
- data/.travis.yml +5 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +30 -0
- data/README.md +44 -0
- data/Rakefile +10 -0
- data/bin/chg +18 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/certs/oz.pem +20 -0
- data/chg.gemspec +30 -0
- data/lib/chg/cli.rb +34 -0
- data/lib/chg/version.rb +3 -0
- data/lib/chg.rb +6 -0
- data.tar.gz.sig +2 -0
- metadata +136 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3c846a0baec4a71b168fe9358a59cabd2fd34304
|
4
|
+
data.tar.gz: aae664511bf792fcc7036a58803b4be21b6e6089
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a0ee2f99925808dc477c00bbc48cc5bd8c5f57b29eb800c6daeb776389fe1ba870faa1a98aed189b2ae9584c42e3358ddbb87c495a307b0bb845ea12b7c36e27
|
7
|
+
data.tar.gz: 94b702c99dbc1a679f35acf7d89d4847508fc4c05dd57274ff95850cbdcfa741c49f46b66ac35947609596ad82da71d79cef93568851a0647904bc5649116da6
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
chg (0.1.0)
|
5
|
+
alphavantagerb (~> 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
alphavantagerb (1.0.0)
|
11
|
+
httparty (= 0.15.6)
|
12
|
+
humanize (= 1.7.0)
|
13
|
+
httparty (0.15.6)
|
14
|
+
multi_xml (>= 0.5.2)
|
15
|
+
humanize (1.7.0)
|
16
|
+
minitest (5.10.3)
|
17
|
+
multi_xml (0.6.0)
|
18
|
+
rake (10.5.0)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
bundler (~> 1.16)
|
25
|
+
chg!
|
26
|
+
minitest (~> 5.0)
|
27
|
+
rake (~> 10.0)
|
28
|
+
|
29
|
+
BUNDLED WITH
|
30
|
+
1.16.0
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Chg
|
2
|
+
|
3
|
+
`chg` is a very basic CLI for currency exchange, using [Alpha Vantage][alpha] API.
|
4
|
+
|
5
|
+
# Installation
|
6
|
+
|
7
|
+
```shell
|
8
|
+
gem install chg
|
9
|
+
```
|
10
|
+
|
11
|
+
# Usage
|
12
|
+
|
13
|
+
```shell
|
14
|
+
$ chg -h
|
15
|
+
Usage: chg <from> <to> [amount = 1]
|
16
|
+
$ chg BTC USD
|
17
|
+
1.0 BTC = 1234567890.01234 USD
|
18
|
+
```
|
19
|
+
|
20
|
+
That's about it.
|
21
|
+
|
22
|
+
# Development
|
23
|
+
|
24
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
25
|
+
`rake test` to run the tests. You can also run `bin/console` for an interactive
|
26
|
+
prompt that will allow you to experiment.
|
27
|
+
|
28
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
29
|
+
release a new version, update the version number in `version.rb`, and then run
|
30
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
31
|
+
git commits and tags, and push the `.gem` file to [rubygems.org][rubygems].
|
32
|
+
|
33
|
+
# Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome at https://git.cypr.io/oz/chg.
|
36
|
+
`git format-patch` is also your friend.
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [GPL v3 License][license].
|
41
|
+
|
42
|
+
[alpha]: https://alphavantage.co/
|
43
|
+
[rubygems]: https://rubygems.org
|
44
|
+
[license]: https://www.gnu.org/licenses/gpl.html
|
data/Rakefile
ADDED
data/bin/chg
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'chg'
|
5
|
+
|
6
|
+
cli = Chg::CLI.new ENV['ALPHAVANTAGE_KEY']
|
7
|
+
|
8
|
+
if ARGV.size < 2 || ARGV.size > 3 || ARGV[0] == '-h' || ARGV[0] == '--help'
|
9
|
+
warn cli.usage
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
ARGV.push '1' if ARGV.size == 2
|
13
|
+
from, to, amount = ARGV
|
14
|
+
begin
|
15
|
+
puts cli.change from, to, amount.to_f
|
16
|
+
rescue StandardError => err
|
17
|
+
warn "Error: #{err}"
|
18
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'chg'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/certs/oz.pem
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDXDCCAkSgAwIBAgIBATANBgkqhkiG9w0BAQUFADA6MQswCQYDVQQDDAJvejEW
|
3
|
+
MBQGCgmSJomT8ixkARkWBmN5cHJpbzETMBEGCgmSJomT8ixkARkWA25ldDAeFw0x
|
4
|
+
NzEyMDYyMzU3MDVaFw0xODEyMDYyMzU3MDVaM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4gYsI4f1BmvbLsViOfj66eASScL+qJxlJ94n1q503A5gAq2v
|
20
|
+
-----END CERTIFICATE-----
|
data/chg.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chg/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'chg'
|
8
|
+
spec.version = Chg::VERSION
|
9
|
+
spec.authors = ['Arnaud Berthomier']
|
10
|
+
spec.email = ['oz@cyprio.net']
|
11
|
+
|
12
|
+
spec.summary = 'Get exchange rates from Alpha Vantage'
|
13
|
+
spec.description = 'Change amounts between currencies using the Alpha Vantage API'
|
14
|
+
spec.homepage = 'https://rubygems.org/gems/chg'
|
15
|
+
spec.license = 'GPL-3.0'
|
16
|
+
spec.cert_chain = ['certs/oz.pem']
|
17
|
+
spec.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
spec.bindir = 'bin'
|
23
|
+
spec.executables = ['chg']
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_dependency 'alphavantagerb', '~> 1.0'
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
28
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
end
|
data/lib/chg/cli.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'alphavantagerb'
|
2
|
+
|
3
|
+
module Chg
|
4
|
+
# CLI interface
|
5
|
+
class CLI
|
6
|
+
MissingKey = ArgumentError.new('Missing ALPHAVANTAGE_KEY env. var')
|
7
|
+
attr_reader :key
|
8
|
+
|
9
|
+
def initialize(key)
|
10
|
+
@key = key
|
11
|
+
end
|
12
|
+
|
13
|
+
def usage
|
14
|
+
"Usage: #{program} <from> <to> [amount = 1]"
|
15
|
+
end
|
16
|
+
|
17
|
+
def change(from, to, amount)
|
18
|
+
changed = amount * rate(from, to)
|
19
|
+
"#{amount} #{from.upcase} = #{changed} #{to.upcase}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def rate(from, to)
|
23
|
+
raise MissingKey unless key
|
24
|
+
xchg = Alphavantage::Exchange.new from: from, to: to, key: key
|
25
|
+
xchg.exchange_rate.to_f
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def program
|
31
|
+
$PROGRAM_NAME.sub(%r{.*/}, '')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/chg/version.rb
ADDED
data/lib/chg.rb
ADDED
data.tar.gz.sig
ADDED
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arnaud Berthomier
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDXDCCAkSgAwIBAgIBATANBgkqhkiG9w0BAQUFADA6MQswCQYDVQQDDAJvejEW
|
14
|
+
MBQGCgmSJomT8ixkARkWBmN5cHJpbzETMBEGCgmSJomT8ixkARkWA25ldDAeFw0x
|
15
|
+
NzEyMDYyMzU3MDVaFw0xODEyMDYyMzU3MDVaMDoxCzAJBgNVBAMMAm96MRYwFAYK
|
16
|
+
CZImiZPyLGQBGRYGY3lwcmlvMRMwEQYKCZImiZPyLGQBGRYDbmV0MIIBIjANBgkq
|
17
|
+
hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz21HEhVkaXSPzy1MlQ6/ooofI7UsUi0y
|
18
|
+
hs2OijsIMU11OFidoovzpVSjeBh6tKpMSZ+DZUDBs7j7v+ySUneNpxE5HgBsMReR
|
19
|
+
QmrlST2DVwDXbrBCg6qa7z2wnqirRTcoC7dlNXxwbd30uiO9urUPe7DrEX7DKDPC
|
20
|
+
pjsMe35emITwPBqdRLfb41jId4cee1LtczEjA5Nq8k6NToP4bdTBzHMqhNqZuWo9
|
21
|
+
JF0zJoSqj6ESs6BkrfojSO1QrhXByHKUshgb+TphCZRgvRvhVc2UKXT//bLY7c30
|
22
|
+
MXJEE9s1TZ54PEOKCyF01GxekiZgEWl5eHQmla/CioVUiNwrOe/FawIDAQABo20w
|
23
|
+
azAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU5oGx6Kd/9dKH11cx
|
24
|
+
yeHsZQd6b/AwGAYDVR0RBBEwD4ENb3pAY3lwcmlvLm5ldDAYBgNVHRIEETAPgQ1v
|
25
|
+
ekBjeXByaW8ubmV0MA0GCSqGSIb3DQEBBQUAA4IBAQC9e2a843gYyOmVCpGPceVa
|
26
|
+
IcwgRNQaePzQqD8k9pedQTe3208E2bFDyHYH9hUBlEgtVx5bHuNaGsiLgcfdQNvS
|
27
|
+
HUiMcheNPvFir8RzDdQvbqt7aJtjquqL8ja3KpAOAGvD7k7g6/cwX8Z6MF5ilIVj
|
28
|
+
5tNjXvqYHYrNXT0BPaRnRffAWkhvjYaF5AADo/C2S/lBuEUktV2N39HFLjP1wn3X
|
29
|
+
vNI5ttfCjlZb2OmvoC04CvZqSKFG8QuEnCqTL6CKO3HCkKUddqb1C6m8z6JQT/LR
|
30
|
+
T7BikqZkr+M4rr6H4gYsI4f1BmvbLsViOfj66eASScL+qJxlJ94n1q503A5gAq2v
|
31
|
+
-----END CERTIFICATE-----
|
32
|
+
date: 2017-12-07 00:00:00.000000000 Z
|
33
|
+
dependencies:
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: alphavantagerb
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
type: :runtime
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.16'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: minitest
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
type: :development
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: rake
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
description: Change amounts between currencies using the Alpha Vantage API
|
91
|
+
email:
|
92
|
+
- oz@cyprio.net
|
93
|
+
executables:
|
94
|
+
- chg
|
95
|
+
extensions: []
|
96
|
+
extra_rdoc_files: []
|
97
|
+
files:
|
98
|
+
- ".gitignore"
|
99
|
+
- ".travis.yml"
|
100
|
+
- Gemfile
|
101
|
+
- Gemfile.lock
|
102
|
+
- README.md
|
103
|
+
- Rakefile
|
104
|
+
- bin/chg
|
105
|
+
- bin/console
|
106
|
+
- bin/setup
|
107
|
+
- certs/oz.pem
|
108
|
+
- chg.gemspec
|
109
|
+
- lib/chg.rb
|
110
|
+
- lib/chg/cli.rb
|
111
|
+
- lib/chg/version.rb
|
112
|
+
homepage: https://rubygems.org/gems/chg
|
113
|
+
licenses:
|
114
|
+
- GPL-3.0
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.6.13
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Get exchange rates from Alpha Vantage
|
136
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|