swift-checker 0.0.2
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 +7 -0
- data/Rakefile +8 -0
- data/bin/swift_checker +4 -0
- data/lib/swift_checker.rb +97 -0
- data/test/test_swift_checker.rb +16 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6be4d68b97732d762961c9c3a5733dba753d629d574a93b65bdb9a8634c19e61
|
4
|
+
data.tar.gz: 37983814e68c76962d3d30949d099a44af7e711fe2943e687644895a7d83a795
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d64a917edb8907ab24f6ba896d004dccf96cbeb0d260dfb52685ae97888fd901dd75a33c505bd0aa2831285089e3b5e29af8227799086b3dd450ca15cb1e26d6
|
7
|
+
data.tar.gz: 74edc603694a785a6f53347f7a90cc448e94309678c2892d26f4314ff2a6335166578870ba3d2cbdd1bfc0bea47dea4152341e651a826ba92f21d488eadb6250
|
data/Rakefile
ADDED
data/bin/swift_checker
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class SwiftChecker
|
5
|
+
def initialize(watcher = nil)
|
6
|
+
puts "it is best practice to provide a watcher in production"
|
7
|
+
@watcher = watcher
|
8
|
+
end
|
9
|
+
|
10
|
+
def validate(swift)
|
11
|
+
previous_validation = fetch_cached(swift)
|
12
|
+
|
13
|
+
if previous_validation
|
14
|
+
result = build("validation_result", previous_validation)
|
15
|
+
return result
|
16
|
+
end
|
17
|
+
|
18
|
+
response = post("api/v1/validate_swift", { swift: swift })
|
19
|
+
|
20
|
+
if success?(response)
|
21
|
+
data = parse_json(response.body)
|
22
|
+
notify_human(data["notify_human_info"])
|
23
|
+
|
24
|
+
result = build("validation_result", data)
|
25
|
+
cache(swift, result)
|
26
|
+
result
|
27
|
+
elsif response.is_a?(StandardError)
|
28
|
+
raise response
|
29
|
+
else fail
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def fetch_cached(swift)
|
34
|
+
# todo
|
35
|
+
end
|
36
|
+
|
37
|
+
def cache(swift, validation)
|
38
|
+
# todo
|
39
|
+
end
|
40
|
+
|
41
|
+
def success?(response)
|
42
|
+
if response.is_a?(StandardError)
|
43
|
+
false
|
44
|
+
else
|
45
|
+
response.code == "200"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def post(path, data)
|
50
|
+
uri = URI("http://hidden-oasis-93800.herokuapp.com/#{path}")
|
51
|
+
Net::HTTP.post_form(uri, data)
|
52
|
+
rescue StandardError => e
|
53
|
+
e
|
54
|
+
end
|
55
|
+
|
56
|
+
def handle_error(e)
|
57
|
+
raise e if e.is_a?(StandardError)
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse_json(json)
|
61
|
+
::JSON.parse(json)
|
62
|
+
end
|
63
|
+
|
64
|
+
def build(what, a = nil)
|
65
|
+
case what
|
66
|
+
when "validation_result"
|
67
|
+
result = a
|
68
|
+
|
69
|
+
def result.valid?
|
70
|
+
self["validation_status"]
|
71
|
+
end
|
72
|
+
|
73
|
+
unless result.valid?
|
74
|
+
def result.errors
|
75
|
+
self["errors"]
|
76
|
+
end
|
77
|
+
|
78
|
+
def result.error_messages
|
79
|
+
self["errors"].map { |error| error["message"] }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
result
|
83
|
+
else fail
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def notify_human(info)
|
88
|
+
if info
|
89
|
+
if @watcher
|
90
|
+
watcher.notify_human(info)
|
91
|
+
else
|
92
|
+
puts "Hello, Human your attention is required! #{info}"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'swift_checker'
|
3
|
+
|
4
|
+
class SwiftCheckerTest < Test::Unit::TestCase
|
5
|
+
def test_english_hello
|
6
|
+
#assert_equal "hello world", Hola.hi("english")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_any_hello
|
10
|
+
#assert_equal "hello world", Hola.hi("ruby")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_spanish_hello
|
14
|
+
#assert_equal "hola mundo", Hola.hi("spanish")
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swift-checker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Grzegorz Hauska
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A wsift codes validator
|
14
|
+
email: grzegorz.hauska@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- Rakefile
|
20
|
+
- bin/swift_checker
|
21
|
+
- lib/swift_checker.rb
|
22
|
+
- test/test_swift_checker.rb
|
23
|
+
homepage: https://github.com/hauska7/swift-checker
|
24
|
+
licenses: []
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.0.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 3
|
44
|
+
summary: Allows for validating SWIFT/BIC codes
|
45
|
+
test_files:
|
46
|
+
- test/test_swift_checker.rb
|