Skip to content

Commit

Permalink
nil check app_id and api_key
Browse files Browse the repository at this point in the history
  • Loading branch information
bobjflong committed Jan 18, 2016
1 parent eb52c17 commit bf53a88
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/intercom/client.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module Intercom
class MisconfiguredClientError < StandardError; end
class Client
include Options
attr_reader :base_url, :rate_limit_details
Expand All @@ -16,6 +17,8 @@ def set_base_url(base_url)
def initialize(app_id: 'my_app_id', api_key: 'my_api_key')
@app_id = app_id
@api_key = api_key
validate_credentials!

@base_url = 'https://api.intercom.io'
@rate_limit_details = {}
end
Expand Down Expand Up @@ -90,6 +93,12 @@ def delete(path, payload_hash)

private

def validate_credentials!
error = MisconfiguredClientError.new("app_id and api_key must not be nil")
fail error if @app_id.nil?
fail error if @api_key.nil?
end

def execute_request(request)
result = request.execute(@base_url, username: @app_id, secret: @api_key)
@rate_limit_details = request.rate_limit_details
Expand Down
3 changes: 3 additions & 0 deletions spec/unit/intercom/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ module Intercom
client.base_url.must_equal('https://api.intercom.io')
end

it 'should raise on nil credentials' do
proc { Client.new(app_id: nil, api_key: nil) }.must_raise MisconfiguredClientError
end
end
end

0 comments on commit bf53a88

Please sign in to comment.