bit_converter 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2eb71713960145a2fe047edbc7c843b1e775852c06dfc7a37c71ef56332c02cf
4
- data.tar.gz: 28d8d6b891f47da00e1c1c19ff2a04838ecbb02238ba6fe5ccd077acf5054592
3
+ metadata.gz: f1a694eae2812a06c1783fe29508c91b00b7dadde2061208f638f530e64fb2b0
4
+ data.tar.gz: b828330e5307abeb9299debf3b357bbdb9f8e0c89725f1bcc69b6079e8caca0c
5
5
  SHA512:
6
- metadata.gz: 1dfa7bae7efeb747ae7512a5615bef83393aacb86a57abfd439f39ad5bff88a6e276d9adb6a0d0e4f6e18fef3f6bfe7b3aa67a9f70e2bf1b083f613d85b06709
7
- data.tar.gz: 7dd06299c898310fe5084c6cd784e92edc4344dd83d4b9d12ce1bcd18feb163add099e5ef8ce9ff3aa696f8abb174de40cd842be0c1a7abb294d84aba3b74197
6
+ metadata.gz: e3b89e69e7e706cdf64602c768e090f87b6fbe14ba8abb9b6f414c6821df603b6884bc5123173010e0ef6786a1676818f1b4d09a7ec5a48e40c91075f0fe5526
7
+ data.tar.gz: c73eb322fc963fc2f4c56f1e9a01b7554802ff751fdc2bddd2bd86f61e4260c97d85f15dcc9176c0a027a6f538140829631abae91b0a1c62b519ae806625e548
data/.gitignore CHANGED
@@ -5,6 +5,7 @@
5
5
  /InstalledFiles
6
6
  /pkg/
7
7
  /spec/reports/
8
+ .rspec_status
8
9
  /spec/examples.txt
9
10
  /test/tmp/
10
11
  /test/version_tmp/
data/Gemfile CHANGED
@@ -4,3 +4,5 @@ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in bit_converter.gemspec
6
6
  gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/Gemfile.lock CHANGED
@@ -2,19 +2,24 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  bit_converter (0.1.0)
5
- httparty (~> 0.18.1)
6
- money (~> 6.16)
7
- rake (~> 13.0)
5
+ actionview (~> 6.1, >= 6.1.4.1)
8
6
  thor
9
7
 
10
8
  GEM
11
9
  remote: https://rubygems.org/
12
10
  specs:
13
- activesupport (4.2.10)
14
- i18n (~> 0.7)
15
- minitest (~> 5.1)
16
- thread_safe (~> 0.3, >= 0.3.4)
17
- tzinfo (~> 1.1)
11
+ actionview (6.1.4.1)
12
+ activesupport (= 6.1.4.1)
13
+ builder (~> 3.1)
14
+ erubi (~> 1.4)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
17
+ activesupport (6.1.4.1)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 1.6, < 2)
20
+ minitest (>= 5.1)
21
+ tzinfo (~> 2.0)
22
+ zeitwerk (~> 2.3)
18
23
  addressable (2.8.0)
19
24
  public_suffix (>= 2.0.2, < 5.0)
20
25
  aruba (2.0.0)
@@ -25,12 +30,12 @@ GEM
25
30
  rspec-expectations (~> 3.4)
26
31
  thor (~> 1.0)
27
32
  builder (3.2.4)
28
- byebug (11.1.3)
29
33
  childprocess (4.1.0)
30
34
  concurrent-ruby (1.1.9)
31
35
  contracts (0.16.1)
32
36
  crack (0.4.5)
33
37
  rexml
38
+ crass (1.0.6)
34
39
  cucumber (7.0.0)
35
40
  builder (~> 3.2, >= 3.2.4)
36
41
  cucumber-core (~> 10.0, >= 10.0.1)
@@ -63,22 +68,28 @@ GEM
63
68
  cucumber-cucumber-expressions (~> 12.1, >= 12.1.1)
64
69
  cucumber-messages (~> 17.0, >= 17.0.1)
65
70
  diff-lcs (1.4.4)
71
+ erubi (1.10.0)
66
72
  ffi (1.15.3)
67
73
  hashdiff (1.0.1)
68
- httparty (0.18.1)
69
- mime-types (~> 3.0)
70
- multi_xml (>= 0.5.2)
71
- i18n (0.9.5)
74
+ i18n (1.8.10)
72
75
  concurrent-ruby (~> 1.0)
76
+ loofah (2.10.0)
77
+ crass (~> 1.0.2)
78
+ nokogiri (>= 1.5.9)
73
79
  mime-types (3.3.1)
74
80
  mime-types-data (~> 3.2015)
75
81
  mime-types-data (3.2021.0704)
76
82
  minitest (5.14.4)
77
- money (6.16.0)
78
- i18n (>= 0.6.4, <= 2)
79
83
  multi_test (0.1.2)
80
- multi_xml (0.6.0)
84
+ nokogiri (1.11.7-x86_64-darwin)
85
+ racc (~> 1.4)
81
86
  public_suffix (4.0.6)
87
+ racc (1.5.2)
88
+ rails-dom-testing (2.0.3)
89
+ activesupport (>= 4.2.0)
90
+ nokogiri (>= 1.6)
91
+ rails-html-sanitizer (1.3.0)
92
+ loofah (~> 2.3)
82
93
  rake (13.0.6)
83
94
  rexml (3.2.5)
84
95
  rspec (3.10.0)
@@ -97,23 +108,22 @@ GEM
97
108
  sys-uname (1.2.2)
98
109
  ffi (~> 1.1)
99
110
  thor (1.1.0)
100
- thread_safe (0.3.6)
101
- tzinfo (1.2.9)
102
- thread_safe (~> 0.1)
111
+ tzinfo (2.0.4)
112
+ concurrent-ruby (~> 1.0)
103
113
  webmock (3.14.0)
104
114
  addressable (>= 2.8.0)
105
115
  crack (>= 0.3.2)
106
116
  hashdiff (>= 0.4.0, < 2.0.0)
117
+ zeitwerk (2.4.2)
107
118
 
108
119
  PLATFORMS
109
120
  x86_64-darwin-19
110
121
 
111
122
  DEPENDENCIES
112
- activesupport (~> 4.2.0)
113
123
  aruba
114
124
  bit_converter!
115
- byebug (~> 11.1, >= 11.1.3)
116
125
  cucumber
126
+ rake (~> 13.0)
117
127
  rspec (~> 3.2)
118
128
  webmock (~> 3.14)
119
129
 
data/README.md CHANGED
@@ -1,13 +1,9 @@
1
1
  # BitConverter
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bit_converter`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ A simple crypto and fiat currency converter which can also serve as a minimal portfolio tracker. Exchange rate data are from [CoinBase](https://developers.coinbase.com/api/v2).
6
4
 
7
5
  ## Installation
8
6
 
9
- Add this line to your application's Gemfile:
10
-
11
7
  ```ruby
12
8
  gem 'bit_converter'
13
9
  ```
@@ -22,7 +18,18 @@ Or install it yourself as:
22
18
 
23
19
  ## Usage
24
20
 
25
- TODO: Write usage instructions here
21
+ ```
22
+ ❯ bit -h
23
+ Commands:
24
+ bit convert AMOUNT FROM TO # Converts between fiat and crypto currencies
25
+
26
+ ❯ bit convert 1 btc usd
27
+ 48,840.005
28
+
29
+ ❯ bit convert 3142 doge btc
30
+ 0.020981663970713434
31
+ ```
32
+
26
33
 
27
34
  ## Development
28
35
 
@@ -32,34 +39,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
39
 
33
40
  ## Contributing
34
41
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bit_converter.
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tuang3142/bit-converter.
36
43
 
37
44
  ## License
38
45
 
39
46
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
-
41
-
42
- # bit-converter
43
-
44
- crypto and fiat CLI converter
45
-
46
- # todo
47
-
48
- - [ ] cache data to make it faster
49
- - [ ] better test organize
50
- - [ ] one import to rule them all?
51
- - [ ] currency format
52
- - [ ] portfolio
53
- - [x] basic convert pairs: fiat-fait, coin-coin, coin-fait
54
- - [x] export as rubygem
55
-
56
- # learn
57
-
58
- - make gem
59
- - fully tdd
60
- - command line
61
- - wrap api call (binance, and one more)
62
- - design pattern
63
-
64
- - in hindsignt, should have know how to organzie files, how does rails link
65
- it all together without having to explicitly require
data/Rakefile CHANGED
@@ -2,7 +2,14 @@
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
+ require "cucumber/rake/task"
5
6
 
6
7
  RSpec::Core::RakeTask.new(:spec)
7
8
 
8
- task default: :spec
9
+ desc "Default: run the specs, features, and standard ."
10
+ task default: %w[spec features]
11
+
12
+ Cucumber::Rake::Task.new(:features) do |t|
13
+ t.fork = true
14
+ t.cucumber_opts = ["--format", (ENV["CUCUMBER_FORMAT"] || "progress")]
15
+ end
data/{exe → bin}/bit RENAMED
File without changes
@@ -14,29 +14,24 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/tuang3142/bit-converter"
15
15
  spec.license = "MIT"
16
16
 
17
- spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = spec.homepage
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
19
20
 
20
21
  # Specify which files should be added to the gem when it is released.
21
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
23
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
24
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
25
  end
25
- spec.bindir = "exe"
26
+ spec.bindir = "bin"
26
27
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
28
  spec.require_paths = ["lib"]
28
29
 
29
30
  spec.required_ruby_version = ">= 2.4.0"
30
- spec.add_dependency "httparty", "~> 0.18.1"
31
31
  spec.add_dependency "thor"
32
- spec.add_dependency "rake", "~> 13.0"
33
- spec.add_dependency "money", "~> 6.16"
32
+ spec.add_dependency "actionview", "~> 6.1", ">= 6.1.4.1"
34
33
  spec.add_development_dependency "rspec", "~> 3.2"
35
34
  spec.add_development_dependency "cucumber"
36
35
  spec.add_development_dependency "aruba"
37
36
  spec.add_development_dependency "webmock", "~> 3.14"
38
- spec.add_development_dependency "byebug", "~> 11.1", ">= 11.1.3"
39
-
40
- # for the pluralize method in dummy test
41
- spec.add_development_dependency "activesupport", "~> 4.2.0"
42
37
  end
data/lib/bit_converter.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative "bit_converter/convert"
4
4
  require_relative "bit_converter/coinbase_wrapper"
5
- require_relative "bit_converter/food"
5
+ require_relative "bit_converter/ping"
6
6
  require_relative "bit_converter/version"
7
7
 
8
8
  module BitConverter; end
@@ -1,24 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "thor"
2
4
  require "bit_converter"
3
5
 
4
6
  module BitConverter
5
7
  class CLI < Thor
6
- desc "portray ITEM", "Determines if a piece of food is gross or delicious"
7
- def portray(name)
8
- puts BitConverter::Food.portray(name)
9
- end
10
-
11
- desc "pluralize", "Pluralizes a word"
12
- method_option :word, :aliases => :word
13
- def pluralize
14
- puts BitConverter::Food.pluralize(options[:word])
8
+ desc "ping", "pong!"
9
+ def ping
10
+ puts BitConverter::Ping.ping
15
11
  end
16
12
 
17
13
  desc "convert AMOUNT FROM TO", "Converts between fiat and cypto currencies"
18
14
  def convert(amount, from, to)
19
- puts BitConverter::Convert.convert(amount: amount.to_f,
20
- from: from,
21
- to: to)
15
+ puts BitConverter::Convert.pretty_convert(amount: amount.to_f,
16
+ from: from,
17
+ to: to)
18
+ rescue RuntimeError => e
19
+ puts e.message
20
+ end
21
+
22
+ desc "rate FROM TO", "Get exchange rate between fiat and crypto currencies"
23
+ def rate(from, to)
24
+ convert(1, from, to)
22
25
  end
23
26
  end
24
27
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "httparty"
3
+ require "net/http"
4
+ require "json"
5
+
4
6
  module BitConverter
5
7
  class CoinbaseWrapper
6
8
  class << self
@@ -11,10 +13,10 @@ module BitConverter
11
13
  private
12
14
 
13
15
  def get_exchange_rates(coin)
14
- url = "https://api.coinbase.com/v2/exchange-rates?currency=#{coin}"
15
- response = HTTParty.get(url)
16
+ uri = URI("https://api.coinbase.com/v2/exchange-rates?currency=#{coin}")
17
+ response = Net::HTTP.get(uri)
16
18
 
17
- JSON.parse(response.body)["data"]["rates"]
19
+ JSON.parse(response)["data"]["rates"]
18
20
  end
19
21
 
20
22
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "action_view"
4
+
3
5
  module BitConverter
4
6
  class Convert
5
7
  class << self
@@ -7,14 +9,28 @@ module BitConverter
7
9
  rate_of(to.upcase) / rate_of(from.upcase) * amount
8
10
  end
9
11
 
12
+ def pretty_convert(amount:, from:, to:)
13
+ result = convert(amount: amount, from: from, to: to)
14
+
15
+ helper.number_to_currency(result, unit: "")
16
+ end
17
+
10
18
  private
11
19
 
20
+ def helper
21
+ @helper ||= Class.new do
22
+ include ActionView::Helpers::NumberHelper
23
+ end.new
24
+ end
25
+
12
26
  def rate_of(currency)
27
+ raise "Currencies #{currency} unavailable" if rates[currency].nil?
28
+
13
29
  rates[currency].to_f
14
30
  end
15
31
 
16
32
  def rates
17
- CoinbaseWrapper.usd_exchange_rates
33
+ @rates ||= CoinbaseWrapper.usd_exchange_rates
18
34
  end
19
35
  end
20
36
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BitConverter
4
+ class Ping
5
+ def self.ping
6
+ "pong!"
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BitConverter
4
- VERSION = "0.1.0"
4
+ VERSION = "1.0.0"
5
5
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bit_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tuan Nguyen
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2021-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: httparty
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.18.1
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 0.18.1
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: thor
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -39,33 +25,25 @@ dependencies:
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
- name: rake
28
+ name: actionview
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '13.0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '13.0'
55
- - !ruby/object:Gem::Dependency
56
- name: money
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
33
+ version: '6.1'
34
+ - - ">="
60
35
  - !ruby/object:Gem::Version
61
- version: '6.16'
36
+ version: 6.1.4.1
62
37
  type: :runtime
63
38
  prerelease: false
64
39
  version_requirements: !ruby/object:Gem::Requirement
65
40
  requirements:
66
41
  - - "~>"
67
42
  - !ruby/object:Gem::Version
68
- version: '6.16'
43
+ version: '6.1'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 6.1.4.1
69
47
  - !ruby/object:Gem::Dependency
70
48
  name: rspec
71
49
  requirement: !ruby/object:Gem::Requirement
@@ -122,72 +100,37 @@ dependencies:
122
100
  - - "~>"
123
101
  - !ruby/object:Gem::Version
124
102
  version: '3.14'
125
- - !ruby/object:Gem::Dependency
126
- name: byebug
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '11.1'
132
- - - ">="
133
- - !ruby/object:Gem::Version
134
- version: 11.1.3
135
- type: :development
136
- prerelease: false
137
- version_requirements: !ruby/object:Gem::Requirement
138
- requirements:
139
- - - "~>"
140
- - !ruby/object:Gem::Version
141
- version: '11.1'
142
- - - ">="
143
- - !ruby/object:Gem::Version
144
- version: 11.1.3
145
- - !ruby/object:Gem::Dependency
146
- name: activesupport
147
- requirement: !ruby/object:Gem::Requirement
148
- requirements:
149
- - - "~>"
150
- - !ruby/object:Gem::Version
151
- version: 4.2.0
152
- type: :development
153
- prerelease: false
154
- version_requirements: !ruby/object:Gem::Requirement
155
- requirements:
156
- - - "~>"
157
- - !ruby/object:Gem::Version
158
- version: 4.2.0
159
103
  description: A simple crypto and fiat currency converter which can also serve as a
160
104
  minimal portfolio tracker.
161
105
  email:
162
106
  - hi@tuanguyen.com
163
- executables:
164
- - bit
107
+ executables: []
165
108
  extensions: []
166
109
  extra_rdoc_files: []
167
110
  files:
168
111
  - ".gitignore"
169
112
  - ".rspec"
170
- - ".rspec_status"
171
113
  - Gemfile
172
114
  - Gemfile.lock
173
115
  - LICENSE.txt
174
116
  - README.md
175
117
  - Rakefile
118
+ - bin/bit
176
119
  - bin/console
177
120
  - bin/setup
178
121
  - bit_converter.gemspec
179
122
  - cucumber.yml
180
- - exe/bit
181
123
  - lib/bit_converter.rb
182
124
  - lib/bit_converter/cli.rb
183
125
  - lib/bit_converter/coinbase_wrapper.rb
184
126
  - lib/bit_converter/convert.rb
185
- - lib/bit_converter/food.rb
127
+ - lib/bit_converter/ping.rb
186
128
  - lib/bit_converter/version.rb
187
129
  homepage: https://github.com/tuang3142/bit-converter
188
130
  licenses:
189
131
  - MIT
190
132
  metadata:
133
+ allowed_push_host: https://rubygems.org
191
134
  homepage_uri: https://github.com/tuang3142/bit-converter
192
135
  source_code_uri: https://github.com/tuang3142/bit-converter
193
136
  post_install_message:
data/.rspec_status DELETED
@@ -1,10 +0,0 @@
1
- example_id | status | run_time |
2
- ---------------------------------------------------- | ------ | --------------- |
3
- ./spec/bit_converter/coinbase_wrapper_spec.rb[1:1:1] | passed | 0.01462 seconds |
4
- ./spec/bit_converter/convert_spec.rb[1:1:2] | passed | 0.00349 seconds |
5
- ./spec/bit_converter/convert_spec.rb[1:1:3] | passed | 0.00376 seconds |
6
- ./spec/bit_converter/convert_spec.rb[1:1:4] | passed | 0.00404 seconds |
7
- ./spec/bit_converter/food_spec.rb[1:1] | passed | 0.00116 seconds |
8
- ./spec/bit_converter/food_spec.rb[1:2] | passed | 0.00007 seconds |
9
- ./spec/bit_converter/food_spec.rb[1:3] | passed | 0.0001 seconds |
10
- ./spec/bit_converter_spec.rb[1:1] | passed | 0.00124 seconds |
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_support/inflector"
4
-
5
- module BitConverter
6
- class Food
7
- def self.portray(food)
8
- if food.downcase == "broccoli"
9
- "Gross!"
10
- else
11
- "Delicious!"
12
- end
13
- end
14
-
15
- def self.pluralize(food)
16
- food.pluralize
17
- end
18
- end
19
- end