Skip to content

Commit 0465e91

Browse files
committed
Merge pull request #217 from intercom/BL/nils
nil check app_id and api_key
2 parents eb52c17 + bf53a88 commit 0465e91

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/intercom/client.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module Intercom
2+
class MisconfiguredClientError < StandardError; end
23
class Client
34
include Options
45
attr_reader :base_url, :rate_limit_details
@@ -16,6 +17,8 @@ def set_base_url(base_url)
1617
def initialize(app_id: 'my_app_id', api_key: 'my_api_key')
1718
@app_id = app_id
1819
@api_key = api_key
20+
validate_credentials!
21+
1922
@base_url = 'https://api.intercom.io'
2023
@rate_limit_details = {}
2124
end
@@ -90,6 +93,12 @@ def delete(path, payload_hash)
9093

9194
private
9295

96+
def validate_credentials!
97+
error = MisconfiguredClientError.new("app_id and api_key must not be nil")
98+
fail error if @app_id.nil?
99+
fail error if @api_key.nil?
100+
end
101+
93102
def execute_request(request)
94103
result = request.execute(@base_url, username: @app_id, secret: @api_key)
95104
@rate_limit_details = request.rate_limit_details

spec/unit/intercom/client_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ module Intercom
1717
client.base_url.must_equal('https://api.intercom.io')
1818
end
1919

20+
it 'should raise on nil credentials' do
21+
proc { Client.new(app_id: nil, api_key: nil) }.must_raise MisconfiguredClientError
22+
end
2023
end
2124
end

0 commit comments

Comments
 (0)