lib/stytch/otps.rb in stytch-2.2.0 vs lib/stytch/otps.rb in stytch-2.3.0
- old
+ new
@@ -4,19 +4,20 @@
module Stytch
class OTPs
include Stytch::RequestHelper
- attr_reader :sms, :whatsapp
+ attr_reader :sms, :whatsapp, :email
PATH = '/v1/otps'
def initialize(connection)
@connection = connection
@sms = Stytch::OTPs::SMS.new(@connection)
@whatsapp = Stytch::OTPs::WhatsApp.new(@connection)
+ @email = Stytch::OTPs::Email.new(@connection)
end
def authenticate(
method_id:,
code:,
@@ -110,9 +111,51 @@
attributes: {},
create_user_as_pending: false
)
request = {
phone_number: phone_number,
+ expiration_minutes: expiration_minutes,
+ create_user_as_pending: create_user_as_pending
+ }
+
+ request[:attributes] = attributes if attributes != {}
+
+ post_request("#{PATH}/login_or_create", request)
+ end
+ end
+
+ class Email
+ include Stytch::RequestHelper
+
+ PATH = "#{Stytch::OTPs::PATH}/email"
+
+ def initialize(connection)
+ @connection = connection
+ end
+
+ def send(
+ email:,
+ expiration_minutes: nil,
+ attributes: {}
+ )
+ request = {
+ email: email,
+ expiration_minutes: expiration_minutes
+ }
+
+ request[:attributes] = attributes if attributes != {}
+
+ post_request("#{PATH}/send", request)
+ end
+
+ def login_or_create(
+ email:,
+ expiration_minutes: nil,
+ attributes: {},
+ create_user_as_pending: false
+ )
+ request = {
+ email: email,
expiration_minutes: expiration_minutes,
create_user_as_pending: create_user_as_pending
}
request[:attributes] = attributes if attributes != {}