mla_active_duty_status 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +126 -0
- data/Rakefile +15 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/example.pdf +0 -0
- data/lib/mla_active_duty_status.rb +60 -0
- data/lib/mla_active_duty_status/applicant.rb +70 -0
- data/lib/mla_active_duty_status/client.rb +44 -0
- data/lib/mla_active_duty_status/configuration.rb +30 -0
- data/lib/mla_active_duty_status/response.rb +24 -0
- data/lib/mla_active_duty_status/version.rb +3 -0
- data/mla_active_duty_status.gemspec +67 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38da4c2b00c833056a516195abc9483414318648
|
4
|
+
data.tar.gz: 10286b89d1529d4e4a42fd4813e5100119c3bd4a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 542fe65b2872d914c7bbec6c4e2eda3819ab924cfcaf8a2133dc0636e6f53864e5ad77fe38c39fdc053ec7d6814a4a84b50f7b0e252ad9165cf1bb35df118593
|
7
|
+
data.tar.gz: 0dbf87086b57109fe55b6e85ef532e74ae9d1223f21880e0ae5bc8c66469dda785ed604559e375aa0e88063afda50711681c30e3d571810049c858da61069425
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at jim@jimjames.org. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 jimjames99
|
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,126 @@
|
|
1
|
+
# MlaActiveDutyStatus
|
2
|
+
|
3
|
+
![Travis badge](https://travis-ci.org/jimjames99/mla_active_duty_status.svg?branch=master) Tested on ruby 2.3.0 and jruby 1.7.
|
4
|
+
|
5
|
+
The Military Lending Act requires lenders in certain situations to check the active duty status of the loan applicant.
|
6
|
+
This gem uses [Mechanize](https://github.com/sparklemotion/mechanize) to screenscrape the MLA website providing the applicant details and returns a coded response for the active duty status
|
7
|
+
and the MLA PDF certificate.
|
8
|
+
|
9
|
+
MLA website: `https://mla.dmdc.osd.mil`
|
10
|
+
|
11
|
+
Please note the MLA may change their site at any time, rendering this gem useless.
|
12
|
+
Usage is at your own risk.
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'mla_active_duty_status'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle install
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install mla_active_duty_status
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
This gem can be run from the console with `rake console`.
|
33
|
+
|
34
|
+
The MLA requires the following details:
|
35
|
+
* last_name (required)
|
36
|
+
* first_name (optional)
|
37
|
+
* middle_name (optional)
|
38
|
+
* ssn (required)
|
39
|
+
* dob (required)
|
40
|
+
* tracking_number that will be embedded in the Certificate (optional)
|
41
|
+
|
42
|
+
Create an applicant object:
|
43
|
+
|
44
|
+
````
|
45
|
+
mla = MlaActiveDutyStatus::Applicant.new(
|
46
|
+
last_name: 'Doolittle',
|
47
|
+
first_name: 'Alfred',
|
48
|
+
middle_name: 'A',
|
49
|
+
ssn: '614223456',
|
50
|
+
date_of_birth: '1950-01-25')
|
51
|
+
````
|
52
|
+
|
53
|
+
Check that the applicant details meet requirements:
|
54
|
+
|
55
|
+
````
|
56
|
+
mla.valid?
|
57
|
+
````
|
58
|
+
This returns `true` or `false` and then you can view any validation errors:
|
59
|
+
|
60
|
+
````
|
61
|
+
mla.errors
|
62
|
+
=> ["last_name must be present", "date_of_birth must be within 100 years"]
|
63
|
+
````
|
64
|
+
|
65
|
+
Get the active duty status of the applicant:
|
66
|
+
|
67
|
+
````
|
68
|
+
mla.active_duty_status
|
69
|
+
````
|
70
|
+
|
71
|
+
This returns an array of 2 values:
|
72
|
+
* status:
|
73
|
+
|
74
|
+
0 = neither applicant nor spouse are active duty
|
75
|
+
|
76
|
+
1 = applicant or spouse appears active duty
|
77
|
+
|
78
|
+
7 = MLA service timeout or error
|
79
|
+
|
80
|
+
9 = invalid or missing required fields
|
81
|
+
|
82
|
+
* pdf - a binary string of the Certificate
|
83
|
+
|
84
|
+
|
85
|
+
Response times are typically 1.0 - 3.0 seconds. This gem does not maintain a persistent connection across Rails'
|
86
|
+
requests because Mechanize is not threadsafe. A future version will probably drop Mechanize for a
|
87
|
+
pure [HTTP::Net::Persistent](http://docs.seattlerb.org/net-http-persistent/) implementation.
|
88
|
+
|
89
|
+
## Rubies
|
90
|
+
|
91
|
+
Currently tested against MRI 2.3.0 but anything > 1.9.2 should work.
|
92
|
+
|
93
|
+
Known [issue with jruby](https://github.com/sparklemotion/mechanize/issues/209) but the gem monkeypatches
|
94
|
+
a fix until the issue is available in Mechanize.
|
95
|
+
|
96
|
+
## Certificates
|
97
|
+
|
98
|
+
The MLA site is part of the DoD and uses site certificates that you might not ordinarily have installed.
|
99
|
+
|
100
|
+
The MLA has [instructions for installing certificates](https://mla.dmdc.osd.mil/faq.xhtml#Q1),
|
101
|
+
but you will most likely need to download the cert file to your production server and point to it like this:
|
102
|
+
|
103
|
+
````
|
104
|
+
MlaActiveDutyStatus.configuration.ca_path = '/path/to/my/ca_cert.crt'
|
105
|
+
````
|
106
|
+
|
107
|
+
By default, this gem will use this certificates path: `"#{ENV['JAVA_HOME']}/jre/lib/security/cacerts"`
|
108
|
+
|
109
|
+
It is highly recommended that you do NOT disable certificate verification, but if you need to debug a problem
|
110
|
+
then set the configuration like this:
|
111
|
+
|
112
|
+
````
|
113
|
+
MlaActiveDutyStatus.configuration.ssl_verify = false
|
114
|
+
````
|
115
|
+
|
116
|
+
## Contributing
|
117
|
+
|
118
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jimjames99/mla_active_duty_status.
|
119
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
|
120
|
+
the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
121
|
+
|
122
|
+
|
123
|
+
## License
|
124
|
+
|
125
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
126
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
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
|
11
|
+
|
12
|
+
desc 'Open an irb session preloaded with this library'
|
13
|
+
task :console do
|
14
|
+
sh 'irb -rubygems -I lib -r mla_active_duty_status.rb'
|
15
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mla_active_duty_status"
|
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
data/example.pdf
ADDED
Binary file
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'mla_active_duty_status/version'
|
2
|
+
require 'mla_active_duty_status/configuration'
|
3
|
+
require 'mla_active_duty_status/applicant'
|
4
|
+
require 'mla_active_duty_status/client'
|
5
|
+
require 'mla_active_duty_status/response'
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
module MlaActiveDutyStatus
|
9
|
+
|
10
|
+
self.configure
|
11
|
+
MLA_NOT_ACTIVE_DUTY = 0 # neither applicant nor spouse are active duty
|
12
|
+
MLA_ACTIVE_DUTY = 1 # applicant or spouse appears active duty
|
13
|
+
MLA_ERROR = 7 # MLA service timeout or error
|
14
|
+
MLA_INVALID = 9 # invalid or missing required fields
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
# Monkeypatch Mechanize for jruby until their gem is fixed.
|
19
|
+
# Issue: https://github.com/sparklemotion/mechanize/issues/209
|
20
|
+
class Mechanize::Util
|
21
|
+
|
22
|
+
def self.html_unescape(s)
|
23
|
+
return s unless s
|
24
|
+
s.gsub(/&(\w+|#[0-9]+);/) { |match|
|
25
|
+
number = case match
|
26
|
+
when /&(\w+);/
|
27
|
+
Mechanize.html_parser::NamedCharacters[$1]
|
28
|
+
when /&#([0-9]+);/
|
29
|
+
$1.to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
number ? ([number].pack('U') rescue match) : match
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
case NKF::BINARY
|
37
|
+
when Encoding
|
38
|
+
def self.guess_encoding(src)
|
39
|
+
NKF.guess(src) || Encoding::UTF_8
|
40
|
+
end
|
41
|
+
else
|
42
|
+
# Old NKF from 1.8, still bundled with JRuby and Rubinius
|
43
|
+
NKF_ENCODING_MAP = {
|
44
|
+
NKF::UNKNOWN => Encoding::US_ASCII,
|
45
|
+
NKF::BINARY => Encoding::ASCII_8BIT,
|
46
|
+
NKF::ASCII => Encoding::US_ASCII,
|
47
|
+
NKF::JIS => Encoding::ISO_2022_JP,
|
48
|
+
NKF::EUC => Encoding::EUC_JP,
|
49
|
+
NKF::SJIS => Encoding::Shift_JIS,
|
50
|
+
NKF::UTF8 => Encoding::UTF_8,
|
51
|
+
NKF::UTF16 => Encoding::UTF_16BE,
|
52
|
+
NKF::UTF32 => Encoding::UTF_32BE,
|
53
|
+
}
|
54
|
+
|
55
|
+
def self.guess_encoding(src)
|
56
|
+
NKF_ENCODING_MAP[NKF.guess(src)]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'semantic_logger'
|
2
|
+
|
3
|
+
module MlaActiveDutyStatus
|
4
|
+
class Applicant
|
5
|
+
|
6
|
+
include SemanticLogger::Loggable
|
7
|
+
|
8
|
+
attr_accessor :errors
|
9
|
+
|
10
|
+
attr_reader :last_name, :first_name, :middle_name, :ssn, :date_of_birth, :date_of_birth_usa
|
11
|
+
|
12
|
+
def initialize(last_name, first_name, middle_name, ssn, date_of_birth, tracking_number)
|
13
|
+
@last_name = last_name.to_s.strip
|
14
|
+
@first_name = first_name.to_s.strip
|
15
|
+
@middle_name = middle_name.to_s.strip
|
16
|
+
@ssn = ssn.to_s.strip.gsub(/\D/, '')
|
17
|
+
@date_of_birth = date_of_birth
|
18
|
+
@date_of_birth_usa = nil
|
19
|
+
@tracking_number = tracking_number
|
20
|
+
@errors = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def valid?
|
24
|
+
validate_args
|
25
|
+
errors.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
def active_duty_status
|
29
|
+
logger.measure_info '#mla_active_duty_status', metric: 'supplier/mla/active_duty_status' do
|
30
|
+
if !self.valid?
|
31
|
+
return status = MLA_INVALID, pdf = nil
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
status, pdf = MlaActiveDutyStatus::Client.call_mla_site(self)
|
35
|
+
end
|
36
|
+
rescue Timeout::Error
|
37
|
+
return status = MLA_ERROR, pdf = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def file_format
|
41
|
+
sprintf('%9s', @ssn) + @date_of_birth.strftime('%Y%m%d') + sprintf('%-26.26s', @last_name) + sprintf('%-20.20s', @first_name) + sprintf('%-20.20s', @middle_name) + sprintf('%-28.28s', @tracking_number)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def validate_args
|
47
|
+
validate_last_name
|
48
|
+
validate_ssn
|
49
|
+
validate_date_of_birth
|
50
|
+
end
|
51
|
+
|
52
|
+
def validate_last_name
|
53
|
+
errors << 'last_name must be present' if @last_name.empty?
|
54
|
+
end
|
55
|
+
|
56
|
+
def validate_ssn
|
57
|
+
errors << 'ssn must be present' if @ssn.empty?
|
58
|
+
errors << 'ssn must be 9 digits' unless @ssn.length == 9
|
59
|
+
end
|
60
|
+
|
61
|
+
def validate_date_of_birth
|
62
|
+
@date_of_birth = Date.parse(@date_of_birth.to_s)
|
63
|
+
errors << "date_of_birth must be within #{MlaActiveDutyStatus.configuration.max_years_for_age_check} years" if @date_of_birth < (Date.today << (MlaActiveDutyStatus.configuration.max_years_for_age_check * 12))
|
64
|
+
@date_of_birth_usa = @date_of_birth.strftime('%m/%d/%Y')
|
65
|
+
rescue ArgumentError
|
66
|
+
errors << 'date_of_birth not valid date'
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'semantic_logger'
|
2
|
+
require 'mechanize'
|
3
|
+
|
4
|
+
module MlaActiveDutyStatus
|
5
|
+
module Client
|
6
|
+
|
7
|
+
include SemanticLogger::Loggable
|
8
|
+
|
9
|
+
def self.call_mla_site(mla)
|
10
|
+
browser = Mechanize.new do |agent|
|
11
|
+
agent.open_timeout = 3
|
12
|
+
agent.read_timeout = 3
|
13
|
+
log = Logger.new('mechlog.log')
|
14
|
+
log.level = Logger::DEBUG
|
15
|
+
agent.log = log
|
16
|
+
agent.user_agent_alias = 'Mac Firefox'
|
17
|
+
end
|
18
|
+
if MlaActiveDutyStatus.configuration.ssl_verify
|
19
|
+
browser.agent.http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
20
|
+
else
|
21
|
+
browser.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
22
|
+
end
|
23
|
+
cert_store = OpenSSL::X509::Store.new
|
24
|
+
ca_path = File.expand_path(MlaActiveDutyStatus.configuration.ca_path)
|
25
|
+
cert_store.add_file ca_path
|
26
|
+
browser.agent.http.cert_store = cert_store
|
27
|
+
browser.agent.http.debug_output = $stdout
|
28
|
+
host = MlaActiveDutyStatus.configuration.mla_host
|
29
|
+
path = MlaActiveDutyStatus.configuration.mla_path
|
30
|
+
page = browser.get("https://#{host}#{path}")
|
31
|
+
mla_form = page.form('myForm')
|
32
|
+
mla_form.ssn = mla.ssn
|
33
|
+
mla_form.ssn2 = mla.ssn
|
34
|
+
mla_form.dateOfBirth = mla.date_of_birth_usa
|
35
|
+
mla_form.lastName = mla.last_name
|
36
|
+
mla_form.firstName = mla.first_name
|
37
|
+
mla_form.middleName = mla.first_name
|
38
|
+
page = browser.submit(mla_form, mla_form.buttons[1])
|
39
|
+
pdf = page.body
|
40
|
+
return Response.parse_response(pdf), pdf
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module MlaActiveDutyStatus
|
2
|
+
|
3
|
+
class << self
|
4
|
+
attr_accessor :configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configure
|
8
|
+
self.configuration ||= Configuration.new
|
9
|
+
yield(configuration) if block_given?
|
10
|
+
end
|
11
|
+
|
12
|
+
# For tests.
|
13
|
+
def self.reset
|
14
|
+
@configuration = Configuration.new
|
15
|
+
end
|
16
|
+
|
17
|
+
class Configuration
|
18
|
+
attr_accessor :mla_host, :mla_path, :max_years_for_age_check, :ssl_verify, :ca_path
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@max_years_for_age_check = 100
|
22
|
+
@mla_host = 'mla.dmdc.osd.mil'
|
23
|
+
@mla_path = '/mla/single_record.xhtml'
|
24
|
+
@ssl_verify = true
|
25
|
+
@ca_path = "#{ENV['JAVA_HOME']}/jre/lib/security/cacerts"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module MlaActiveDutyStatus
|
2
|
+
module Response
|
3
|
+
|
4
|
+
require 'pdf/reader'
|
5
|
+
|
6
|
+
# lines look like:
|
7
|
+
#
|
8
|
+
# Based on the information you provided DMDC does not possess information indicating that the individual is either on active duty for more than 30 days or a family member of a service member on active duty
|
9
|
+
# or
|
10
|
+
# Based on the information you provided DMDC does possess information indicating that the individual is either on active duty for more than 30 days or a family member of a service member on active duty
|
11
|
+
#
|
12
|
+
# Yes, the only difference is the presence of "not".
|
13
|
+
#
|
14
|
+
def self.parse_response(pdf)
|
15
|
+
pdf.force_encoding('UTF-8')
|
16
|
+
reader = PDF::Reader.new(StringIO.new(pdf))
|
17
|
+
status_text =reader.pages.first.text.split("\n")[25]
|
18
|
+
status_text.include?('not') ? MLA_NOT_ACTIVE_DUTY : MLA_ACTIVE_DUTY
|
19
|
+
rescue
|
20
|
+
MLA_ERROR
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mla_active_duty_status/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'mla_active_duty_status'
|
8
|
+
spec.version = MlaActiveDutyStatus::VERSION
|
9
|
+
spec.authors = ['jimjames99']
|
10
|
+
spec.email = ['jim@jimjames.org']
|
11
|
+
|
12
|
+
spec.summary = %q{Calls mla.dmdc.osd.mil Single Record Request page to get active duty status.}
|
13
|
+
spec.description = %q{Write a longer description or delete this line.}
|
14
|
+
spec.homepage = 'https://github.com/jimjames99/mla_active_duty_status'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
31
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
32
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
33
|
+
|
34
|
+
spec.add_dependency 'semantic_logger', '~> 2.0'
|
35
|
+
spec.add_dependency 'pdf-reader', '~> 1.4'
|
36
|
+
spec.add_dependency 'mechanize', '~> 2.7', '>= 2.7.4'
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# mla = MLA.new(last_name: 'JAMES',
|
41
|
+
# first_name: 'xx',
|
42
|
+
# middle_name: 'xx',
|
43
|
+
# ssn: '614058902',
|
44
|
+
# dob: '1960-01-25')
|
45
|
+
# if mla.valid?
|
46
|
+
# # wrap this in a minion...
|
47
|
+
# valid, military_status, pdf, error = mla.perform
|
48
|
+
# else
|
49
|
+
# puts mla.errors
|
50
|
+
# end
|
51
|
+
# or put it on a minion
|
52
|
+
# required: last_name, ssn, dob
|
53
|
+
# valid boolean, true if no problems and known military_status is returned.
|
54
|
+
# military_status returns
|
55
|
+
# 0 = neither applicant nor spouse are active duty
|
56
|
+
# 1 = applicant or spouse appears active duty
|
57
|
+
# 7 = MLA service timeout or error
|
58
|
+
# 9 = invalid or missing required fields
|
59
|
+
# pdf return binary object
|
60
|
+
# error returns text like:
|
61
|
+
# service timeout
|
62
|
+
# service not available
|
63
|
+
# SSN not present or not well formed
|
64
|
+
# date not valid or missing
|
65
|
+
# last_name blank
|
66
|
+
|
67
|
+
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mla_active_duty_status
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jimjames99
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.11'
|
19
|
+
name: bundler
|
20
|
+
prerelease: false
|
21
|
+
type: :development
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '10.0'
|
33
|
+
name: rake
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '5.0'
|
47
|
+
name: minitest
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.0'
|
61
|
+
name: semantic_logger
|
62
|
+
prerelease: false
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.4'
|
75
|
+
name: pdf-reader
|
76
|
+
prerelease: false
|
77
|
+
type: :runtime
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2.7'
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 2.7.4
|
92
|
+
name: mechanize
|
93
|
+
prerelease: false
|
94
|
+
type: :runtime
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '2.7'
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 2.7.4
|
103
|
+
description: Write a longer description or delete this line.
|
104
|
+
email:
|
105
|
+
- jim@jimjames.org
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- ".gitignore"
|
111
|
+
- ".travis.yml"
|
112
|
+
- CODE_OF_CONDUCT.md
|
113
|
+
- Gemfile
|
114
|
+
- LICENSE.txt
|
115
|
+
- README.md
|
116
|
+
- Rakefile
|
117
|
+
- bin/console
|
118
|
+
- bin/setup
|
119
|
+
- example.pdf
|
120
|
+
- lib/mla_active_duty_status.rb
|
121
|
+
- lib/mla_active_duty_status/applicant.rb
|
122
|
+
- lib/mla_active_duty_status/client.rb
|
123
|
+
- lib/mla_active_duty_status/configuration.rb
|
124
|
+
- lib/mla_active_duty_status/response.rb
|
125
|
+
- lib/mla_active_duty_status/version.rb
|
126
|
+
- mla_active_duty_status.gemspec
|
127
|
+
homepage: https://github.com/jimjames99/mla_active_duty_status
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.4.8
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Calls mla.dmdc.osd.mil Single Record Request page to get active duty status.
|
151
|
+
test_files: []
|