buda 0.0.0 → 0.1.4.0.4
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 +4 -4
- data/.gitignore +14 -0
- data/.rubocop.yml +6 -0
- data/.vscode/settings.json +1 -0
- data/Gemfile +10 -0
- data/Rakefile +16 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/buda.gemspec +23 -0
- data/lib/buda/client.rb +138 -0
- data/lib/buda/constants.rb +11 -0
- data/lib/buda/errors.rb +43 -0
- data/lib/buda/resources/balance.rb +24 -0
- data/lib/buda/resources/currency.rb +21 -0
- data/lib/buda/resources/deposit.rb +45 -0
- data/lib/buda/resources/deposit_data.rb +30 -0
- data/lib/buda/resources/fiat_account.rb +34 -0
- data/lib/buda/resources/market.rb +30 -0
- data/lib/buda/resources/ticker.rb +30 -0
- data/lib/buda/resources/withdrawal.rb +38 -0
- data/lib/buda/resources/withdrawal_data.rb +31 -0
- data/lib/buda/utils.rb +47 -0
- data/lib/buda/version.rb +5 -0
- data/lib/buda.rb +7 -4
- metadata +30 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdc15eb6001b9c923419a9985835dcd3e7962e4e667135066d90714e3b8038a8
|
4
|
+
data.tar.gz: 9910e867b55e96625c2dedeb573297b00cfeac86ebc4792170fcfa085a3b48ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e842e8ef9b05b581f4f733565f49bb186e580d0fcd79f3be2bb51b2aeacd1989233717639a1754a36c21180d9be14b204c44e4bc6bb948f17e74f174eb9cff2e
|
7
|
+
data.tar.gz: 77f8652261520842f9a4d22e1fa2633d565d011e755352511cebaf3f73f74799f4ddfe94ee3af210c49301027ccdc4dd455978ba8d3d1b3c685bf4b95fa86d50
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{}
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rubocop/rake_task'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'bundler/setup'
|
8
|
+
Bundler::GemHelper.install_tasks
|
9
|
+
rescue LoadError
|
10
|
+
puts 'although not required, bundler is recommended for running the tests'
|
11
|
+
end
|
12
|
+
task default: :spec
|
13
|
+
RuboCop::RakeTask.new do |task|
|
14
|
+
task.requires << 'rubocop-performance'
|
15
|
+
task.requires << 'rubocop-rspec'
|
16
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'buda'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/buda.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'buda'
|
5
|
+
s.version = '0.1.4.0.4'
|
6
|
+
s.summary = 'buda.com client'
|
7
|
+
s.description = 'A simple client for buda.com api'
|
8
|
+
s.authors = ['Alfredo Enrione']
|
9
|
+
s.email = 'aenrione@protonmail.com'
|
10
|
+
s.homepage =
|
11
|
+
'https://rubygems.org/gems/buda'
|
12
|
+
s.license = 'MIT'
|
13
|
+
s.required_ruby_version = Gem::Requirement.new('>= 2.7.3')
|
14
|
+
s.add_dependency 'http'
|
15
|
+
s.add_dependency 'json'
|
16
|
+
s.files = Dir.chdir(File.expand_path(__dir__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
end
|
19
|
+
s.bindir = 'exe'
|
20
|
+
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
s.require_paths = ['lib']
|
22
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
23
|
+
end
|
data/lib/buda/client.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'http'
|
4
|
+
require 'buda/utils'
|
5
|
+
require 'buda/errors'
|
6
|
+
require 'buda/constants'
|
7
|
+
require 'buda/version'
|
8
|
+
require 'buda/resources/balance'
|
9
|
+
require 'buda/resources/deposit'
|
10
|
+
require 'buda/resources/withdrawal'
|
11
|
+
require 'buda/resources/market'
|
12
|
+
require 'json'
|
13
|
+
require 'net/http'
|
14
|
+
require 'net/https'
|
15
|
+
|
16
|
+
module Buda
|
17
|
+
# Client component to make the requests and get data
|
18
|
+
class Client
|
19
|
+
def initialize(api_key, api_secret)
|
20
|
+
@api_key = api_key
|
21
|
+
@api_secret = api_secret
|
22
|
+
@user_agent = "buda-ruby/#{Buda::VERSION}"
|
23
|
+
@headers = {
|
24
|
+
'Content-Type': 'application/json', 'X-SBTC-APIKEY': @api_key,
|
25
|
+
'User-Agent': @user_agent
|
26
|
+
}
|
27
|
+
@default_params = {}
|
28
|
+
end
|
29
|
+
|
30
|
+
def get
|
31
|
+
request('get')
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete
|
35
|
+
request('delete')
|
36
|
+
end
|
37
|
+
|
38
|
+
def request(method)
|
39
|
+
proc do |resource, is_private, **kwargs|
|
40
|
+
parameters = params(method, **kwargs)
|
41
|
+
response = make_request(method, resource, parameters, is_private)
|
42
|
+
content = JSON.parse(response.body, symbolize_names: true)
|
43
|
+
|
44
|
+
# raise_custom_error(content[:error]) if response.status.client_error? || response.status.server_error?
|
45
|
+
|
46
|
+
content
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def balances
|
51
|
+
result = get.call('balances', true)[:balances]
|
52
|
+
balances = []
|
53
|
+
result&.each do |balance|
|
54
|
+
balances << Balance.new(**balance)
|
55
|
+
end
|
56
|
+
balances
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_balance(balance_id)
|
60
|
+
result = get.call("balances/#{balance_id}", true)[:balance]
|
61
|
+
Balance.new(**result)
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_market(market_id)
|
65
|
+
market = get.call("markets/#{market_id.upcase}")[:market]
|
66
|
+
ticker = get.call("markets/#{market_id.upcase}/ticker")[:ticker]
|
67
|
+
new_market = Market.new(**market)
|
68
|
+
new_market.set_ticker(**ticker)
|
69
|
+
new_market
|
70
|
+
end
|
71
|
+
|
72
|
+
def deposits(currency)
|
73
|
+
result = get.call("currencies/#{currency}/deposits", true)[:deposits]
|
74
|
+
deposits = []
|
75
|
+
result&.each do |deposit|
|
76
|
+
deposits << Deposit.new(**deposit)
|
77
|
+
end
|
78
|
+
deposits
|
79
|
+
end
|
80
|
+
|
81
|
+
def withdrawals(currency)
|
82
|
+
result = get.call("currencies/#{currency}/withdrawals", true)[:withdrawals]
|
83
|
+
withdrawals = []
|
84
|
+
result&.each do |withdrawal|
|
85
|
+
withdrawals << Withdrawal.new(**withdrawal)
|
86
|
+
end
|
87
|
+
withdrawals
|
88
|
+
end
|
89
|
+
|
90
|
+
def to_s
|
91
|
+
visible_chars = 4
|
92
|
+
hidden_part = '*' * (@api_key.size - visible_chars)
|
93
|
+
visible_key = @api_key.slice(0, visible_chars)
|
94
|
+
"Client(🔑=#{hidden_part + visible_key}"
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def client
|
100
|
+
@client ||= Net::HTTP
|
101
|
+
end
|
102
|
+
|
103
|
+
def make_request(method, resource, _parameters, is_private)
|
104
|
+
uri = URI.parse("#{Buda::Constants::SCHEME}#{Buda::Constants::BASE_URL}#{resource}")
|
105
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
106
|
+
https.use_ssl = true
|
107
|
+
if is_private
|
108
|
+
req = Net::HTTP::Get.new(uri.path, @headers)
|
109
|
+
req['X-SBTC-SIGNATURE'] = sign(method.upcase, uri.path, '')
|
110
|
+
req['X-SBTC-NONCE'] = nonce
|
111
|
+
else
|
112
|
+
req = Net::HTTP::Get.new(uri.path)
|
113
|
+
end
|
114
|
+
https.request(req)
|
115
|
+
end
|
116
|
+
|
117
|
+
def params(method, **kwargs)
|
118
|
+
if method == 'get'
|
119
|
+
{ params: { **@default_params, **kwargs } }
|
120
|
+
else
|
121
|
+
{ json: { **@default_params, **kwargs } }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def raise_custom_error(error)
|
126
|
+
raise error_class(error[:code]).new(error[:message], error[:doc_url])
|
127
|
+
end
|
128
|
+
|
129
|
+
def nonce
|
130
|
+
(Time.now.to_i * (10**6)).to_s
|
131
|
+
end
|
132
|
+
|
133
|
+
def sign(method, path, _body)
|
134
|
+
prep = "#{method} #{path} #{nonce}"
|
135
|
+
OpenSSL::HMAC.hexdigest('SHA384', @api_secret, prep)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Constant values for the client
|
4
|
+
module Buda
|
5
|
+
module Constants
|
6
|
+
FIELDSUBS = [%w[id id_], %w[type type_]].freeze
|
7
|
+
GENERAL_DOC_URL = 'https://api.buda.com/'
|
8
|
+
SCHEME = 'https://'
|
9
|
+
BASE_URL = 'www.buda.com/api/v2/'
|
10
|
+
end
|
11
|
+
end
|
data/lib/buda/errors.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'buda/constants'
|
4
|
+
|
5
|
+
module Buda
|
6
|
+
module Errors
|
7
|
+
# Error definitions for handling wrong requests
|
8
|
+
class BudaError < StandardError
|
9
|
+
def initialize(message, doc_url = Buda::Constants::GENERAL_DOC_URL)
|
10
|
+
super()
|
11
|
+
@message = message
|
12
|
+
@doc_url = doc_url
|
13
|
+
end
|
14
|
+
|
15
|
+
def message
|
16
|
+
"\n#{@message}\n Please check the docs at: #{@doc_url}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
message
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class InvalidRequestError < BudaError; end
|
25
|
+
class LinkError < BudaError; end
|
26
|
+
class AuthenticationError < BudaError; end
|
27
|
+
class InstitutionError < BudaError; end
|
28
|
+
class ApiError < BudaError; end
|
29
|
+
class MissingResourceError < BudaError; end
|
30
|
+
class InvalidLinkTokenError < BudaError; end
|
31
|
+
class InvalidUsernameError < BudaError; end
|
32
|
+
class InvalidHolderTypeError < BudaError; end
|
33
|
+
class MissingParameterError < BudaError; end
|
34
|
+
class EmptyStringError < BudaError; end
|
35
|
+
class UnrecognizedRequestError < BudaError; end
|
36
|
+
class InvalidDateError < BudaError; end
|
37
|
+
class InvalidCredentialsError < BudaError; end
|
38
|
+
class LockedCredentialsError < BudaError; end
|
39
|
+
class InvalidApiKeyError < BudaError; end
|
40
|
+
class UnavailableInstitutionError < BudaError; end
|
41
|
+
class InternalServerError < BudaError; end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buda
|
4
|
+
# for handling the total balance
|
5
|
+
class Balance
|
6
|
+
attr_reader :id, :available, :current, :frozen, :pending
|
7
|
+
|
8
|
+
def initialize(id:, available_amount:, amount:, frozen_amount:, pending_withdraw_amount:, **)
|
9
|
+
@id = id
|
10
|
+
@available = available_amount[0]
|
11
|
+
@current = amount[0]
|
12
|
+
@frozen = frozen_amount[0]
|
13
|
+
@pending = pending_withdraw_amount[0]
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"#{id}: #{@current} (#{@available})"
|
18
|
+
end
|
19
|
+
|
20
|
+
def inspect
|
21
|
+
"<Balance #{@current} (#{@available})>"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buda
|
4
|
+
# Client component to make the requests and get data
|
5
|
+
class Client
|
6
|
+
attr_reader :id, :amount
|
7
|
+
|
8
|
+
def initialize(id, amount)
|
9
|
+
@id = id
|
10
|
+
@amount = amount
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"#{@amount} (#{@id})"
|
15
|
+
end
|
16
|
+
|
17
|
+
def inspect
|
18
|
+
"<Currency #{@amount} (#{@id})>"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'deposit_data'
|
4
|
+
|
5
|
+
module Buda
|
6
|
+
# for handling deposited amount
|
7
|
+
class Deposit
|
8
|
+
attr_reader :id, :created_at, :amount, :currency,
|
9
|
+
:fee, :state, :deposit_data, :account_id,
|
10
|
+
:user_id, :order_id, :order_type, :state_reason,
|
11
|
+
:expected_arrival_time, :reserve_name, :reserve_code
|
12
|
+
|
13
|
+
def initialize(
|
14
|
+
id:, created_at:, amount:, currency:,
|
15
|
+
fee:, state:, account_id:, user_id:,
|
16
|
+
order_id:, order_type:, state_reason:,
|
17
|
+
expected_arrival_time:, reserve_name:, reserve_code:,
|
18
|
+
deposit_data:, **
|
19
|
+
)
|
20
|
+
@id = id
|
21
|
+
@created_at = created_at
|
22
|
+
@amount = amount[0]
|
23
|
+
@currency = currency
|
24
|
+
@fee = fee
|
25
|
+
@state = state
|
26
|
+
@account_id = account_id
|
27
|
+
@user_id = user_id
|
28
|
+
@order_id = order_id
|
29
|
+
@order_type = order_type
|
30
|
+
@state_reason = state_reason
|
31
|
+
@expected_arrival_time = expected_arrival_time
|
32
|
+
@reserve_name = reserve_name
|
33
|
+
@reserve_code = reserve_code
|
34
|
+
@deposit_data = DepositData.new(**deposit_data)
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
"#{@amount} (#{@currency})"
|
39
|
+
end
|
40
|
+
|
41
|
+
def inspect
|
42
|
+
"<Deposit #{@amount} (#{@currency})>"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buda
|
4
|
+
# for handling deposit_data of Deposit Class
|
5
|
+
class DepositData
|
6
|
+
attr_reader :type, :upload_url, :created_at, :update_at,
|
7
|
+
:tx_hash, :address, :method
|
8
|
+
|
9
|
+
def initialize(
|
10
|
+
type:, upload_url:, created_at:,
|
11
|
+
updated_at:, **kwargs
|
12
|
+
)
|
13
|
+
@type = type
|
14
|
+
@upload_url = upload_url
|
15
|
+
@created_at = created_at
|
16
|
+
@updated_at = updated_at
|
17
|
+
@method = kwargs[:method]
|
18
|
+
@address = kwargs[:address]
|
19
|
+
@tx_hash = kwargs[:tx_hash]
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
"#{@type} (#{@created_at.to_date})"
|
24
|
+
end
|
25
|
+
|
26
|
+
def inspect
|
27
|
+
"<DepositData #{@type} (#{@created_at.to_date})>"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buda
|
4
|
+
# for handling the total balance
|
5
|
+
class FiatAccount
|
6
|
+
attr_reader :id, :account_number, :created_at, :account_type,
|
7
|
+
:currency
|
8
|
+
|
9
|
+
def initialize(**kwargs)
|
10
|
+
@id = kwargs[:id]
|
11
|
+
@account_number = kwargs[:account_number]
|
12
|
+
@created_at = kwargs[:created_at]
|
13
|
+
@account_type = kwargs[:account_type]
|
14
|
+
@bank_id = kwargs[:bank_id]
|
15
|
+
@currency = kwargs[:currency]
|
16
|
+
@document_number = kwargs[:document_number]
|
17
|
+
@email = kwargs[:email]
|
18
|
+
@phone = kwargs[:phone]
|
19
|
+
@national_number_identifier = kwargs[:national_number_identifier]
|
20
|
+
@bank_name = kwargs[:bank_name]
|
21
|
+
@updated_at = kwargs[:updated_at]
|
22
|
+
@inter_bank_number = kwargs[:inter_bank_number]
|
23
|
+
@source_account = kwargs[:source_account]
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
"#{@bank_name} (#{@account_number})"
|
28
|
+
end
|
29
|
+
|
30
|
+
def inspect
|
31
|
+
"<FiatAccount #{@bank_name} (#{@account_number})>"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'ticker'
|
4
|
+
|
5
|
+
module Buda
|
6
|
+
# for handling the total balance
|
7
|
+
class Market
|
8
|
+
attr_reader :id, :name, :base_currency, :quote_currency, :minimum_order_amount, :ticker
|
9
|
+
|
10
|
+
def initialize(id:, name:, base_currency:, quote_currency:, minimum_order_amount:, **)
|
11
|
+
@id = id
|
12
|
+
@name = name
|
13
|
+
@base_currency = base_currency
|
14
|
+
@quote_currency = quote_currency
|
15
|
+
@minimum_order_amount = minimum_order_amount
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_ticker(**ticker)
|
19
|
+
@ticker = Buda::Ticker.new(**ticker)
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
"#{@name} (#{@id})"
|
24
|
+
end
|
25
|
+
|
26
|
+
def inspect
|
27
|
+
"<Market #{@name} (#{@id})>"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buda
|
4
|
+
# for handling the total balance
|
5
|
+
class Ticker
|
6
|
+
attr_reader :market_id, :last_price, :min_ask, :volume,
|
7
|
+
:max_bid, :price_variation_7d, :price_variation_24h
|
8
|
+
|
9
|
+
def initialize(market_id:,
|
10
|
+
last_price:, min_ask:,
|
11
|
+
max_bid:, volume:,
|
12
|
+
price_variation_24h:, price_variation_7d:, **)
|
13
|
+
@market_id = market_id
|
14
|
+
@last_price = last_price[0]
|
15
|
+
@min_ask = min_ask
|
16
|
+
@max_bid = max_bid
|
17
|
+
@price_variation_24h = price_variation_24h
|
18
|
+
@volume = volume
|
19
|
+
@price_variation_7d = price_variation_7d
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
"#{@market_id} (#{@last_price})"
|
24
|
+
end
|
25
|
+
|
26
|
+
def inspect
|
27
|
+
"<Ticker #{@market_id} (#{@last_price})>"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'withdrawal_data'
|
4
|
+
|
5
|
+
module Buda
|
6
|
+
# for handling the total balance
|
7
|
+
class Withdrawal
|
8
|
+
attr_reader :id, :created_at, :amount, :currency,
|
9
|
+
:fee, :state, :deposit_data, :account_id,
|
10
|
+
:user_id, :order_id, :order_type, :state_reason,
|
11
|
+
:expected_arrival_time, :reserve_name, :reserve_code
|
12
|
+
|
13
|
+
def initialize(**kwargs)
|
14
|
+
@id = kwargs[:id]
|
15
|
+
@uuid = kwargs[:uuid]
|
16
|
+
@currency = kwargs[:currency]
|
17
|
+
@created_at = kwargs[:created_at]
|
18
|
+
@forced_reason = kwargs[:forced_reason]
|
19
|
+
@account_id = kwargs[:account_id]
|
20
|
+
@user_id = kwargs[:user_id]
|
21
|
+
@expected_execution_time = kwargs[:expected_execution_time]
|
22
|
+
@expected_arrival_time = kwargs[:expected_arrival_time]
|
23
|
+
@hold_execution = kwargs[:hold_execution]
|
24
|
+
@amount = kwargs[:amount][0]
|
25
|
+
@fee = kwargs[:fee]
|
26
|
+
@usd_amount = kwargs[:usd_amount]
|
27
|
+
@deposit_data = WithdrawalData.new(**kwargs[:withdrawal_data])
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
"#{@amount} (#{@currency})"
|
32
|
+
end
|
33
|
+
|
34
|
+
def inspect
|
35
|
+
"<Withdrawal #{@amount} (#{@currency})>"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'buda/resources/fiat_account'
|
4
|
+
|
5
|
+
module Buda
|
6
|
+
# for handling the total balance
|
7
|
+
class WithdrawalData
|
8
|
+
attr_reader :type, :id, :created_at, :update_at,
|
9
|
+
:tx_hash, :target_address, :statement_ref,
|
10
|
+
:fiat_account
|
11
|
+
|
12
|
+
def initialize(**kwargs)
|
13
|
+
@type = kwargs[:type]
|
14
|
+
@id = kwargs[:id]
|
15
|
+
@statement_ref = kwargs[:statement_ref]
|
16
|
+
@created_at = kwargs[:created_at]
|
17
|
+
@updated_at = kwargs[:updated_at]
|
18
|
+
@target_address = kwargs[:target_address]
|
19
|
+
@tx_hash = kwargs[:tx_hash]
|
20
|
+
@fiat_account = FiatAccount.new(**kwargs[:fiat_account]) if kwargs[:fiat_account]
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
"#{@type} (#{@created_at})"
|
25
|
+
end
|
26
|
+
|
27
|
+
def inspect
|
28
|
+
"<WithdrawalData #{@type} (#{@created_at})>"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/buda/utils.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buda
|
4
|
+
# A handful of run-of-the-mill utilities
|
5
|
+
module Utils
|
6
|
+
module_function
|
7
|
+
|
8
|
+
# Get a flat Array out of a list of lists of Iterables(Enumerators)
|
9
|
+
#
|
10
|
+
def flatten(sequences)
|
11
|
+
Enumerator::Chain.new(*sequences).to_a
|
12
|
+
end
|
13
|
+
|
14
|
+
# If the key exists, you will get that key-value pair.
|
15
|
+
#
|
16
|
+
# @param dict_ [Hash] the hash to pick from
|
17
|
+
# @param key [String] the key to look at
|
18
|
+
# @return [Hash] the key-value pair or an empty hash
|
19
|
+
def pick(dict_, key)
|
20
|
+
key = key.to_sym
|
21
|
+
if dict_.key?(key)
|
22
|
+
{ "#{key}": dict_[key] }
|
23
|
+
else
|
24
|
+
{}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get a pluralized noun with its appropiate quantifier
|
29
|
+
#
|
30
|
+
# @param amount [Integer]
|
31
|
+
# @param noun [String] the noun to pluralize
|
32
|
+
# @param suffix [String]
|
33
|
+
# @return [String]
|
34
|
+
def pluralize(amount, noun, suffix = 's')
|
35
|
+
quantifier = amount or 'no'
|
36
|
+
"#{quantifier} #{amount == 1 ? noun : noun + suffix}"
|
37
|
+
end
|
38
|
+
|
39
|
+
# Transform a snake-cased name to its pascal-cased version.
|
40
|
+
#
|
41
|
+
# @param name [String]
|
42
|
+
# @return [String]
|
43
|
+
def snake_to_pascal(name)
|
44
|
+
name.split('_').map(&:capitalize).join
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/buda/version.rb
ADDED
data/lib/buda.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.1.4.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alfredo Enrione
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01
|
11
|
+
date: 2022-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -38,17 +38,40 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description: A simple
|
41
|
+
description: A simple client for buda.com api
|
42
42
|
email: aenrione@protonmail.com
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
+
- ".gitignore"
|
48
|
+
- ".rubocop.yml"
|
49
|
+
- ".vscode/settings.json"
|
50
|
+
- Gemfile
|
51
|
+
- Rakefile
|
52
|
+
- bin/console
|
53
|
+
- bin/setup
|
54
|
+
- buda.gemspec
|
47
55
|
- lib/buda.rb
|
56
|
+
- lib/buda/client.rb
|
57
|
+
- lib/buda/constants.rb
|
58
|
+
- lib/buda/errors.rb
|
59
|
+
- lib/buda/resources/balance.rb
|
60
|
+
- lib/buda/resources/currency.rb
|
61
|
+
- lib/buda/resources/deposit.rb
|
62
|
+
- lib/buda/resources/deposit_data.rb
|
63
|
+
- lib/buda/resources/fiat_account.rb
|
64
|
+
- lib/buda/resources/market.rb
|
65
|
+
- lib/buda/resources/ticker.rb
|
66
|
+
- lib/buda/resources/withdrawal.rb
|
67
|
+
- lib/buda/resources/withdrawal_data.rb
|
68
|
+
- lib/buda/utils.rb
|
69
|
+
- lib/buda/version.rb
|
48
70
|
homepage: https://rubygems.org/gems/buda
|
49
71
|
licenses:
|
50
72
|
- MIT
|
51
|
-
metadata:
|
73
|
+
metadata:
|
74
|
+
rubygems_mfa_required: 'true'
|
52
75
|
post_install_message:
|
53
76
|
rdoc_options: []
|
54
77
|
require_paths:
|
@@ -57,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
80
|
requirements:
|
58
81
|
- - ">="
|
59
82
|
- !ruby/object:Gem::Version
|
60
|
-
version: 2.3
|
83
|
+
version: 2.7.3
|
61
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
85
|
requirements:
|
63
86
|
- - ">="
|
@@ -67,5 +90,5 @@ requirements: []
|
|
67
90
|
rubygems_version: 3.1.6
|
68
91
|
signing_key:
|
69
92
|
specification_version: 4
|
70
|
-
summary:
|
93
|
+
summary: buda.com client
|
71
94
|
test_files: []
|