Sha256: 3ad6ce63a954acd3f2decaff339c447022fb95491358b29d2bad2ea6b7b5add9

Contents?: true

Size: 792 Bytes

Versions: 32

Compression:

Stored size: 792 Bytes

Contents

# frozen_string_literal: true

module FinApps
  module REST
    class Institutions < FinAppsCore::REST::Resources
      ROUTING_NUMBER_LENGTH = 9

      def list(search_term)
        not_blank(search_term, :search_term) # API errors when search_term is blank, maybe it shouldn't

        path = "#{end_point}/search/#{ERB::Util.url_encode(search_term)}"
        super path
      end

      def show(id)
        digits = remove_non_digits id
        not_blank(digits, :id)

        path = "#{end_point}/#{search_type digits}/#{digits}"
        super digits, path
      end

      private

      def search_type(digits)
        digits.length >= ROUTING_NUMBER_LENGTH ? :routing : :site
      end

      def remove_non_digits(value)
        value.to_s.gsub(/\D/, '')
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
finapps-5.0.3 lib/finapps/rest/institutions.rb
finapps-5.0.2 lib/finapps/rest/institutions.rb
finapps-5.0.1 lib/finapps/rest/institutions.rb
finapps-5.0.0 lib/finapps/rest/institutions.rb
finapps-4.0.16 lib/finapps/rest/institutions.rb
finapps-4.0.15 lib/finapps/rest/institutions.rb
finapps-4.0.14 lib/finapps/rest/institutions.rb
finapps-4.0.12 lib/finapps/rest/institutions.rb
finapps-4.0.11 lib/finapps/rest/institutions.rb
finapps-4.0.10 lib/finapps/rest/institutions.rb
finapps-4.0.9 lib/finapps/rest/institutions.rb
finapps-4.0.8 lib/finapps/rest/institutions.rb
finapps-4.0.7 lib/finapps/rest/institutions.rb
finapps-4.0.6 lib/finapps/rest/institutions.rb
finapps-4.0.5 lib/finapps/rest/institutions.rb
finapps-4.0.4 lib/finapps/rest/institutions.rb
finapps-4.0.3 lib/finapps/rest/institutions.rb
finapps-4.0.2 lib/finapps/rest/institutions.rb
finapps-4.0.1 lib/finapps/rest/institutions.rb
finapps-3.0.7 lib/finapps/rest/institutions.rb