Sha256: c2ad48a9ea3f699f1a0b3f427c79e4e75cbdd1aa2435601ad60c4f6db793b9e2

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

module Stytch
  module Endpoints
    module Magic
      PATH = "/v1/magic_links".freeze

      def send_magic(
          method_id:,
          user_id:,
          magic_link_url:,
          expiration_minutes:,
          template_id: nil,
          attributes: {}
      )
        request = {
            method_id: method_id,
            user_id: user_id,
            magic_link_url: magic_link_url,
            expiration_minutes: expiration_minutes,
        }

        request[:template_id] = template_id if template_id != nil
        request[:attributes] = attributes if attributes != {}

        post("#{PATH}/send", request)
      end

      def send_magic_by_email(
          email:,
          magic_link_url:,
          expiration_minutes:,
          template_id: nil,
          attributes: {}
      )
        request = {
            email: email,
            magic_link_url: magic_link_url,
            expiration_minutes: expiration_minutes,
        }

        request[:template_id] = template_id if template_id != nil
        request[:attributes] = attributes if attributes != {}

        post("#{PATH}/send_by_email", request)
      end

      def authenticate_magic(
          token:,
          attributes: {},
          options: {}
      )
        request = {}

        request[:attributes] = attributes if attributes != {}
        request[:options] = options if options != {}

        post("#{PATH}/#{token}/authenticate", request)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stytch-0.1.7 lib/stytch/endpoints/magic.rb