fdic 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: add200a412197e304c2a7e2248ebf6a602e6b107
4
+ data.tar.gz: 066321ccc3f906f473c0ee1fff106f7d06887a8c
5
+ SHA512:
6
+ metadata.gz: 6afed6e86475264c939298e6d17e785a29d636343a48426aa55d920939b8aaa8c2de58dfb3e35c8e70f11ea3e17e8755f835139ffbda0e3d256ac401727c5dcf
7
+ data.tar.gz: 390906519e45984ddf10404b71495f1f5f671dd1efca79f89fadd606db87c25f8d24f9ab69fcf03ed3f2e8573abbd624096e7aba2233e1f899c13cafb3f9eeb5
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ fdic-*.gem
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.1
5
+ - 2.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fdic.gemspec
4
+ gemspec
5
+
6
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fdic (0.1.0)
5
+ httparty (~> 0.13)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ codeclimate-test-reporter (0.4.7)
11
+ simplecov (>= 0.7.1, < 1.0.0)
12
+ diff-lcs (1.2.5)
13
+ docile (1.1.5)
14
+ httparty (0.13.5)
15
+ json (~> 1.8)
16
+ multi_xml (>= 0.5.2)
17
+ json (1.8.3)
18
+ multi_xml (0.5.5)
19
+ rake (10.4.2)
20
+ rspec (3.3.0)
21
+ rspec-core (~> 3.3.0)
22
+ rspec-expectations (~> 3.3.0)
23
+ rspec-mocks (~> 3.3.0)
24
+ rspec-core (3.3.2)
25
+ rspec-support (~> 3.3.0)
26
+ rspec-expectations (3.3.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.3.0)
29
+ rspec-mocks (3.3.2)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.3.0)
32
+ rspec-support (3.3.0)
33
+ simplecov (0.10.0)
34
+ docile (~> 1.1.0)
35
+ json (~> 1.8)
36
+ simplecov-html (~> 0.10.0)
37
+ simplecov-html (0.10.0)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bundler (~> 1.10)
44
+ codeclimate-test-reporter
45
+ fdic!
46
+ rake (~> 10.0)
47
+ rspec (~> 3.0)
48
+
49
+ BUNDLED WITH
50
+ 1.10.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Continuity
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ [![Code Climate](https://codeclimate.com/github/ContinuityControl/fdic/badges/gpa.svg)](https://codeclimate.com/github/ContinuityControl/fdic)
2
+ [![Test Coverage](https://codeclimate.com/github/ContinuityControl/fdic/badges/coverage.svg)](https://codeclimate.com/github/ContinuityControl/fdic/coverage)
3
+
4
+ # FDIC
5
+
6
+ The FDIC [lets you find information on FDIC-insured banking
7
+ institutions](https://research.fdic.gov/bankfind/index.html). Their site uses
8
+ [a JSON
9
+ API](http://www.programmableweb.com/news/fdic-bank-data-api-available-official-announcement-pending/2015/02/06)
10
+ to look up financial information, branch information, etc.
11
+
12
+ This gem is a ruby client to that API. It's totally unaffiliated with the FDIC.
13
+ It's open source, so anyone can use it, and anyone can help maintain it. At
14
+ this point, it's maintained by [the
15
+ developers](http://engineering.continuity.net/) at
16
+ [Continuity](http://continuity.net).
17
+
18
+ If you need help understanding the data returned by that API, and this gem, it
19
+ can help to look at [the FDIC's BankFind glossary of
20
+ terms](https://research.fdic.gov/bankfind/glossary.html).
21
+
22
+ ## Installation
23
+
24
+ Add this line to your application's Gemfile:
25
+
26
+ ```ruby
27
+ gem 'fdic'
28
+ ```
29
+
30
+ And then execute:
31
+
32
+ $ bundle
33
+
34
+ Or install it yourself as:
35
+
36
+ $ gem install fdic
37
+
38
+ ## Usage
39
+
40
+ You can look up a Bank by its name, and find all matching Banks:
41
+
42
+ ```
43
+ # Returns an Array:
44
+ FDIC.find_bank('Dedicated Community Bank') #=> [FDIC::Bank, FDIC::Bank, ...]
45
+ ```
46
+
47
+ You can look up an Institution by its FDIC Certificate number:
48
+
49
+ ```
50
+ # Returns only one:
51
+ FDIC.find_institution(26588) #=> FDIC::Institution
52
+ ```
53
+
54
+ You can look up a Bank's branches by its FDIC Certificate number:
55
+
56
+ ```
57
+ # Returns an Array:
58
+ FDIC.find_branches(25688) #=> [FDIC::Branch, FDIC::Branch, ...]
59
+ ```
60
+
61
+ You can look up a Bank's history by its name and FDIC Certificate number:
62
+
63
+ ```
64
+ # Returns an Array:
65
+ FDIC.find_history_events('Dedicated Community Bank', 26588) #=> [FDIC::HistoryEvent, ...]
66
+ ```
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ContinuityControl/fdic.
71
+
72
+ ## License
73
+
74
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
75
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fdic"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/fdic.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fdic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fdic"
8
+ spec.version = FDIC::VERSION
9
+ spec.authors = ["Tom Reznick", "Dan Bernier"]
10
+ spec.email = ["treznick@continuity.net", "dbernier@continuity.net"]
11
+
12
+ spec.summary = %q{A Ruby client to the FDIC's BankFind API}
13
+ spec.description = %q{The FDIC recently exposed a JSON-over-HTTP API behind its BankFind website. This gem makes that API easy to use from Ruby.}
14
+ spec.homepage = "https://github.com/ContinuityControl/fdic"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "httparty", "~> 0.13"
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
data/lib/fdic.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'httparty'
2
+ require 'logger'
3
+ require "fdic/version"
4
+ require 'fdic/client'
5
+ require 'fdic/record'
6
+ require 'fdic/bank'
7
+ require 'fdic/institution'
8
+ require 'fdic/branch'
9
+ require 'fdic/history_event'
10
+
11
+ module FDIC
12
+
13
+ def find_bank(bank_name)
14
+ resp = Client.new.find_bank(bank_name)
15
+ resp['d']['results'].map { |result|
16
+ FDIC::Bank.new(result)
17
+ }
18
+ end
19
+
20
+ def find_institution(certificate_number)
21
+ resp = Client.new.find_institution(certificate_number)
22
+ result = resp['d']['results'].first
23
+ FDIC::Institution.new(result)
24
+ end
25
+
26
+ def find_branches(certificate_number)
27
+ resp = Client.new.find_branches(certificate_number)
28
+ resp['d']['results'].map { |result|
29
+ FDIC::Branch.new(result)
30
+ }
31
+ end
32
+
33
+ def find_history_events(bank_name, certificate_number)
34
+ resp = Client.new.find_history_events(bank_name, certificate_number)
35
+ resp['d']['results'].map { |result|
36
+ FDIC::HistoryEvent.new(result)
37
+ }
38
+ end
39
+
40
+ extend self
41
+ end
data/lib/fdic/bank.rb ADDED
@@ -0,0 +1,22 @@
1
+ module FDIC
2
+ class Bank < Record
3
+ field :fdic_id, 'id'
4
+ field(:legal_name, 'legalName', &:strip)
5
+ field :certificate_number, :certNumber
6
+ field(:active?, 'activeFlag') { |value| value == 'Y' }
7
+ field :address
8
+ field :city
9
+ field :state
10
+ field :zip
11
+ field :office_count, :officeCount
12
+ date_field :effective_date, :effectiveDate
13
+
14
+ def find_institution!
15
+ @institution ||= FDIC.find_institution(certificate_number)
16
+ end
17
+
18
+ def find_history_events!
19
+ @history_events ||= FDIC.find_history_events(legal_name, certificate_number)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ =begin
2
+ { "__metadata"=> {
3
+ "uri"=>"http://odata.fdic.gov:80/v1/financial-institution/Branch('10345')",
4
+ "type"=>"financial-institutionModel.Branch"
5
+ },
6
+ "id"=>"10345",
7
+ "branchName"=>"First National Bank Alaska",
8
+ "certNumber"=>"16130",
9
+ "address"=>"101 W. 36th Avenue",
10
+ "city"=>"Anchorage",
11
+ "county"=>"Anchorage",
12
+ "state"=>"AK",
13
+ "zip"=>"99510.0",
14
+ "branchNum"=>nil,
15
+ "establishedDate"=>"1922-01-30 00:00:00.0",
16
+ "acquiredDate"=>nil,
17
+
18
+ "fiUninum"=>"10345",
19
+ "servTypeCd"=>"11"
20
+ }
21
+ =end
22
+
23
+ module FDIC
24
+ class Branch < Record
25
+ field :fdic_id, 'id'
26
+ field(:branch_name, 'branchName', &:strip)
27
+ field :certificate_number, :certNumber
28
+
29
+ field :address
30
+ field :city
31
+ field :county
32
+ field :state
33
+ field :zip
34
+
35
+ field :branch_number, :branchNum
36
+ date_field :established_date, :establishedDate
37
+ date_field :acquired_date, :acquiredDate
38
+ end
39
+ end
@@ -0,0 +1,52 @@
1
+ module FDIC
2
+ class Client
3
+ include HTTParty
4
+ base_uri 'https://odata.fdic.gov/v1/financial-institution/'
5
+ format :json
6
+
7
+ #logger ::Logger.new 'httparty.log', :debug, :curl
8
+ #debug_output
9
+
10
+ def find_bank(bank_name)
11
+ self.class.get('/Bank',
12
+ query:
13
+ { '$inlinecount' => 'all',
14
+ '$format' => 'json',
15
+ '$filter' => "(substringof('#{escape_single_quotes(bank_name.upcase)}',name))"})
16
+ end
17
+
18
+ def find_institution(certificate_number)
19
+ self.class.get('/Institution',
20
+ query:
21
+ { '$inlinecount' => 'all',
22
+ '$format' => 'json',
23
+ '$filter' => "certNumber eq #{certificate_number}"})
24
+ end
25
+
26
+ def find_branches(certificate_number)
27
+ self.class.get('/Branch',
28
+ query:
29
+ { '$inlinecount' => 'allpages',
30
+ '$format' => 'json',
31
+ '$filter' => "certNumber eq #{certificate_number}"})
32
+ end
33
+
34
+ def find_history_events(bank_name, certificate_number)
35
+ filter = "legalName eq '#{escape_single_quotes(bank_name.upcase)}' and certNumber eq #{certificate_number}"
36
+ self.class.get('/History',
37
+ query:
38
+ { '$inlinecount' => 'all',
39
+ '$format' => 'json',
40
+ '$filter' => filter})
41
+ end
42
+
43
+ private
44
+
45
+ def escape_single_quotes(string)
46
+ # Urm? The API 500's if you have a single-quote in name: "People's United Bank."
47
+ # Their web forms double-up the single-quotes to escape them.
48
+ # NB: let's keep an eye on this flim-flam, and be sure it doesn't get out of hand.
49
+ string.gsub("'", "''")
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,22 @@
1
+ module FDIC
2
+ class HistoryEvent < Record
3
+
4
+ field :fdic_id, :id
5
+ field(:legal_name, :legalName, &:strip)
6
+ field :certificate_number, :certNumber
7
+
8
+ date_field :effective_date, :orgEffDate
9
+ field :event_description, :eventDescription
10
+ field :change_code, :changeCode
11
+ field :change_description, :changeDesc
12
+
13
+ field :trust_power, :trustPower
14
+ field :trust_power_check, :trustPowerCheck
15
+
16
+ field :city
17
+ field :state
18
+
19
+ field :primary_regulatory_agency_check, :primaryRegulatoryAgencyCheck
20
+ field :primary_regulatory_agency, :primaryRegulatoryAgency
21
+ end
22
+ end
@@ -0,0 +1,41 @@
1
+ module FDIC
2
+ class Institution < Record
3
+ field :fdic_id, :id
4
+ field(:legal_name, :legalName, &:strip)
5
+ field :certificate_number, :certNumber
6
+
7
+ field :supervising_authority, :FACodeText
8
+ field :supervising_authority_code, :FACode
9
+
10
+ field(:active?, 'activeFlag') { |value| value == 'Y' }
11
+ date_field :inactive_as_of_date, "inActiveAsofDt"
12
+ field :address
13
+ field :city
14
+ field :county
15
+ field :state
16
+ field :zip
17
+ field :web_site, "webSite"
18
+
19
+ date_field :insured_date, 'insuredDate'
20
+ date_field :insured_from_date, "insuredFrmDt"
21
+ date_field :insured_to_date, "insuredToDt"
22
+ date_field :established_date, 'establishedDate'
23
+ date_field :as_of_date, 'asOfDate'
24
+
25
+ date_field :report_date, "reportDate" # This is NOT the date the query was made.
26
+
27
+ int_field :office_count, "officeCount"
28
+ currency_field :total_assets_in_thousands, 'totalAssets'
29
+ currency_field :total_deposits_in_thousands, "totalDeposits"
30
+ currency_field :domestic_deposits_in_thousands, "domesticDeposits"
31
+ currency_field :bank_equity_capital_in_thousands, "bankEquityCapital"
32
+
33
+ def find_history_events!
34
+ @history_events ||= FDIC.find_history_events(legal_name, certificate_number)
35
+ end
36
+
37
+ def find_branches!
38
+ @branches ||= FDIC.find_branches(certificate_number)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,36 @@
1
+ module FDIC
2
+ class Record
3
+ def initialize(attributes)
4
+ @attributes = attributes
5
+ @attributes.freeze
6
+ end
7
+
8
+ attr_reader :attributes
9
+
10
+ def self.field(method_name, response_key=method_name, &munger)
11
+ munger ||= lambda { |x| x }
12
+ define_method(method_name) {
13
+ value = attributes[response_key.to_s]
14
+ value && munger.call(value)
15
+ }
16
+ end
17
+
18
+ def self.int_field(method_name, response_key=method_name)
19
+ field(method_name, response_key, &:to_i)
20
+ end
21
+
22
+ def self.currency_field(method_name, response_key=method_name)
23
+ field(method_name, response_key, &:to_f)
24
+ end
25
+
26
+ def self.date_field(method_name, response_key=method_name)
27
+ field(method_name, response_key) { |value|
28
+ Date.parse(value)
29
+ }
30
+ end
31
+
32
+ def uri
33
+ attributes['__metadata']['uri']
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module FDIC
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fdic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom Reznick
8
+ - Dan Bernier
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-08-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.13'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.13'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.10'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.10'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ description: The FDIC recently exposed a JSON-over-HTTP API behind its BankFind website.
71
+ This gem makes that API easy to use from Ruby.
72
+ email:
73
+ - treznick@continuity.net
74
+ - dbernier@continuity.net
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - fdic.gemspec
89
+ - lib/fdic.rb
90
+ - lib/fdic/bank.rb
91
+ - lib/fdic/branch.rb
92
+ - lib/fdic/client.rb
93
+ - lib/fdic/history_event.rb
94
+ - lib/fdic/institution.rb
95
+ - lib/fdic/record.rb
96
+ - lib/fdic/version.rb
97
+ homepage: https://github.com/ContinuityControl/fdic
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.4.7
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: A Ruby client to the FDIC's BankFind API
121
+ test_files: []