remitano 1.5.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.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +13 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +127 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.md +115 -0
  9. data/Rakefile +51 -0
  10. data/bin/remitano +20 -0
  11. data/lib/remitano.rb +2 -0
  12. data/lib/remitano/client.rb +98 -0
  13. data/lib/remitano/client/action_confirmations.rb +29 -0
  14. data/lib/remitano/client/coin_accounts.rb +9 -0
  15. data/lib/remitano/client/coin_collection.rb +18 -0
  16. data/lib/remitano/client/coin_withdrawals.rb +24 -0
  17. data/lib/remitano/client/collection.rb +29 -0
  18. data/lib/remitano/client/fiat_accounts.rb +9 -0
  19. data/lib/remitano/client/fiat_collection.rb +18 -0
  20. data/lib/remitano/client/helper.rb +14 -0
  21. data/lib/remitano/client/merchant_charges.rb +24 -0
  22. data/lib/remitano/client/merchant_withdrawals.rb +38 -0
  23. data/lib/remitano/client/net.rb +100 -0
  24. data/lib/remitano/client/offers.rb +21 -0
  25. data/lib/remitano/client/orders.rb +26 -0
  26. data/lib/remitano/client/public/offers.rb +18 -0
  27. data/lib/remitano/client/public/price_ladders.rb +7 -0
  28. data/lib/remitano/client/public/rates.rb +12 -0
  29. data/lib/remitano/client/trades.rb +37 -0
  30. data/lib/remitano/version.rb +3 -0
  31. data/remitano.gemspec +40 -0
  32. data/spec/client/merchant_charges_spec.rb +66 -0
  33. data/spec/client/merchant_withdrawals_spec.rb +111 -0
  34. data/spec/coin_accounts_spec.rb +11 -0
  35. data/spec/fiat_accounts_spec.rb +11 -0
  36. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_charges/_create/invalid_params/raises_error.yml +51 -0
  37. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_charges/_create/valid_params/returns_created_charge.yml +53 -0
  38. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_charges/_get/object_exists/returns_charge_data.yml +48 -0
  39. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_charges/_get/object_not_found/raises_error.yml +46 -0
  40. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_withdrawals/_create/invalid_params/raises_error.yml +52 -0
  41. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_withdrawals/_create/valid_params/auto_confirms_withdrawal_with_htop_and_returns_created_withdrawal.yml +296 -0
  42. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_withdrawals/_get/object_exists/returns_withdrawal_data.yml +48 -0
  43. data/spec/fixtures/vcr_cassettes/Remitano_Client_merchant_withdrawals/_get/object_not_found/raises_error.yml +46 -0
  44. data/spec/fixtures/vcr_cassettes/remitano/coin_accounts/me.yml +52 -0
  45. data/spec/fixtures/vcr_cassettes/remitano/fiat_accounts/me.yml +52 -0
  46. data/spec/fixtures/vcr_cassettes/remitano/my_offers/sell.yml +47 -0
  47. data/spec/fixtures/vcr_cassettes/remitano/offers/update.yml +94 -0
  48. data/spec/fixtures/vcr_cassettes/remitano/orders/cancel.yml +54 -0
  49. data/spec/fixtures/vcr_cassettes/remitano/orders/create.yml +54 -0
  50. data/spec/fixtures/vcr_cassettes/remitano/orders/open.yml +54 -0
  51. data/spec/fixtures/vcr_cassettes/remitano/price_ladders/sell.yml +48 -0
  52. data/spec/fixtures/vcr_cassettes/remitano/rates.yml +44 -0
  53. data/spec/fixtures/vcr_cassettes/remitano/trades/active.yml +46 -0
  54. data/spec/fixtures/vcr_cassettes/remitano/trades/completed.yml +46 -0
  55. data/spec/fixtures/vcr_cassettes/remitano/trades/release.yml +144 -0
  56. data/spec/offers_spec.rb +18 -0
  57. data/spec/orders_spec.rb +29 -0
  58. data/spec/public/price_ladders_spec.rb +11 -0
  59. data/spec/public/rates_spec.rb +10 -0
  60. data/spec/spec_helper.rb +25 -0
  61. data/spec/support/crendentials.rb +12 -0
  62. data/spec/support/request_usec.rb +5 -0
  63. data/spec/support/vcr.rb +22 -0
  64. data/spec/trades_spec.rb +39 -0
  65. metadata +329 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cc18e45f3fa565aa6a5774ee2c1b1323f11d139d1197b8a1bc925f980161db63
4
+ data.tar.gz: 51d916c445864a89814f45c028f23d3d6775ea03cd66e7e22e411509fa86bb39
5
+ SHA512:
6
+ metadata.gz: a5dbcd371e79dc2c94f460c82e21c5279f1631a7af40f5ac88be9e7e9bf1bfa65f19cde2bd0f7a2df5cd108a4e86bd01e12b9b5ac1b7f319a3ec10761280e5c6
7
+ data.tar.gz: d62b97089efb0d17f6cd1476d330b4d590ee40b00930b926c7fb323cadf5d9c5e7b1d3198c68dc1530a0c0f001e6cfdfa22d3582abd92c614c6f84be116da50f
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .env
2
+ tags
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ Style/StringLiterals:
2
+ EnforcedStyle: double_quotes
3
+
4
+ Style/Documentation:
5
+ Enabled: false
6
+
7
+ Style/ClassAndModuleChildren:
8
+ Enabled: false
9
+
10
+ Layout/LineLength:
11
+ Max: 120
12
+
13
+
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "http://rubygems.org"
4
+ gemspec
5
+
6
+ gem "rubocop", require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,127 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ remitano (1.5.0)
5
+ activesupport (>= 4.2.10)
6
+ api-auth (~> 2.1.0)
7
+ hashie
8
+ rest-client (>= 1.7.3)
9
+ rotp
10
+ ruby-hmac (= 0.4.0)
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ activesupport (5.2.5)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
20
+ addressable (2.5.2)
21
+ public_suffix (>= 2.0.2, < 4.0)
22
+ api-auth (2.1.0)
23
+ ast (2.4.0)
24
+ byebug (3.5.1)
25
+ columnize (~> 0.8)
26
+ debugger-linecache (~> 1.2)
27
+ slop (~> 3.6)
28
+ columnize (0.9.0)
29
+ concurrent-ruby (1.1.8)
30
+ crack (0.4.3)
31
+ safe_yaml (~> 1.0.0)
32
+ debugger-linecache (1.2.0)
33
+ diff-lcs (1.3)
34
+ domain_name (0.5.20190701)
35
+ unf (>= 0.0.5, < 1.0.0)
36
+ dotenv (2.0.0)
37
+ git (1.2.5)
38
+ hashdiff (0.3.7)
39
+ hashie (4.1.0)
40
+ http-cookie (1.0.3)
41
+ domain_name (~> 0.5)
42
+ i18n (1.8.10)
43
+ concurrent-ruby (~> 1.0)
44
+ jaro_winkler (1.5.1)
45
+ jeweler (1.8.4)
46
+ bundler (~> 1.0)
47
+ git (>= 1.2.5)
48
+ rake
49
+ rdoc
50
+ json (1.8.6)
51
+ mime-types (3.2.2)
52
+ mime-types-data (~> 3.2015)
53
+ mime-types-data (3.2018.0812)
54
+ minitest (5.14.4)
55
+ netrc (0.11.0)
56
+ parallel (1.12.1)
57
+ parser (2.5.3.0)
58
+ ast (~> 2.4.0)
59
+ powerpack (0.1.2)
60
+ public_suffix (3.0.2)
61
+ rainbow (3.0.0)
62
+ rake (10.0.4)
63
+ rdoc (3.12.2)
64
+ json (~> 1.4)
65
+ rest-client (2.0.2)
66
+ http-cookie (>= 1.0.2, < 2.0)
67
+ mime-types (>= 1.16, < 4.0)
68
+ netrc (~> 0.8)
69
+ rotp (6.2.0)
70
+ rspec (3.8.0)
71
+ rspec-core (~> 3.8.0)
72
+ rspec-expectations (~> 3.8.0)
73
+ rspec-mocks (~> 3.8.0)
74
+ rspec-core (3.8.0)
75
+ rspec-support (~> 3.8.0)
76
+ rspec-expectations (3.8.1)
77
+ diff-lcs (>= 1.2.0, < 2.0)
78
+ rspec-support (~> 3.8.0)
79
+ rspec-mocks (3.8.0)
80
+ diff-lcs (>= 1.2.0, < 2.0)
81
+ rspec-support (~> 3.8.0)
82
+ rspec-support (3.8.0)
83
+ rubocop (0.60.0)
84
+ jaro_winkler (~> 1.5.1)
85
+ parallel (~> 1.10)
86
+ parser (>= 2.5, != 2.5.1.1)
87
+ powerpack (~> 0.1)
88
+ rainbow (>= 2.2.2, < 4.0)
89
+ ruby-progressbar (~> 1.7)
90
+ unicode-display_width (~> 1.4.0)
91
+ ruby-hmac (0.4.0)
92
+ ruby-progressbar (1.10.0)
93
+ safe_yaml (1.0.4)
94
+ slop (3.6.0)
95
+ thor (0.20.0)
96
+ thread_safe (0.3.6)
97
+ tzinfo (1.2.9)
98
+ thread_safe (~> 0.1)
99
+ unf (0.1.4)
100
+ unf_ext
101
+ unf_ext (0.0.7.7)
102
+ unicode-display_width (1.4.0)
103
+ vcr (4.0.0)
104
+ webmock (3.3.0)
105
+ addressable (>= 2.3.6)
106
+ crack (>= 0.3.2)
107
+ hashdiff
108
+
109
+ PLATFORMS
110
+ ruby
111
+
112
+ DEPENDENCIES
113
+ bundler
114
+ byebug
115
+ dotenv (~> 2.0.0)
116
+ jeweler (~> 1.8.4)
117
+ rdoc (~> 3.12)
118
+ remitano!
119
+ rspec
120
+ rspec-mocks (>= 3.8)
121
+ rubocop
122
+ thor
123
+ vcr (~> 4.0.0)
124
+ webmock (~> 3.3.0)
125
+
126
+ BUNDLED WITH
127
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Kojn
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # Remitano Ruby API Client
2
+
3
+ Feel free to fork, modify & redistribute under the MIT license.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+ ```
9
+ gem 'remitano'
10
+ ```
11
+ Then execute:
12
+ ```
13
+ bundle install
14
+ ```
15
+ Or install it yourself as:
16
+ ```
17
+ gem install remitano
18
+ ```
19
+
20
+ ## Usage
21
+ ### Create API Key
22
+
23
+ Visit https://remitano.com/settings/api_key to create API key.
24
+
25
+ ### Get Authentiator secret
26
+
27
+ Visit https://remitano.com/settings/authenticator to get your authenticator secret.
28
+
29
+ Note: This is needed to perform actions which need 2FA authentication like withdrawals, otherwise, you won't need it.
30
+ ### Setup Remitano client
31
+
32
+ ```ruby
33
+ Remitano::Client.default_key = YOUR_API_KEY
34
+ Remitano::Client.default_secret = YOUR_API_SECRET
35
+ Remitano::Client.default_authenticator_secret = YOUR_AUTHENTICATOR_SECRET
36
+ Remitano::Client.default # => the default client
37
+ ```
38
+ or
39
+ ```ruby
40
+ client = new Remitano::Client(
41
+ key: YOUR_API_KEY,
42
+ secret: YOUR_API_SECRET,
43
+ authenticator_secret: YOUR_AUTHENTICATOR_SECRET,
44
+ )
45
+
46
+ ```
47
+ ### Payment gateway
48
+ Visit https://developers.remitano.com/api-explorer - Merchant section for more information.
49
+ #### Charges
50
+ ##### Get
51
+ ```ruby
52
+ client.merchant_charges.get(id)
53
+ ```
54
+ ##### Create
55
+ ```ruby
56
+ client.merchant_charges.create(
57
+ coin_currency: "usdt",
58
+ coin_amount: 10.99,
59
+ cancelled_or_completed_callback_url: "https://example.com/payments/callback?id=example"
60
+ )
61
+ ```
62
+ Note: For now, we only support `usdt` as the price coin currency.
63
+
64
+ #### Withdrawals
65
+ ##### Get
66
+ ```ruby
67
+ client.merchant_withdrawals.get(id)
68
+ ```
69
+ ##### Create
70
+ 1. Withdraw to external coin address
71
+ ```ruby
72
+ client.merchant_withdrawals.create(
73
+ merchant_withdrawal_ref: "akh9r1h29e1", # your withdrawal_ref, we won't process withdrawal if the same ref is submitted before
74
+ coin_currency: "xrp",
75
+ coin_amount: 10.99,
76
+ receiver_pay_fee: true, # defines who will be charged for the withdrawal fee
77
+ cancelled_or_completed_callback_url: "http://sample.com/123/callback",
78
+ coin_address: "rLpumSZQNJ6Cve7hfQcdkG9rJbJhkSV8AD0",
79
+ destination_tag: 1710676231 # include destination_tag if coin_currency is xrp, otherwise, leave it nil
80
+ )
81
+ ```
82
+ 2. Withdraw to other remitano account
83
+ ```ruby
84
+ client.merchant_withdrawals.create(
85
+ merchant_withdrawal_ref: "akh9r1h29e1", # your withdrawal_ref, we won't process withdrawal if the same ref is submitted before
86
+ coin_currency: "xrp",
87
+ coin_amount: 10.99,
88
+ receiver_pay_fee: true,
89
+ cancelled_or_completed_callback_url: "http://sample.com/123/callback",
90
+ remitano_username: "receiver123",
91
+ remitano_phone_number: "+234 1 123 4567"
92
+ )
93
+ ```
94
+
95
+ #### Callbacks
96
+ When Charge or Withdrawal is changed to completed or cancelled in our system, we will send
97
+ a POST callback request to `object.cancelled_or_completed_callback_url` with following
98
+ request json body:
99
+ ```ruby
100
+ { "id" => object.id }
101
+ ```
102
+ then you could call `client.merchant_charges.get(id)` or `client.merchant_withdrawals.get(id)`
103
+ to get the updated information and process accordingly.
104
+
105
+ ### Errors
106
+ When receiving non 200-299 http code, a Remitano::Client::Request::RequestError will be raised.
107
+
108
+ ## Contributing
109
+
110
+ 1. Fork it
111
+ 2. Create your feature branch (`git checkout -b
112
+ my-new-feature`)
113
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
114
+ 4. Push to the branch (`git push origin my-new-feature`)
115
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ require "bundler/gem_tasks"
6
+
7
+ begin
8
+ Bundler.setup(:default, :development)
9
+ rescue Bundler::BundlerError => e
10
+ $stderr.puts e.message
11
+ $stderr.puts "Run `bundle install` to install missing gems"
12
+ exit e.status_code
13
+ end
14
+ require 'rake'
15
+
16
+ require 'jeweler'
17
+ Jeweler::Tasks.new do |gem|
18
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
19
+ gem.name = "remitano"
20
+ gem.homepage = "http://github.com/phuongnd08/remitano-ruby"
21
+ gem.license = "MIT"
22
+ gem.summary = %Q{Remitano Ruby API}
23
+ gem.description = %Q{Ruby API for use with Remitano.}
24
+ gem.email = "phuongnd08@gmail.com"
25
+ gem.authors = ["Phuong Gia Su"]
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "remitano #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/bin/remitano ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "thor"
4
+ require "remitano"
5
+ require "dotenv"
6
+ require "byebug"
7
+
8
+ Dotenv.load
9
+
10
+ Remitano.key = ENV["REMITANO_KEY"]
11
+ Remitano.secret = ENV["REMITANO_SECRET"]
12
+
13
+ class RemitanoCLI < Thor
14
+ desc "fetch-balance COIN", "Fetch your COIN balance"
15
+ def fetch_balance(coin)
16
+ puts "#{coin.upcase} balance: #{Remitano::Client.default.coin_accounts(coin).me.main.available_balance}"
17
+ end
18
+ end
19
+
20
+ RemitanoCLI.start(ARGV)
data/lib/remitano.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'remitano/version'
2
+ require 'remitano/client'
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+ require 'active_support/core_ext'
5
+ require 'active_support/inflector'
6
+ require 'rest_client'
7
+ require 'hmac-sha2'
8
+ require 'hashie'
9
+ require 'rotp'
10
+
11
+ String.send(:include, ActiveSupport::Inflector)
12
+
13
+ module Remitano
14
+ class Client
15
+ class << self
16
+ attr_accessor :default_key, :default_secret, :default_authenticator_secret, :default_verbose
17
+ def default
18
+ @default ||= new(key: default_key, secret: default_secret, authenticator_secret: default_authenticator_secret, verbose: default_verbose)
19
+ end
20
+ end
21
+
22
+ attr_accessor :key, :secret, :authenticator_secret, :verbose
23
+
24
+ def initialize(key:, secret:, authenticator_secret: nil, verbose: false)
25
+ self.key = key
26
+ self.secret = secret
27
+ self.authenticator_secret = authenticator_secret
28
+ self.verbose = verbose
29
+ end
30
+
31
+ def authenticator_token
32
+ ROTP::TOTP.new(authenticator_secret).now
33
+ end
34
+
35
+ def hotp(otp_counter)
36
+ ROTP::HOTP.new(authenticator_secret).at(otp_counter)
37
+ end
38
+
39
+ def net
40
+ @net ||= Remitano::Client::Net.new(config: self)
41
+ end
42
+
43
+ def action_confirmations
44
+ @action_confirmations ||= ActionConfirmations.new(config: self)
45
+ end
46
+
47
+ def coin_accounts(coin)
48
+ @coin_accounts ||= {}
49
+ @coin_accounts[coin] ||= CoinAccounts.new(coin, config: self)
50
+ end
51
+
52
+ def fiat_accounts(currency)
53
+ @fiat_accounts ||= {}
54
+ @fiat_accounts[currency] ||= FiatAccounts.new(currency, config: self)
55
+ end
56
+
57
+ def offers(coin)
58
+ @offers ||= {}
59
+ @offers[coin] ||= Offers.new(coin, config: self)
60
+ end
61
+
62
+ def trades(coin)
63
+ @trades ||= {}
64
+ @trades[coin] ||= Trades.new(coin, config: self)
65
+ end
66
+
67
+ def coin_withdrawals(coin)
68
+ @coin_withdrawals ||= CoinWithdrawals.new(coin, config: self)
69
+ end
70
+
71
+ def orders
72
+ @orders ||= Orders.new(config: self)
73
+ end
74
+
75
+ def rates
76
+ @rates ||= Rates.new
77
+ end
78
+
79
+ def public_offers(coin)
80
+ @public_offers ||= {}
81
+ @public_offers[coin] ||= PublicOffers.new(coin)
82
+ end
83
+
84
+ def price_ladders
85
+ @price_ladders ||= PriceLadders.new
86
+ end
87
+
88
+ def merchant_charges
89
+ @merchant_charges ||= MerchantCharges.new(config: self)
90
+ end
91
+
92
+ def merchant_withdrawals
93
+ @merchant_withdrawals ||= MerchantWithdrawals.new(config: self)
94
+ end
95
+ end
96
+ end
97
+
98
+ Dir[File.expand_path("../client/**/*.rb", __FILE__)].each { |f| require f }