Sha256: db1db0fb99ca115365b33ffd9c6a691f4af51ba212b49e9c56c1f99bf88ce71f

Contents?: true

Size: 1.44 KB

Versions: 4

Compression:

Stored size: 1.44 KB

Contents

module Stytch
  module Endpoints
    module User
      PATH = "/v1/users".freeze

      def get_user(user_id:)
        get("#{PATH}/#{user_id}")
      end

      def get_pending_users(
          limit: nil,
          starting_after_id: nil
      )
        query_params = {
            limit: limit,
            starting_after_id: starting_after_id,
        }

        request = request_with_query_params("#{PATH}/pending", query_params)

        get(request)
      end

      def create_user(
          email:,
          name: {},
          attributes: {}
      )
        request = {
          email: email,
        }

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

        post(PATH, request)
      end

      def update_user(
        user_id:,
        name: {},
        emails: [],
        attributes: {}
      )
        request = {
            emails: format_emails(emails),
        }

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

        put("#{PATH}/#{user_id}", request)
      end

      def delete_user(user_id:)
        delete("#{PATH}/#{user_id}")
      end

      def delete_user_email(
        user_id:,
        email:
      )
        delete("#{PATH}/#{user_id}/emails/#{email}")
      end

      private

      def format_emails(emails)
        e = []
        emails.each { |email| e << { email: email} }
        e
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
stytch-0.1.20 lib/stytch/endpoints/user.rb
stytch-0.1.19 lib/stytch/endpoints/user.rb
stytch-0.1.18 lib/stytch/endpoints/user.rb
stytch-0.1.17 lib/stytch/endpoints/user.rb