22
33require_relative 'auth'
44require_relative 'user_api'
5- require_relative 'error'
65require_relative 'version'
76
87module Passage
@@ -16,32 +15,25 @@ module Passage
1615 class Client
1716 attr_reader :auth , :user
1817
19- def initialize ( app_id :, api_key : '' , auth_strategy : COOKIE_STRATEGY )
20- @app_id = app_id
21- @api_key = api_key
22-
23- # check for valid auth strategy
24- unless [ COOKIE_STRATEGY , HEADER_STRATEGY ] . include? auth_strategy
25- raise PassageError . new (
26- status_code : 400 ,
27- body : {
28- error : 'Invalid auth strategy' ,
29- code : 'invalid_argument'
30- }
31- )
18+ def initialize ( app_id :, api_key :)
19+ unless app_id && !app_id . empty?
20+ raise ArgumentError ,
21+ 'A Passage App ID is required. Please include (app_id: YOUR_APP_ID, api_key: YOUR_API_KEY).'
22+ end
23+ unless api_key && !api_key . empty?
24+ raise ArgumentError ,
25+ 'A Passage API key is required. Please include (app_id: YOUR_APP_ID, api_key: YOUR_API_KEY).'
3226 end
3327
34- @auth_strategy = auth_strategy
35-
36- header_params = { 'Passage-Version' => "passage-ruby #{ Passage ::VERSION } " }
37- header_params [ 'Authorization' ] = "Bearer #{ @api_key } " if @api_key != ''
38-
39- @req_opts = { }
40- @req_opts [ :header_params ] = header_params
41- @req_opts [ :debug_auth_names ] = [ 'header' ]
28+ req_opts = { }
29+ req_opts [ :header_params ] = {
30+ 'Passage-Version' => "passage-ruby #{ Passage ::VERSION } " ,
31+ 'Authorization' => "Bearer #{ api_key } "
32+ }
33+ req_opts [ :debug_auth_names ] = [ 'header' ]
4234
43- @auth = Passage ::Auth . new ( @ app_id, @api_key , @auth_strategy )
44- @user = Passage ::UserAPI . new ( @ app_id, @api_key )
35+ @auth = Passage ::Auth . new ( app_id : app_id , req_opts : req_opts )
36+ @user = Passage ::UserAPI . new ( app_id : app_id , req_opts : req_opts )
4537 end
4638 end
4739end
0 commit comments