ofac_sdn 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d1bfde7b0ba49c30964a0d8abe93a6b81786ff19
4
+ data.tar.gz: 91b0a014f538b09d91f4ab4e058f6153625e6b00
5
+ SHA512:
6
+ metadata.gz: 4ee32d8ac6b628b7c20531a307bb9675ed92be6bd36745535faa21dd6f87c39d2d793bb1c177b7ba511ac9771557e423ec0d431d5cecc3b63924f1184696b739
7
+ data.tar.gz: 9c00b548c70a02b81ac5a8df7564c013039a69f604197c7893bb6706e008b2218f5f7db108dd801c13e9393d313f80fa41de5600a34cc37f05590cfbeaa09205
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ofac_sdn.gemspec
6
+ # gem 'pry-byebug'
7
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ofac_sdn (0.1.0)
5
+ nokogiri (~> 1.8.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (10.0.2)
11
+ coderay (1.1.1)
12
+ method_source (0.9.0)
13
+ mini_portile2 (2.3.0)
14
+ minitest (5.10.2)
15
+ nokogiri (1.8.2)
16
+ mini_portile2 (~> 2.3.0)
17
+ pry (0.11.3)
18
+ coderay (~> 1.1.0)
19
+ method_source (~> 0.9.0)
20
+ pry-byebug (3.6.0)
21
+ byebug (~> 10.0)
22
+ pry (~> 0.10)
23
+ rake (10.4.2)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.16)
30
+ minitest (~> 5.0)
31
+ ofac_sdn!
32
+ pry-byebug
33
+ rake (~> 10.0)
34
+
35
+ BUNDLED WITH
36
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Bryam Noguera
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,53 @@
1
+ # OfacSdn
2
+ This gem provides the OFAC `sdn.xml` as an easy to use Ruby hash. This allows you to conduct your own search criteria on your own system.
3
+
4
+ You can find the OFAC downloads here:
5
+ [OFAC Downloads](https://www.treasury.gov/ofac/downloads)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ofac_sdn'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ofac_sdn
22
+
23
+ ## Usage
24
+ You should run this in a worker since parsing an XML and converting it to a pretty Hash does take relatively long.
25
+
26
+ ```
27
+ require 'ofac_sdn'
28
+
29
+ sdn_hash = OfacSdn::Read.call
30
+ ```
31
+
32
+ Check to see if there are any new updates in the date or record count from your last database insertion to avoid pulling the data again:
33
+
34
+ ```
35
+ date = OfacSdn::Read.publish_date
36
+ count = OfacSdn::Read.record_count
37
+ ```
38
+
39
+ * How often is the Specially Designated Nationals (SDN) List updated? [OFAC FAQ](https://www.treasury.gov/resource-center/faqs/Sanctions/Pages/faq_lists.aspx)
40
+
41
+ * The SDN list is frequently updated. There is no predetermined timetable, but rather names are added or removed as necessary and appropriate.
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/csebryam/ofac_sdn.
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ofac_sdn"
5
+
6
+ # (If you use this, don't forget to add pry to your Gemfile!)
7
+ require "pry-byebug"
8
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'nokogiri'
5
+ require 'open-uri'
6
+
7
+ module OfacSdn
8
+ # OfacSdn::Document holds the XML OFAC document
9
+ class Document
10
+ def self.call
11
+ new.call
12
+ end
13
+ attr_reader :data_url, :xml_path
14
+
15
+ def initialize
16
+ @data_url = 'https://www.treasury.gov/ofac/downloads/sdn.xml'.freeze
17
+ @xml_path = open(data_url)
18
+ end
19
+
20
+ def call
21
+ Nokogiri::XML(xml_path)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,92 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module OfacSdn
5
+ # OfacSdn::Parser parses the XML document and returns a formatted hash
6
+ class Parser
7
+ def self.run(**kwargs)
8
+ new(**kwargs).call
9
+ end
10
+
11
+ attr_reader :document, :result, :xsd
12
+
13
+ def initialize(xsd:, document:)
14
+ @xsd = xsd
15
+ @document = document
16
+ end
17
+
18
+ def call
19
+ initialize_result_hash
20
+ build_hash_with('sdnList > sdnEntry')
21
+ result
22
+ end
23
+
24
+ private
25
+
26
+ def build_hash(sdn_entry)
27
+ result[:sdnEntry] << sdn_entry_hash(sdn_entry)
28
+ sdn_id = result[:sdnEntry].last[:id]
29
+ build_sdn_lists(sdn_entry, sdn_id)
30
+ end
31
+
32
+ def build_hash_with(search_css)
33
+ document.css(search_css).map do |sdn_entry|
34
+ build_hash(sdn_entry)
35
+ end
36
+ end
37
+
38
+ def build_sdn_list(table, sdn_entry, sdn_id)
39
+ element = set_element(table, sdn_entry)
40
+ return if element.empty?
41
+ element.each_with_object({}) do |k, h|
42
+ col_type = xsd[table][:element][k.name.to_sym]
43
+ next unless col_type
44
+ set_hash(h, k, col_type) unless k.nil?
45
+ h[:sdn_id] = sdn_id
46
+ end
47
+ end
48
+
49
+ def build_sdn_lists(sdn_entry, sdn_id)
50
+ xsd.each_key do |table|
51
+ next if table == :sdnEntry
52
+ table_hash = build_sdn_list(table, sdn_entry, sdn_id)
53
+ result[table] << table_hash unless table_hash.nil?
54
+ end
55
+ end
56
+
57
+ def initialize_result_hash
58
+ @result ||= xsd.keys.each_with_object({}) { |t, h| h[t] = [] }
59
+ end
60
+
61
+ def sdn_entry_hash(sdn_entry)
62
+ xsd[:sdnEntry][:element].each_with_object({}) do |(e, e_type), h|
63
+ element = sdn_entry.children.css(e).first
64
+ set_hash(h, element, e_type) unless element.nil?
65
+ end
66
+ end
67
+
68
+ def set_element(table, sdn_entry)
69
+ element = sdn_entry.css(table).children
70
+ element = element[1].children if xsd[table][:key] && !element.empty?
71
+ element
72
+ end
73
+
74
+ def set_hash(hash, element, column_type)
75
+ key = :id if element.name == 'uid'
76
+ key ||= element.name.to_sym
77
+ hash[key] = to_type(element.text, column_type)
78
+ end
79
+
80
+ def to_type(value, type)
81
+ case type
82
+ when 'int'
83
+ value.to_i
84
+ when 'bool'
85
+ return false if value == 'false'
86
+ true
87
+ else
88
+ value.to_s
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OfacSdn
4
+ VERSION = "0.1.1"
5
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OfacSdn
4
+ # https://www.treasury.gov/resource-center/sanctions/SDN-List/Documents/sdn.xsd
5
+ XSD_HASH =
6
+ {
7
+ sdnEntry: {
8
+ element: {
9
+ uid: 'int',
10
+ firstName: 'string',
11
+ lastName: 'string',
12
+ title: 'string',
13
+ sdnType: 'string',
14
+ remarks: 'string'
15
+ }
16
+ },
17
+ programList: {
18
+ element: {
19
+ program: 'string'
20
+ }
21
+ },
22
+ idList: {
23
+ key: 'id',
24
+ element: {
25
+ uid: 'int',
26
+ idType: 'string',
27
+ idNumber: 'string',
28
+ idCountry: 'string',
29
+ issueDate: 'string',
30
+ expirationDate: 'string'
31
+ }
32
+ },
33
+ akaList: {
34
+ key: 'aka',
35
+ element: {
36
+ uid: 'int',
37
+ type: 'string',
38
+ category: 'string',
39
+ lastName: 'string',
40
+ firstName: 'string'
41
+ }
42
+ },
43
+ addressList: {
44
+ key: 'address',
45
+ element:
46
+ {
47
+ uid: 'int',
48
+ address1: 'string',
49
+ address2: 'string',
50
+ address3: 'string',
51
+ city: 'string',
52
+ stateOrProvince: 'string',
53
+ postalCode: 'string',
54
+ country: 'string'
55
+ }
56
+ },
57
+ nationalityList: {
58
+ key: 'nationality',
59
+ element: {
60
+ uid: 'int',
61
+ country: 'string',
62
+ mainEntry: 'bool'
63
+ }
64
+ },
65
+ citizenshipList: {
66
+ key: 'citizenship',
67
+ element: {
68
+ uid: 'int',
69
+ country: 'string',
70
+ mainEntry: 'bool'
71
+ }
72
+ },
73
+ dateOfBirthList: {
74
+ key: 'dateOfBirthItem',
75
+ element: {
76
+ uid: 'int',
77
+ dateOfBirth: 'string',
78
+ mainEntry: 'bool'
79
+ }
80
+ },
81
+ placeOfBirthList: {
82
+ key: 'placeOfBirthItem',
83
+ element: {
84
+ uid: 'int',
85
+ placeOfBirth: 'string',
86
+ mainEntry: 'bool'
87
+ }
88
+ },
89
+ vesselInfo: {
90
+ element: {
91
+ callSign: 'string',
92
+ vesselType: 'string',
93
+ vesselFlag: 'string',
94
+ vesselOwner: 'string',
95
+ tonnage: 'int',
96
+ grossRegisteredTonnage: 'int'
97
+ }
98
+ }
99
+ }.freeze
100
+ end
data/lib/ofac_sdn.rb ADDED
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'ofac_sdn/document'
5
+ require 'ofac_sdn/parser'
6
+ require 'ofac_sdn/version'
7
+ require 'ofac_sdn/xsd'
8
+
9
+ module OfacSdn
10
+ # OfacSdn::Read.new creates the SDN Hash document
11
+ class Read
12
+ class << self
13
+ def call
14
+ new.call(document)
15
+ end
16
+
17
+ def document
18
+ @document ||= Document.call
19
+ end
20
+
21
+ def publish_date
22
+ document.css('sdnList publshInformation Publish_Date').text
23
+ end
24
+
25
+ def record_count
26
+ document.css('sdnList publshInformation Record_Count').text.to_i
27
+ end
28
+ end
29
+
30
+ def call(document)
31
+ Parser.run(document: document, xsd: XSD_HASH)
32
+ end
33
+ end
34
+ end
data/ofac_sdn.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'ofac_sdn/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'ofac_sdn'
9
+ spec.version = OfacSdn::VERSION
10
+ spec.authors = ['Bryam Noguera']
11
+ spec.email = ['bryam@primetrust.com']
12
+
13
+ spec.summary = 'returns a hash for the ofac sdn.xml list'
14
+ spec.homepage = 'https://github.com/csebryam/ofac-sdn'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.16'
25
+ spec.add_development_dependency 'minitest', '~> 5.0'
26
+ spec.add_development_dependency 'pry-byebug'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_runtime_dependency 'nokogiri', '~> 1.8.2'
29
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ofac_sdn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Bryam Noguera
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.8.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.8.2
83
+ description:
84
+ email:
85
+ - bryam@primetrust.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/ofac_sdn.rb
100
+ - lib/ofac_sdn/document.rb
101
+ - lib/ofac_sdn/parser.rb
102
+ - lib/ofac_sdn/version.rb
103
+ - lib/ofac_sdn/xsd.rb
104
+ - ofac_sdn.gemspec
105
+ homepage: https://github.com/csebryam/ofac-sdn
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: returns a hash for the ofac sdn.xml list
129
+ test_files: []