consolidated_screening_list 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e812e7200b3a2f450bc727a7895cd57ef8ffb4c23daba4181a4144cb60f9b76a
4
+ data.tar.gz: 3370598ff2ad9fbb030a147f970ea8e883c9846b0fe0a562ccf50f92a435857f
5
+ SHA512:
6
+ metadata.gz: 0f51ca556ad96803506b9d431c5b62ff51588bb3716df43930a09511e73b417bc1649eb9b2d8bbf76ac42881a822f00e92523a1aad5610e71e96506e2a4a6de6
7
+ data.tar.gz: 6a4f46071510d3603c0c48c086c110141cbf0161025c871c71c41cbff29362170e65b6e5d0b6b2947e7454c75b42c968e8978e658bf2d7bfa79e9243cb039e5e
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Andrew Mason
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.
@@ -0,0 +1,57 @@
1
+ # ConsolidatedScreeningList
2
+
3
+ A Ruby client for [Trade.gov's Consolidated Screening List](https://developer.trade.gov/consolidated-screening-list.html)
4
+
5
+ ## Usage
6
+
7
+ ```sh
8
+ client = ImportExport::Client.new :api_key => "12345"
9
+ client.search :q => "smith"
10
+ => [
11
+ #<ImportExport::Result name="PRIDMORE-SMITH, BRAMWELL J.">,
12
+ #<ImportExport::Result name="PRIDMORE-SMITH, JOHN B.">
13
+ ]
14
+
15
+ client.search :name => "smith", :fuzzy_name => true
16
+ => [
17
+ #<ImportExport::Result name="PRIDMORE-SMITH, JOHN B.">,
18
+ #<ImportExport::Result name="PRIDMORE-SMITH, BRAMWELL J.">,
19
+ #<ImportExport::Result name="MID-SOUTH INVESTMENTS LIMITED">,
20
+ #<ImportExport::Result name="SOUTH-EAST MOVEMENT">,
21
+ ...
22
+ ]
23
+ ```
24
+
25
+ NOTE: `api_key` defaults to `ENV["TRADE_API_KEY"]` if not specified.
26
+
27
+ ### Available parameters
28
+
29
+ * `q`
30
+ * `sources`
31
+ * `countries` (defaults to all countries)
32
+ * `address`
33
+ * `name`
34
+ * `fuzzy_name` (true or false)
35
+ * `type`
36
+ * `size` (number of results per page, defaults to 100)
37
+ * `offset` (defaults to 0)
38
+
39
+ For more information, see [the Consolidated Screening List API docs](https://developer.trade.gov/consolidated-screening-list.html).
40
+
41
+ ### Command line usage
42
+
43
+ ```sh
44
+ import_export [NAME]
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ 1. [Fork it](https://github.com/andrewmcodes/consolidated_screening_list/fork)
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create a new Pull Request
54
+
55
+ ## Attribution
56
+
57
+ This gem was originally forked from [benbalter/import_export](https://github.com/benbalter/import_export).
@@ -0,0 +1,26 @@
1
+ require "iso_country_codes"
2
+ require "rest_client"
3
+ require "dotenv"
4
+ require "uri"
5
+ require "logger"
6
+ require "json"
7
+ require "uuid"
8
+
9
+ require "consolidated_screening_list/version"
10
+ require "consolidated_screening_list/source"
11
+ require "consolidated_screening_list/result"
12
+ require "consolidated_screening_list/client"
13
+ require "consolidated_screening_list/query"
14
+
15
+ Dotenv.load
16
+ RestClient.log = STDOUT unless ENV["DEBUG"].to_s.empty?
17
+
18
+ module ConsolidatedScreeningList
19
+ class Error < StandardError; end
20
+
21
+ API_BASE = "https://api.trade.gov/gateway/v1/consolidated_screening_list/".freeze
22
+
23
+ def self.user_agent
24
+ "ConsolidatedScreeningList/#{ConsolidatedScreeningList::VERSION}; +https://github.com/andrewmcodes/consolidated_screening_list)"
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ module ConsolidatedScreeningList
2
+ class Client
3
+ class << self
4
+ def search(options = {})
5
+ Client.new.search(options)
6
+ end
7
+ end
8
+
9
+ attr_reader :api_key
10
+
11
+ def initialize(options = {})
12
+ @api_key = options[:api_key] || ENV["TRADE_API_KEY"]
13
+ end
14
+
15
+ def search(params = {})
16
+ parse_response Query.new(params, api_key).call
17
+ end
18
+
19
+ private
20
+
21
+ def parse_response(response)
22
+ JSON.parse(response)["results"].map { |data| Result.new(data) }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,62 @@
1
+ module ConsolidatedScreeningList
2
+ class Query
3
+ class << self
4
+ def countries
5
+ @countries ||= IsoCountryCodes.all.map { |c| c.alpha2 }
6
+ end
7
+
8
+ def endpoint
9
+ @endpoint ||= URI.join(ConsolidatedScreeningList::API_BASE, "search").to_s
10
+ end
11
+ end
12
+
13
+ PARAMETERS = {
14
+ q: nil,
15
+ sources: Source.keys,
16
+ countries: Query.countries,
17
+ address: nil,
18
+ name: nil,
19
+ fuzzy_name: false,
20
+ type: nil,
21
+ size: 100,
22
+ offset: 0,
23
+ }
24
+
25
+ TYPES = %w[
26
+ Individual
27
+ Entity
28
+ Vessel
29
+ ]
30
+
31
+ def initialize(params, api_key)
32
+ params = {q: params} if params.is_a? String
33
+ @params = PARAMETERS.merge(params)
34
+ @api_key = api_key
35
+ invalid_parameter = @params.find { |key, value| !PARAMETERS.key?(key) }
36
+ invalid_source = @params[:sources].find { |source| !Source.find_by_key(source) }
37
+ invalid_country = @params[:countries].find { |country| !Query.countries.include?(country) }
38
+ invalid_api_key = !UUID.validate(api_key)
39
+ raise ArgumentError, "Invalid parameter: #{invalid[0]}" if invalid_parameter
40
+ raise ArgumentError, "Invalid source: #{invalid}" if invalid_source
41
+ raise ArgumentError, "Invalid country: #{invalid}" if invalid_country
42
+ raise ArgumentError, "Invalid API key: #{invalid}" if invalid_api_key
43
+ end
44
+
45
+ def call
46
+ RestClient.get Query.endpoint, {
47
+ :params => params,
48
+ "Authorization" => "Bearer #{@api_key}",
49
+ "User-Agent" => ConsolidatedScreeningList.user_agent,
50
+ }
51
+ end
52
+
53
+ private
54
+
55
+ def params
56
+ params = @params.clone
57
+ params[:countries] = params[:countries].join(",")
58
+ params[:sources] = params[:sources].join(",")
59
+ params.reject { |k, v| v.nil? }
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,29 @@
1
+ module ConsolidatedScreeningList
2
+ class Result
3
+ attr_reader :data
4
+
5
+ def initialize(data)
6
+ @data = data
7
+ end
8
+
9
+ def inspect
10
+ "#<ConsolidatedScreeningList::Result name=\"#{name}\">"
11
+ end
12
+
13
+ def method_missing(method_name, *arguments, &block)
14
+ if data.key?(method_name.to_s)
15
+ data[method_name.to_s]
16
+ else
17
+ super
18
+ end
19
+ end
20
+
21
+ def respond_to_missing?(method_name, include_private = false)
22
+ if data.key?(method_name.to_s)
23
+ true
24
+ else
25
+ super
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,51 @@
1
+ module ConsolidatedScreeningList
2
+ class Source
3
+ SOURCES = {
4
+ "CAP" => "Correspondent Account or Payable-Through Account Sanctions (CAPTA)",
5
+ "DPL" => "Denied Persons List",
6
+ "DTC" => "ITAR Debarred",
7
+ "EL" => "Entity List",
8
+ "FSE" => "Foreign Sanctions Evaders",
9
+ "ISN" => "Nonproliferation Sanctions",
10
+ "PIB" => "Persons Identified as Blocked",
11
+ "PLC" => "Palestinian Legislative Council List",
12
+ "SDN" => "Specially Designated Nationals",
13
+ "SSI" => "Sectoral Sanctions Identifications List",
14
+ "UVL" => "Unverified List",
15
+ "561" => "Part 561 List",
16
+ }.freeze
17
+
18
+ class << self
19
+ def all
20
+ @all ||= SOURCES.map { |key, value| new(key) }
21
+ end
22
+
23
+ def find_by_key(key)
24
+ all.find { |source| source.key == key }
25
+ end
26
+ alias [] find_by_key
27
+
28
+ def find_by_name(name)
29
+ all.find { |source| source.name == name }
30
+ end
31
+
32
+ def keys
33
+ @keys ||= SOURCES.keys
34
+ end
35
+ end
36
+
37
+ attr_reader :key
38
+
39
+ def initialize(key)
40
+ @key = key
41
+ end
42
+
43
+ def inspect
44
+ "#<ConsolidatedScreeningList::Source key=\"#{key}\" name=\"#{name}\">"
45
+ end
46
+
47
+ def name
48
+ SOURCES[key]
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module ConsolidatedScreeningList
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: consolidated_screening_list
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Mason
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: iso_country_codes
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.7'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: uuid
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.3'
69
+ description: A Ruby client for Trade.gov's Consolidated Screening List.
70
+ email:
71
+ - andrewmcodes@protonmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE.txt
77
+ - README.md
78
+ - lib/consolidated_screening_list.rb
79
+ - lib/consolidated_screening_list/client.rb
80
+ - lib/consolidated_screening_list/query.rb
81
+ - lib/consolidated_screening_list/result.rb
82
+ - lib/consolidated_screening_list/source.rb
83
+ - lib/consolidated_screening_list/version.rb
84
+ homepage: https://github.com/andrewmcodes/consolidated_screening_list
85
+ licenses:
86
+ - MIT
87
+ metadata:
88
+ allowed_push_host: https://rubygems.org
89
+ bug_tracker_uri: https://github.com/andrewmcodes/consolidated_screening_list/issues
90
+ homepage_uri: https://github.com/andrewmcodes/consolidated_screening_list
91
+ source_code_uri: https://github.com/andrewmcodes/consolidated_screening_list
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 2.3.0
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.1.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: A Ruby client for Trade.gov's Consolidated Screening List.
111
+ test_files: []