money-bank-cryptocompare 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c6ed758c024e1785d40d226934c3b57eb4fccf6
4
+ data.tar.gz: 901752f7c5ee656f9688d8a7151609a9afa5d45d
5
+ SHA512:
6
+ metadata.gz: 5a2496fd58e40f77cb9fdfad86236f38400ea18506c99aed2b78e205fb78429c441b7b691c5ebe768971b52b1f09543ae572100c2a69128f3d9ed2f0658e62d2
7
+ data.tar.gz: 4e7775b74d09be6e94245a954a7f2b6005bd4c61f00bc1fb213a43001d1d3ee14a15ef8c68b46f99fc754d8d03cce295f98562957b6ec0bc15b9a7f5ff43c3ea
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in money-bank-cryptocompare.gemspec
6
+ gemspec
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 LULALALA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ # Money::Bank::Cryptocompare
2
+
3
+ Money gem's Bank implementation to Cryptocompare API to do cryptocurrency exchange, like converting Bitcoin to Ethereum.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'money-bank-cryptocompare'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install money-bank-cryptocompare
20
+
21
+ ## Usage
22
+
23
+ First you need to define the cryptocurrency you need:
24
+
25
+ ```ruby
26
+ require 'money'
27
+
28
+ curr = {
29
+ :priority => 1,
30
+ :iso_code => "IOT",
31
+ :name => "IOT",
32
+ :subunit => "IOT",
33
+ :subunit_to_unit => 1,
34
+ }
35
+ Money::Currency.register(curr)
36
+ ```
37
+
38
+ Initialize the bank, and call `exchange_to` as you normally would.
39
+
40
+ ```ruby
41
+ require 'money/bank/cryptocompare'
42
+ bank = Money::Bank::Cryptocompare.new
43
+ bank.exchange_with(Money.new(100_000_000,'BTC'), 'IOT')
44
+
45
+ # Set default bank to allow auto currency conversion
46
+ Money.default_bank = bank
47
+ Money.new(100_000_000,'BTC').exchange_to('IOT')
48
+ ```
49
+
50
+ Cryptocompare offers some options, such as using specific exchange for rate lookup. This can be set when initializing the bank:
51
+
52
+ ```ruby
53
+ Money::Bank::Cryptocompare.new(options: {'e' => 'Kraken'})
54
+ ```
55
+
56
+ A list of supported exchanges are listed [here](https://github.com/alexanderdavidpan/cryptocompare#supported-exchanges).
57
+
58
+ If we want to set a rates store, pass it with the `:rates_store` key (different to standard bank method signature):
59
+
60
+ ```ruby
61
+ Money::Bank::Cryptocompare.new(rates_store: rates_store)
62
+ ```
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "money/bank/cryptocompare"
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ require "money"
2
+ require "cryptocompare"
3
+
4
+ class Money
5
+ module Bank
6
+ class Cryptocompare < VariableExchange
7
+ def initialize(rates_store: nil, options: {}, &block)
8
+ @cyptocompare_options = options
9
+
10
+ rates_store ||= Money::RatesStore::Memory.new
11
+ super(rates_store, &block)
12
+ end
13
+
14
+ def get_rate(from, to, opts = {})
15
+ rate = super
16
+
17
+ if rate
18
+ rate
19
+ else
20
+ # Fetch exchange rate
21
+ info = ::Cryptocompare::Price.find(from, to, @cyptocompare_options)
22
+ if info["Response"] == "Error"
23
+ return nil
24
+ end
25
+ add_rate(from, to, info[from.to_s][to.to_s])
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "money-bank-cryptocompare"
6
+ spec.version = "0.1.0"
7
+ spec.license = 'MIT'
8
+ spec.authors = ["lulalala"]
9
+ spec.email = ["mark@goodlife.tw"]
10
+
11
+ spec.summary = %q{Money Bank for fetch cryptocurrency exchange rates from Cryptocompare}
12
+ spec.description = %q{Money gem's Bank implementation to Cryptocompare API to do cryptocurrency exchange, like converting Bitcoin to Ethereum.}
13
+ spec.homepage = "https://github.com/lulalala/money-bank-cryptocompare"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'money'
23
+ spec.add_dependency 'cryptocompare'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.7.0"
28
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: money-bank-cryptocompare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - lulalala
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: money
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cryptocompare
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.7.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.7.0
83
+ description: Money gem's Bank implementation to Cryptocompare API to do cryptocurrency
84
+ exchange, like converting Bitcoin to Ethereum.
85
+ email:
86
+ - mark@goodlife.tw
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/money/bank/cryptocompare.rb
100
+ - money-bank-cryptocompare.gemspec
101
+ homepage: https://github.com/lulalala/money-bank-cryptocompare
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.4.5
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Money Bank for fetch cryptocurrency exchange rates from Cryptocompare
125
+ test_files: []