Sha256: 7839df3002902e461e4249b6f82266b1f7af5f8abb26e0b9589d75809a2c21f4

Contents?: true

Size: 1.04 KB

Versions: 14

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Trusona
  module Workers
    #
    ## Finds user accounts
    class UserAccountFinder
      def initialize(user_accounts_service: nil, account_lookups_service: nil)
        @lookups = account_lookups_service ||
                   Trusona::Services::AccountLookupsService.new
        @user_accounts = user_accounts_service ||
                         Trusona::Services::UserAccountsService.new
      end

      def find(opts)
        raise ArgumentError, 'Missing email or trusona id' unless
          contains_required_arguments(opts)

        resource = build_resource(opts)

        if opts[:trusona_id] || opts['trusona_id']
          return @user_accounts.get(resource)
        end

        @lookups.create(resource) if opts[:email] || opts['email']
      end

      private

      def contains_required_arguments(opts)
        opts[:email] || opts['email'] || opts[:trusona_id] || opts['trusona_id']
      end

      def build_resource(options)
        Trusona::Resources::UserAccount.new(options)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
trusona-2.5.1 lib/trusona/workers/user_account_finder.rb
trusona-2.5.0 lib/trusona/workers/user_account_finder.rb
trusona-2.4.0 lib/trusona/workers/user_account_finder.rb
trusona-2.3.0 lib/trusona/workers/user_account_finder.rb
trusona-2.2.0 lib/trusona/workers/user_account_finder.rb
trusona-2.1.0 lib/trusona/workers/user_account_finder.rb
trusona-2.0.0 lib/trusona/workers/user_account_finder.rb
trusona-1.0.1 lib/trusona/workers/user_account_finder.rb
trusona-1.0.0 lib/trusona/workers/user_account_finder.rb
trusona-0.20.0 lib/trusona/workers/user_account_finder.rb
trusona-0.19.0 lib/trusona/workers/user_account_finder.rb
trusona-0.18.2 lib/trusona/workers/user_account_finder.rb
trusona-0.18.1 lib/trusona/workers/user_account_finder.rb
trusona-0.16.0 lib/trusona/workers/user_account_finder.rb