Skip to content

Commit

Permalink
Updates to first bank parser
Browse files Browse the repository at this point in the history
  • Loading branch information
fathermerry committed Aug 29, 2015
1 parent d6b018a commit 42fed8b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/ng-bank-parser/banks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Banks
name: "First Bank",
parsers: [{
format: "pdf",
valid: "lib/ng-bank-parser/fixtures/firstbank-pdf-valid.pdf",
valid: "http://helloworld.ng/firstbank.pdf", #{}"lib/ng-bank-parser/fixtures/firstbank-pdf-valid.pdf",
fixture_password: 19856,
invalid: "lib/ng-bank-parser/fixtures/firstbank-pdf-invalid.pdf",
extensions: ["pdf"]
Expand Down
6 changes: 3 additions & 3 deletions lib/ng-bank-parser/parsers/firstbank-pdf-parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def self.parse(path, password = nil)
return error_message 'Invalid file format'
end

if has_encryption? path
file = open(path)

if has_encryption? file
if password
unless get_unlocked_pdf? path, password
return error_message 'Password supplied for decryption is invalid.'
Expand All @@ -41,10 +43,8 @@ def self.parse(path, password = nil)
else
return error_message 'Could not find any transactions'
end

end


private

def self.extract_transactions(jagged_array = [[]])
Expand Down
16 changes: 11 additions & 5 deletions lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,31 @@ module FirstbankPdfHelpers
@@from_date = nil
@@to_date = nil

def has_encryption? path
def has_encryption? file
begin
@@pdf_reader = PDF::Reader.new(path)
@@pdf_reader = PDF::Reader.new(file)
false
rescue PDF::Reader::EncryptedPDFError
true
end
end

def get_unlocked_pdf? path, password
response = PDFUnlocker.new(File.new(path), password).unlocked_pdf
file = open(path)
# file = File.new("lib/ng-bank-parser/fixtures/firstbank-pdf-valid.pdf")
response = PDFUnlocker.new(file, password).unlocked_pdf
return false unless response
if response.include? 'Unlock Failed'
return false
else
pseudo_file = StringIO.new
pseudo_file.write(response)
@@pdf_reader = PDF::Reader.new(pseudo_file)
return true
begin
@@pdf_reader = PDF::Reader.new(pseudo_file)
return true
rescue
return false
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ng-bank-parser/pdf-unlocker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class PDFUnlocker
base_uri 'http://pdf-unlocker.herokuapp.com'

def initialize(file, password)
puts file
@pdf = file
@password = password
end


def unlocked_pdf
options = { :pdf => @pdf, :password => @password }
begin
Expand Down

0 comments on commit 42fed8b

Please sign in to comment.