adp-downloader 0.1.4 → 0.2.0
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 +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +11 -0
- data/Rakefile +2 -2
- data/lib/adp-downloader.rb +4 -4
- data/lib/adp-downloader/config.rb +3 -3
- data/lib/adp-downloader/constants.rb +4 -3
- data/lib/adp-downloader/downloader.rb +35 -11
- data/lib/adp-downloader/http_client.rb +6 -8
- data/lib/adp-downloader/statement/pay_statement.rb +25 -0
- data/lib/adp-downloader/statement/statement.rb +61 -0
- data/lib/adp-downloader/statement/tax_statement.rb +21 -0
- data/lib/adp-downloader/version.rb +1 -1
- metadata +5 -3
- data/lib/adp-downloader/pay_statement.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d217d84d25e8a5e7f0091b3aaed579e9edcc2e99
|
4
|
+
data.tar.gz: 04abc7c77e4155ba64e6873e5b4ef809972697d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bab0253305cb53817f7d2f552c09be72f733f5a099f0c27fcecd191ede0c6f5ea04cf25adabb4c9f0fbf695b645723e3d275a2f5ad37e3b6fef7ea8883643216
|
7
|
+
data.tar.gz: dbb0326a37f050b01f816c74565d6874c17d47e90109f65236caa5ad4e150739fb87ca0389487e6637869a46913fb57d5cb67430cd138eb537011778caad6d5f
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -11,6 +11,17 @@ that have not yet been downloaded.
|
|
11
11
|
gem install adp-downloader # you might have to use sudo
|
12
12
|
|
13
13
|
|
14
|
+
## Upgrading
|
15
|
+
|
16
|
+
### 0.1.x --> 0.2.x
|
17
|
+
|
18
|
+
Statements are stored by year and the app uses the PDF ID, that is
|
19
|
+
always available, instead of the ID of the detailed JSON, and statements
|
20
|
+
are also stored in directories by year. You might want to save backup
|
21
|
+
your current statements and manually merge the ones that might not be
|
22
|
+
available anymore in the new folders.
|
23
|
+
|
24
|
+
|
14
25
|
## Usage
|
15
26
|
|
16
27
|
Go to the directory where you want the pay stubs to be saved and run:
|
data/Rakefile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "rubygems/package_task"
|
2
2
|
|
3
3
|
task :default => [:gem]
|
4
4
|
|
5
|
-
spec = eval(File.read(
|
5
|
+
spec = eval(File.read("adp-downloader.gemspec"))
|
6
6
|
Gem::PackageTask.new(spec) do |pkg|
|
7
7
|
pkg.need_zip = false
|
8
8
|
pkg.need_tar = false
|
data/lib/adp-downloader.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require 'adp-downloader/pay_statement'
|
1
|
+
require "adp-downloader/downloader"
|
2
|
+
require "adp-downloader/http_client"
|
4
3
|
|
5
4
|
module ADPDownloader
|
6
5
|
def self.download
|
7
6
|
begin
|
8
7
|
downloader = Downloader.new(HttpClient.new)
|
9
|
-
downloader.
|
8
|
+
downloader.get_all_tax_statements
|
9
|
+
downloader.get_all_pay_statements
|
10
10
|
rescue Exception => e
|
11
11
|
path = log_exception_to_file(e)
|
12
12
|
puts "An error ocurred: #{e}"
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "io/console"
|
2
|
+
require "netrc"
|
3
3
|
|
4
4
|
module ADPDownloader
|
5
5
|
MACHINE_NAME = "adp-downloader"
|
@@ -8,5 +8,6 @@ module ADPDownloader
|
|
8
8
|
TARGET_URL = "#{BASE_URL}/static/redbox/"
|
9
9
|
|
10
10
|
LOGIN_URL = "https://agateway.adp.com/siteminderagent/forms/login.fcc"
|
11
|
-
|
11
|
+
PAY_STATEMENTS_PATH = "/v1_0/O/A/payStatements?adjustments=yes&numberoflastpaydates=100"
|
12
|
+
TAX_STATEMENTS_PATH = "/v1_0/O/A/workerTaxStatements"
|
12
13
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "json"
|
2
|
+
require "parallel"
|
3
|
+
require "adp-downloader/constants"
|
4
|
+
require "adp-downloader/statement/pay_statement"
|
5
|
+
require "adp-downloader/statement/tax_statement"
|
4
6
|
|
5
7
|
module ADPDownloader
|
6
8
|
class Downloader
|
@@ -12,31 +14,53 @@ module ADPDownloader
|
|
12
14
|
"#{BASE_URL}#{path}"
|
13
15
|
end
|
14
16
|
|
15
|
-
def
|
16
|
-
response = @http_client.get(full_url(
|
17
|
+
def pay_statements
|
18
|
+
response = @http_client.get(full_url(PAY_STATEMENTS_PATH))
|
17
19
|
response["payStatements"].map { |json| PayStatement.new(json) }
|
18
20
|
end
|
19
21
|
|
22
|
+
def tax_statements
|
23
|
+
response = @http_client.get(full_url(TAX_STATEMENTS_PATH))
|
24
|
+
response["workerTaxStatements"].map { |json| TaxStatement.new(json) }
|
25
|
+
end
|
26
|
+
|
20
27
|
def download_statement_files(statement)
|
21
|
-
|
22
|
-
|
28
|
+
if statement.json_uri
|
29
|
+
json = @http_client.get(full_url(statement.json_uri)) if statement.json_uri
|
30
|
+
_save(JSON.pretty_generate(statement.merge(json)), statement.json)
|
31
|
+
end
|
32
|
+
|
33
|
+
pdf = @http_client.download(full_url(statement.pdf_uri))
|
34
|
+
_save(pdf, statement.pdf)
|
23
35
|
end
|
24
36
|
|
25
37
|
def downloaded?(statement)
|
26
|
-
File.exists? statement.pdf
|
38
|
+
File.exists? statement.pdf
|
27
39
|
end
|
28
40
|
|
29
41
|
def download_or_skip_statement(statement)
|
30
42
|
if not downloaded? statement
|
31
|
-
puts "Saving #{statement.
|
43
|
+
puts "Saving #{statement.date} - #{statement.id}..."
|
32
44
|
download_statement_files(statement)
|
33
45
|
end
|
34
46
|
end
|
35
47
|
|
36
|
-
def
|
37
|
-
Parallel.each(
|
48
|
+
def get_all_pay_statements
|
49
|
+
Parallel.each(pay_statements) do |statement|
|
50
|
+
download_or_skip_statement(statement)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_all_tax_statements
|
55
|
+
Parallel.each(tax_statements) do |statement|
|
38
56
|
download_or_skip_statement(statement)
|
39
57
|
end
|
40
58
|
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def _save(contents, path)
|
62
|
+
FileUtils.mkpath(File.dirname(path))
|
63
|
+
File.open(path, "w") { |f| f.write(contents) }
|
64
|
+
end
|
41
65
|
end
|
42
66
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "json"
|
2
|
+
require "mechanize"
|
3
|
+
require "adp-downloader/config"
|
4
|
+
require "adp-downloader/constants"
|
5
5
|
|
6
6
|
module ADPDownloader
|
7
7
|
class HttpClient
|
@@ -20,10 +20,8 @@ module ADPDownloader
|
|
20
20
|
@agent.post(url, data)
|
21
21
|
end
|
22
22
|
|
23
|
-
def download(url
|
24
|
-
|
25
|
-
File.open(save_path, 'w') {|f| f.write(contents)} if save_path
|
26
|
-
contents
|
23
|
+
def download(url)
|
24
|
+
@agent.get(url).body
|
27
25
|
end
|
28
26
|
|
29
27
|
private
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "adp-downloader/statement/statement"
|
2
|
+
|
3
|
+
module ADPDownloader
|
4
|
+
class PayStatement < Statement
|
5
|
+
def id
|
6
|
+
File.basename(pdf_uri, ".*")
|
7
|
+
end
|
8
|
+
|
9
|
+
def file_suffix
|
10
|
+
"adjustment" if adjustment?
|
11
|
+
end
|
12
|
+
|
13
|
+
def adjustment?
|
14
|
+
_("payAdjustmentIndicator")
|
15
|
+
end
|
16
|
+
|
17
|
+
def date
|
18
|
+
_("payDate")
|
19
|
+
end
|
20
|
+
|
21
|
+
def json_uri
|
22
|
+
_("payDetailUri.href")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module ADPDownloader
|
2
|
+
class Statement
|
3
|
+
def initialize(json)
|
4
|
+
@data = json
|
5
|
+
end
|
6
|
+
|
7
|
+
abstract_methods = %w(id date)
|
8
|
+
|
9
|
+
abstract_methods.each do |method_name|
|
10
|
+
define_method method_name do
|
11
|
+
raise "You need to define `#{method_name}` for #{self.class}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def merge(details)
|
16
|
+
top_level_attr, contents = details.first
|
17
|
+
{ top_level_attr => @data.merge(contents) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def filename
|
21
|
+
[date, id, file_suffix].compact.join("-")
|
22
|
+
end
|
23
|
+
|
24
|
+
def file_suffix
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def pdf_uri
|
29
|
+
path = _("statementImageUri.href")
|
30
|
+
path.gsub(/^\/l2/, "") # remove first characters, since it's incorrect o.O
|
31
|
+
end
|
32
|
+
|
33
|
+
def year
|
34
|
+
date.split("-").first
|
35
|
+
end
|
36
|
+
|
37
|
+
def pdf
|
38
|
+
File.join(year, "#{filename}.pdf")
|
39
|
+
end
|
40
|
+
|
41
|
+
def json
|
42
|
+
File.join(year, "#{filename}.json")
|
43
|
+
end
|
44
|
+
|
45
|
+
def _(string)
|
46
|
+
get_info(@data, string.split("."))
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def get_info(data, attributes)
|
51
|
+
attr = attributes.first
|
52
|
+
info = data[attr]
|
53
|
+
if attributes.size == 1
|
54
|
+
info
|
55
|
+
else
|
56
|
+
next_data = info.nil? ? {} : info
|
57
|
+
get_info(next_data, attributes.drop(1))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "adp-downloader/statement/statement"
|
2
|
+
|
3
|
+
module ADPDownloader
|
4
|
+
class TaxStatement < Statement
|
5
|
+
def id
|
6
|
+
_("statementID")
|
7
|
+
end
|
8
|
+
|
9
|
+
def date
|
10
|
+
_("statementYear.year")
|
11
|
+
end
|
12
|
+
|
13
|
+
def employer
|
14
|
+
_("employerName")
|
15
|
+
end
|
16
|
+
|
17
|
+
def json_uri
|
18
|
+
_("statementUri.href")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adp-downloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anderson Mesquita (andersonvom)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -116,7 +116,9 @@ files:
|
|
116
116
|
- lib/adp-downloader/constants.rb
|
117
117
|
- lib/adp-downloader/downloader.rb
|
118
118
|
- lib/adp-downloader/http_client.rb
|
119
|
-
- lib/adp-downloader/pay_statement.rb
|
119
|
+
- lib/adp-downloader/statement/pay_statement.rb
|
120
|
+
- lib/adp-downloader/statement/statement.rb
|
121
|
+
- lib/adp-downloader/statement/tax_statement.rb
|
120
122
|
- lib/adp-downloader/version.rb
|
121
123
|
homepage: http://rubygems.org/gems/adp-downloader
|
122
124
|
licenses:
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module ADPDownloader
|
2
|
-
class PayStatement
|
3
|
-
def initialize(json)
|
4
|
-
@data = json
|
5
|
-
end
|
6
|
-
|
7
|
-
def id
|
8
|
-
File.basename(@data["payDetailUri"]["href"])
|
9
|
-
end
|
10
|
-
|
11
|
-
def pay_date
|
12
|
-
File.basename(@data["payDate"])
|
13
|
-
end
|
14
|
-
|
15
|
-
def image_url
|
16
|
-
path = @data["statementImageUri"]["href"]
|
17
|
-
path.gsub(/^\/l2/, '') # remove first characters, since it's incorrect o.O
|
18
|
-
end
|
19
|
-
|
20
|
-
def details_url
|
21
|
-
@data["payDetailUri"]["href"]
|
22
|
-
end
|
23
|
-
|
24
|
-
def filename
|
25
|
-
"#{@data["payDate"]}-#{id}"
|
26
|
-
end
|
27
|
-
|
28
|
-
def pdf
|
29
|
-
"#{filename}.pdf"
|
30
|
-
end
|
31
|
-
|
32
|
-
def json
|
33
|
-
"#{filename}.json"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|