Skip to content

Commit e707fe6

Browse files
committed
fix: last commit
1 parent 77f5025 commit e707fe6

File tree

6 files changed

+76
-5
lines changed

6 files changed

+76
-5
lines changed

lib/cryptomarket/client.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,23 @@ def delete(endpoint, params = nil)
3939
@http_manager.make_request(method: 'delete', endpoint: endpoint, params: params)
4040
end
4141

42+
# Changes the user credentials used for authentication in calls
43+
#
44+
# ==== Params
45+
# +String+ +api_key+:: The user public key used in new calls
46+
# +String+ +api_secret+:: The user secret key used in new calls
47+
4248
def change_credentials(api_key:, api_secret:)
43-
@credential_factory.change_credentials(api_key, api_secret)
49+
@http_manager.change_credentials(api_key: api_key, api_secret: api_secret)
4450
end
4551

52+
# Changes the window used in authenticated calls
53+
#
54+
# ==== Params
55+
# +Integer+ +window+:: Acceptable time between request and server execution in millis
56+
4657
def change_window(window:)
47-
@credential_factory.change_window(window)
58+
@http_manager.change_window(window: window)
4859
end
4960

5061
################

lib/cryptomarket/credentials_factory.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def build_credential_message(http_method, method, timestamp, params)
4646
not_post_params(http_method, params)
4747
end
4848
msg += timestamp
49-
msg += @window unless @window.nil?
49+
msg += @window.to_s unless @window.nil?
5050
msg
5151
end
5252

lib/cryptomarket/http_manager.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ def initialize(api_key:, api_secret:, window: nil)
3838
end
3939

4040
def change_credentials(api_key:, api_secret:)
41-
@credential_factory.change_credentials(api_key, api_secret)
41+
@credential_factory.change_credentials(api_key: api_key, api_secret: api_secret)
4242
end
4343

4444
def change_window(window:)
45-
@credential_factory.change_window(window)
45+
@credential_factory.change_window(window: window)
4646
end
4747

4848
def make_request(method:, endpoint:, params: nil, public: false)

tests/rest/change_credentials.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
require 'test/unit'
4+
require_relative '../key_loader'
5+
require_relative '../checks'
6+
require_relative '../../lib/cryptomarket/client'
7+
8+
class ChangeCredentials < Test::Unit::TestCase # rubocop:disable Style/Documentation
9+
def setup
10+
@client = Cryptomarket::Client.new api_key: KeyLoader.api_key, api_secret: KeyLoader.api_secret
11+
end
12+
13+
def test_change_credentials
14+
result = @client.get_wallet_balances
15+
assert(good_list(->(balance) { Check.good_balance(balance) }, result))
16+
17+
@client.change_credentials api_key: '', api_secret: ''
18+
begin
19+
@client.get_wallet_balances
20+
assert(false)
21+
rescue Cryptomarket::APIException
22+
nil
23+
end
24+
25+
@client.change_credentials api_key: KeyLoader.api_key, api_secret: KeyLoader.api_secret
26+
result = @client.get_wallet_balances
27+
assert(good_list(->(balance) { Check.good_balance(balance) }, result))
28+
end
29+
end

tests/rest/change_window.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
require 'test/unit'
4+
require_relative '../key_loader'
5+
require_relative '../checks'
6+
require_relative '../../lib/cryptomarket/client'
7+
8+
class ChangeWindow < Test::Unit::TestCase # rubocop:disable Style/Documentation
9+
def setup
10+
@client = Cryptomarket::Client.new api_key: KeyLoader.api_key, api_secret: KeyLoader.api_secret
11+
end
12+
13+
def test_change_window
14+
result = @client.get_wallet_balances
15+
assert(good_list(->(balance) { Check.good_balance(balance) }, result))
16+
17+
@client.change_window window: 100
18+
begin
19+
@client.get_wallet_balances
20+
assert(false)
21+
rescue Cryptomarket::APIException
22+
nil
23+
end
24+
25+
@client.change_window window: 10_000
26+
result = @client.get_wallet_balances
27+
assert(good_list(->(balance) { Check.good_balance(balance) }, result))
28+
end
29+
end

tests/rest/test_suite.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
require_relative 'spot_trading_history'
77
require_relative 'spot_trading'
88
require_relative 'wallet_management'
9+
require_relative 'change_window'
10+
require_relative 'change_credentials'

0 commit comments

Comments
 (0)