Skip to content

Commit

Permalink
Raise error if API key is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
laurynas committed Jun 10, 2016
1 parent 107f376 commit d650b18
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/packlink_lite/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ def with_error_handling
end

def connection(api_key)
token = api_key || PacklinkLite.config.api_key

raise(Error, 'API key is not set') unless token

@connection ||= build_connection
@connection.headers['Authorization'] = api_key || PacklinkLite.config.api_key
@connection.headers['Authorization'] = token
@connection
end

Expand Down
2 changes: 1 addition & 1 deletion lib/packlink_lite/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PacklinkLite
VERSION = '0.2.0'
VERSION = '0.2.1'
end
10 changes: 10 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
describe PacklinkLite::Client do
context 'when API key is not set' do
before do
PacklinkLite.config.api_key = nil
end

it 'raises error' do
expect { subject.get('services') }.to raise_error(PacklinkLite::Error, /API key/)
end
end

context 'when API key is not passed' do
it 'uses api key from configuration' do
stub_request(:get, 'https://apisandbox.packlink.com/v1/services')
Expand Down

0 comments on commit d650b18

Please sign in to comment.