Class: Passage::Client
- Inherits:
-
Object
- Object
- Passage::Client
- Defined in:
- lib/passageidentity/client.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #create_magic_link(user_id: "", email: "", phone: "", channel: "", send: false, magic_link_path: "", redirect_url: "", language: "", ttl: 60, type: "login") ⇒ Object
- #get_app ⇒ Object
-
#initialize(app_id:, api_key: "", auth_strategy: COOKIE_STRATEGY) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(app_id:, api_key: "", auth_strategy: COOKIE_STRATEGY) ⇒ Client
Returns a new instance of Client.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/passageidentity/client.rb', line 21 def initialize(app_id:, api_key: "", auth_strategy: COOKIE_STRATEGY) @app_id = app_id @api_key = api_key # check for valid auth strategy unless [COOKIE_STRATEGY, HEADER_STRATEGY].include? auth_strategy raise PassageError.new(message: "invalid auth strategy.") end @auth_strategy = auth_strategy # initialize auth class @auth = Passage::Auth.new(@app_id, @auth_strategy) # initialize user class @user = Passage::UserAPI.new(@app_id, @api_key) end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
18 19 20 |
# File 'lib/passageidentity/client.rb', line 18 def auth @auth end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
19 20 21 |
# File 'lib/passageidentity/client.rb', line 19 def user @user end |
Instance Method Details
#create_magic_link(user_id: "", email: "", phone: "", channel: "", send: false, magic_link_path: "", redirect_url: "", language: "", ttl: 60, type: "login") ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/passageidentity/client.rb', line 47 def create_magic_link( user_id: "", email: "", phone: "", channel: "", send: false, magic_link_path: "", redirect_url: "", language: "", ttl: 60, type: "login" ) magic_link_req = {} magic_link_req["user_id"] = user_id unless user_id.empty? magic_link_req["email"] = email unless email.empty? magic_link_req["phone"] = phone unless phone.empty? # check to see if the channel specified is valid before sending it off to the server unless [PHONE_CHANNEL, EMAIL_CHANNEL].include? channel raise PassageError.new( message: "channel: must be either Passage::EMAIL_CHANNEL or Passage::PHONE_CHANNEL" ) end magic_link_req["channel"] = channel unless channel.empty? magic_link_req["send"] = send magic_link_req[ "magic_link_path" ] = magic_link_path unless magic_link_path.empty? magic_link_req["redirect_url"] = redirect_url unless redirect_url.empty? magic_link_req["ttl"] = ttl unless ttl == 0 magic_link_req["type"] = type begin gemspec = File.join(__dir__, "../../passageidentity.gemspec") spec = Gem::Specification.load(gemspec) header_params = { "Passage-Version" => "passage-ruby #{Passage::VERSION}" } header_params["Authorization"] = "Bearer #{@api_key}" if @api_key != "" opts = {} opts[:header_params] = header_params opts[:debug_auth_names] = ["header"] client = OpenapiClient::MagicLinksApi.new return client.create_magic_link(@app_id, magic_link_req, opts).magic_link rescue Faraday::Error => e raise PassageError.new( message: "failed to create Passage Magic Link", status_code: e.response[:status], body: e.response[:body] ) end end |
#get_app ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/passageidentity/client.rb', line 38 def get_app() begin client = OpenapiClient::AppsApi.new return client.get_app(@app_id).app rescue => e raise e end end |