diff --git a/.rubocop.yml b/.rubocop.yml index b493c8d..8df2355 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,3 +13,17 @@ Style/Documentation: Metrics/BlockLength: Exclude: - '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/**/*' diff --git a/lib/strike_me/api/account.rb b/lib/strike_me/api/account.rb index d2a55b7..1521ee4 100644 --- a/lib/strike_me/api/account.rb +++ b/lib/strike_me/api/account.rb @@ -2,7 +2,6 @@ module StrikeMe module API - # Factory helper object connecting the client to the models class Account include BaseClient @@ -16,14 +15,13 @@ module StrikeMe url = profile_url response = client.get url - #body = response.body.presence - #body = JSON.parse(body) if body.is_a? String - if response.success? - @profile = Profile.new response.body.merge(account: self) - else - # if you see this, something went wrong, this is test code - raise ResponseError.new(url, response.body) - end + # body = response.body.presence + # body = JSON.parse(body) if body.is_a? String + raise ResponseError.new(url, response.body) unless response.success? + + @profile = Profile.new response.body.merge(account: self) + + # if you see this, something went wrong, this is test code end def profile_url @@ -39,11 +37,9 @@ module StrikeMe return @balances if @balances.present? response = client.get 'balances' - if response.success? - @balances = Balances.new self, response.body - else - raise ResponseError.new('balances', response.body) - end + raise ResponseError.new('balances', response.body) unless response.success? + + @balances = Balances.new self, response.body end def inspect diff --git a/lib/strike_me/api/client.rb b/lib/strike_me/api/client.rb index 9d76567..132e7cb 100644 --- a/lib/strike_me/api/client.rb +++ b/lib/strike_me/api/client.rb @@ -22,7 +22,7 @@ module StrikeMe end end - #delegate :get, to: :connection + # delegate :get, to: :connection def get(...) @last_response = connection.get(...) end diff --git a/spec/strike_me/api/account_spec.rb b/spec/strike_me/api/account_spec.rb index 8dc6eda..5f27e2c 100644 --- a/spec/strike_me/api/account_spec.rb +++ b/spec/strike_me/api/account_spec.rb @@ -28,7 +28,7 @@ RSpec.describe StrikeMe::API::Account do expect(ENV).to receive(:[]).with('STRIKE_ACCOUNT_ID').and_return 'abc' 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'}) - expect{ subject.id }.to raise_error '[401, {}, ["Invalid or unspecified identity."]]' + expect { subject.id }.to raise_error '[401, {}, ["Invalid or unspecified identity."]]' end end @@ -42,22 +42,23 @@ RSpec.describe StrikeMe::API::Account do it '#to_a properly returns the attributes' do expect(subject.to_a).to eq [ { - "currency" => "BTC", - "current" => 0.00085408, - "pending" => 2.3e-05, - "outgoing" => 5.32e-06, - "reserved" => 0.00234, - "available" => 0.00085408, - "total" => 0.00085408 + 'currency' => 'BTC', + 'current' => 0.00085408, + 'pending' => 2.3e-05, + 'outgoing' => 5.32e-06, + 'reserved' => 0.00234, + 'available' => 0.00085408, + 'total' => 0.00085408 }, { - "currency" => "USDT", - "current" => 50.04, - "pending" => 40.06, - "outgoing" => 60.15, - "reserved" => 0.0, - "available" => 0.0, - "total" => 0.0 - }] + 'currency' => 'USDT', + 'current' => 50.04, + 'pending' => 40.06, + 'outgoing' => 60.15, + 'reserved' => 0.0, + 'available' => 0.0, + 'total' => 0.0 + } + ] end 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_a StrikeMe::API::Account::Balance expect(btc.attributes).to eq( - "available" => 0.00085408, - "currency" => "BTC", - "current" => 0.00085408, - "outgoing" => 5.32e-06, - "pending" => 2.3e-05, - "reserved" => 0.00234, - "total" => 0.00085408 + 'available' => 0.00085408, + 'currency' => 'BTC', + 'current' => 0.00085408, + 'outgoing' => 5.32e-06, + 'pending' => 2.3e-05, + 'reserved' => 0.00234, + 'total' => 0.00085408 ) end it 'raises error when not authorized' do 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'}) - expect{ subject }.to raise_error '[403, {}, ["Insufficient permissions."]]' + expect { subject }.to raise_error '[403, {}, ["Insufficient permissions."]]' end end end