1
1
# frozen_string_literal: true
2
2
3
- require 'rubygems'
4
3
require_relative 'auth'
5
4
require_relative 'user_api'
6
5
require_relative 'error'
7
6
require_relative 'version'
8
- require_relative '../openapi_client'
9
7
10
8
module Passage
11
9
COOKIE_STRATEGY = 0
@@ -18,8 +16,6 @@ module Passage
18
16
class Client
19
17
attr_reader :auth , :user
20
18
21
- extend Gem ::Deprecate
22
-
23
19
def initialize ( app_id :, api_key : '' , auth_strategy : COOKIE_STRATEGY )
24
20
@app_id = app_id
25
21
@api_key = api_key
@@ -44,70 +40,8 @@ def initialize(app_id:, api_key: '', auth_strategy: COOKIE_STRATEGY)
44
40
@req_opts [ :header_params ] = header_params
45
41
@req_opts [ :debug_auth_names ] = [ 'header' ]
46
42
47
- # initialize auth class
48
43
@auth = Passage ::Auth . new ( @app_id , @api_key , @auth_strategy )
49
-
50
- # initialize user class
51
44
@user = Passage ::UserAPI . new ( @app_id , @api_key )
52
-
53
- @magic_links_client = OpenapiClient ::MagicLinksApi . new
54
- end
55
-
56
- # rubocop:disable Naming/AccessorMethodName
57
- def get_app
58
- client = OpenapiClient ::AppsApi . new
59
- client . get_app ( @app_id ) . app
60
- rescue StandardError => e
61
- raise e
62
- end
63
- # rubocop:enable Naming/AccessorMethodName
64
-
65
- # rubocop:disable Metrics/ParameterLists, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
66
- def create_magic_link (
67
- user_id : '' ,
68
- email : '' ,
69
- phone : '' ,
70
- channel : '' ,
71
- send : false ,
72
- magic_link_path : '' ,
73
- redirect_url : '' ,
74
- language : '' ,
75
- ttl : 60 ,
76
- type : 'login'
77
- )
78
- args = { }
79
- args [ 'user_id' ] = user_id unless user_id . empty?
80
- args [ 'email' ] = email unless email . empty?
81
- args [ 'phone' ] = phone unless phone . empty?
82
-
83
- unless [ PHONE_CHANNEL , EMAIL_CHANNEL ] . include? channel
84
- raise PassageError . new (
85
- message :
86
- 'channel: must be either Passage::EMAIL_CHANNEL or Passage::PHONE_CHANNEL'
87
- )
88
- end
89
-
90
- args [ 'channel' ] = channel unless channel . empty?
91
- args [ 'type' ] = type
92
- args [ 'send' ] = send
93
-
94
- args [ 'language' ] = language unless language . empty?
95
- args [ 'magic_link_path' ] = magic_link_path unless magic_link_path . empty?
96
- args [ 'redirect_url' ] = redirect_url unless redirect_url . empty?
97
- args [ 'ttl' ] = ttl unless ttl . zero?
98
-
99
- begin
100
- @magic_links_client . create_magic_link ( @app_id , args , @req_opts ) . magic_link
101
- rescue Faraday ::Error => e
102
- raise PassageError . new (
103
- status_code : e . response [ :status ] ,
104
- body : e . response [ :body ]
105
- )
106
- end
107
45
end
108
- # rubocop:enable Metrics/ParameterLists, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
109
-
110
- deprecate ( :create_magic_link , 'Passage::Auth.create_magic_link' , 2025 , 1 )
111
- deprecate ( :get_app , :none , 2025 , 1 )
112
46
end
113
47
end
0 commit comments