rubocop corrections
This commit is contained in:
1 parent
4b84df0af9
commit
4a7b752ace
4 files changed
+47
-36
No files matched your search
@@ -13,3 +13,17 @@ Style/Documentation:
|
|||||||
Metrics/BlockLength:
|
Metrics/BlockLength:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'spec/**/*'
|
- 'spec/**/*'
|
||||||
|
|
||||||
|
# The next 3 rubocop enabled disallow visual alignment (EasyAlign)
|
||||||
|
Layout/ExtraSpacing:
|
||||||
|
Enabled: false
|
||||||
|
Layout/HashAlignment:
|
||||||
|
Enabled: false
|
||||||
|
Layout/SpaceBeforeFirstArg:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
|
Layout/SpaceInsideHashLiteralBraces:
|
||||||
|
Enabled: false
|
||||||
|
Layout/LineLength:
|
||||||
|
Exclude:
|
||||||
|
- 'spec/**/*'
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
module StrikeMe
|
module StrikeMe
|
||||||
module API
|
module API
|
||||||
|
|
||||||
# Factory helper object connecting the client to the models
|
# Factory helper object connecting the client to the models
|
||||||
class Account
|
class Account
|
||||||
include BaseClient
|
include BaseClient
|
||||||
@@ -16,14 +15,13 @@ module StrikeMe
|
|||||||
|
|
||||||
url = profile_url
|
url = profile_url
|
||||||
response = client.get url
|
response = client.get url
|
||||||
#body = response.body.presence
|
# body = response.body.presence
|
||||||
#body = JSON.parse(body) if body.is_a? String
|
# body = JSON.parse(body) if body.is_a? String
|
||||||
if response.success?
|
raise ResponseError.new(url, response.body) unless response.success?
|
||||||
|
|
||||||
@profile = Profile.new response.body.merge(account: self)
|
@profile = Profile.new response.body.merge(account: self)
|
||||||
else
|
|
||||||
# if you see this, something went wrong, this is test code
|
# if you see this, something went wrong, this is test code
|
||||||
raise ResponseError.new(url, response.body)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def profile_url
|
def profile_url
|
||||||
@@ -39,11 +37,9 @@ module StrikeMe
|
|||||||
return @balances if @balances.present?
|
return @balances if @balances.present?
|
||||||
|
|
||||||
response = client.get 'balances'
|
response = client.get 'balances'
|
||||||
if response.success?
|
raise ResponseError.new('balances', response.body) unless response.success?
|
||||||
|
|
||||||
@balances = Balances.new self, response.body
|
@balances = Balances.new self, response.body
|
||||||
else
|
|
||||||
raise ResponseError.new('balances', response.body)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ module StrikeMe
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#delegate :get, to: :connection
|
# delegate :get, to: :connection
|
||||||
def get(...)
|
def get(...)
|
||||||
@last_response = connection.get(...)
|
@last_response = connection.get(...)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ RSpec.describe StrikeMe::API::Account do
|
|||||||
expect(ENV).to receive(:[]).with('STRIKE_ACCOUNT_ID').and_return 'abc'
|
expect(ENV).to receive(:[]).with('STRIKE_ACCOUNT_ID').and_return 'abc'
|
||||||
stub_request(:get, %r{https://api.strike.me/v1/accounts/abc/profile})
|
stub_request(:get, %r{https://api.strike.me/v1/accounts/abc/profile})
|
||||||
.to_return(status: 401, body: '{"data":{"status":401,"code":"UNAUTHORIZED","message":"Invalid or unspecified identity."}}', headers: {'Content-Type' => 'application/json'})
|
.to_return(status: 401, body: '{"data":{"status":401,"code":"UNAUTHORIZED","message":"Invalid or unspecified identity."}}', headers: {'Content-Type' => 'application/json'})
|
||||||
expect{ subject.id }.to raise_error '[401, {}, ["Invalid or unspecified identity."]]'
|
expect { subject.id }.to raise_error '[401, {}, ["Invalid or unspecified identity."]]'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -42,22 +42,23 @@ RSpec.describe StrikeMe::API::Account do
|
|||||||
it '#to_a properly returns the attributes' do
|
it '#to_a properly returns the attributes' do
|
||||||
expect(subject.to_a).to eq [
|
expect(subject.to_a).to eq [
|
||||||
{
|
{
|
||||||
"currency" => "BTC",
|
'currency' => 'BTC',
|
||||||
"current" => 0.00085408,
|
'current' => 0.00085408,
|
||||||
"pending" => 2.3e-05,
|
'pending' => 2.3e-05,
|
||||||
"outgoing" => 5.32e-06,
|
'outgoing' => 5.32e-06,
|
||||||
"reserved" => 0.00234,
|
'reserved' => 0.00234,
|
||||||
"available" => 0.00085408,
|
'available' => 0.00085408,
|
||||||
"total" => 0.00085408
|
'total' => 0.00085408
|
||||||
}, {
|
}, {
|
||||||
"currency" => "USDT",
|
'currency' => 'USDT',
|
||||||
"current" => 50.04,
|
'current' => 50.04,
|
||||||
"pending" => 40.06,
|
'pending' => 40.06,
|
||||||
"outgoing" => 60.15,
|
'outgoing' => 60.15,
|
||||||
"reserved" => 0.0,
|
'reserved' => 0.0,
|
||||||
"available" => 0.0,
|
'available' => 0.0,
|
||||||
"total" => 0.0
|
'total' => 0.0
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
it '#btc returns the BTC balance' do
|
it '#btc returns the BTC balance' do
|
||||||
@@ -65,20 +66,20 @@ RSpec.describe StrikeMe::API::Account do
|
|||||||
expect(btc).to be_present
|
expect(btc).to be_present
|
||||||
expect(btc).to be_a StrikeMe::API::Account::Balance
|
expect(btc).to be_a StrikeMe::API::Account::Balance
|
||||||
expect(btc.attributes).to eq(
|
expect(btc.attributes).to eq(
|
||||||
"available" => 0.00085408,
|
'available' => 0.00085408,
|
||||||
"currency" => "BTC",
|
'currency' => 'BTC',
|
||||||
"current" => 0.00085408,
|
'current' => 0.00085408,
|
||||||
"outgoing" => 5.32e-06,
|
'outgoing' => 5.32e-06,
|
||||||
"pending" => 2.3e-05,
|
'pending' => 2.3e-05,
|
||||||
"reserved" => 0.00234,
|
'reserved' => 0.00234,
|
||||||
"total" => 0.00085408
|
'total' => 0.00085408
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises error when not authorized' do
|
it 'raises error when not authorized' do
|
||||||
stub_request(:get, %r{https://api.strike.me/v1/balances})
|
stub_request(:get, %r{https://api.strike.me/v1/balances})
|
||||||
.to_return(status: 401, body: '{"data":{"status":403,"code":"FORBIDDEN","message":"Insufficient permissions."}}', headers: {'Content-Type' => 'application/json'})
|
.to_return(status: 401, body: '{"data":{"status":403,"code":"FORBIDDEN","message":"Insufficient permissions."}}', headers: {'Content-Type' => 'application/json'})
|
||||||
expect{ subject }.to raise_error '[403, {}, ["Insufficient permissions."]]'
|
expect { subject }.to raise_error '[403, {}, ["Insufficient permissions."]]'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user