2
2
3
3
require_relative 'auth'
4
4
require_relative 'user_api'
5
- require_relative 'error'
6
5
require_relative 'version'
7
6
8
7
module Passage
@@ -16,32 +15,25 @@ module Passage
16
15
class Client
17
16
attr_reader :auth , :user
18
17
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).'
32
26
end
33
27
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' ]
42
34
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 )
45
37
end
46
38
end
47
39
end
0 commit comments