Sha256: 00bf3f1a8f666718700a93b2d47a736564c6a00864e873617ad91f28fcdb8300

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

module FDIC
  class Client
    include HTTParty
    base_uri 'https://odata.fdic.gov/v1/financial-institution/'
    format :json

    #logger ::Logger.new 'httparty.log', :debug, :curl
    #debug_output

    def find_bank(bank_name)
      self.class.get('/Bank',
                     query:
                     { '$inlinecount' => 'all',
                       '$format' => 'json',
                       '$filter' => "(substringof('#{escape_single_quotes(bank_name.upcase)}',name))"})
    end

    def find_institution(certificate_number)
      self.class.get('/Institution',
                     query:
                     { '$inlinecount' => 'all',
                       '$format' => 'json',
                       '$filter' => "certNumber eq #{certificate_number}"})
    end

    def find_branches(certificate_number)
      self.class.get('/Branch',
                     query:
                     { '$inlinecount' => 'allpages',
                       '$format' => 'json',
                       '$filter' => "certNumber eq #{certificate_number}"})
    end

    def find_history_events(bank_name, certificate_number)
      filter = "legalName eq '#{escape_single_quotes(bank_name.upcase)}' and certNumber eq #{certificate_number}"
      self.class.get('/History',
                     query:
                     { '$inlinecount' => 'all',
                       '$format' => 'json',
                       '$filter' => filter})
    end

    private

    def escape_single_quotes(string)
      # Urm? The API 500's if you have a single-quote in name: "People's United Bank."
      # Their web forms double-up the single-quotes to escape them.
      # NB: let's keep an eye on this flim-flam, and be sure it doesn't get out of hand.
      string.gsub("'", "''")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fdic-0.3.0 lib/fdic/client.rb
fdic-0.2.0 lib/fdic/client.rb
fdic-0.1.0 lib/fdic/client.rb