Class: VantivSFTPReports::Fetch
- Inherits:
-
Object
- Object
- VantivSFTPReports::Fetch
- Defined in:
- lib/vantiv_sftp_reports/fetch.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #call(*args) ⇒ Object
- #download(*filenames) ⇒ Object
- #first(*args) ⇒ Object
-
#initialize(config = VantivSFTPReports.default_config) ⇒ Fetch
constructor
A new instance of Fetch.
- #list(pattern = nil, by_date: Date.today, by_organization_id: organization_id) ⇒ Object
- #session ⇒ Object
Constructor Details
#initialize(config = VantivSFTPReports.default_config) ⇒ Fetch
Returns a new instance of Fetch.
16 17 18 |
# File 'lib/vantiv_sftp_reports/fetch.rb', line 16 def initialize(config = VantivSFTPReports.default_config) @config = Config.with_obj(config) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/vantiv_sftp_reports/fetch.rb', line 14 def config @config end |
Instance Method Details
#call(*args) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/vantiv_sftp_reports/fetch.rb', line 20 def call(*args) download(*list(*args)).each_with_object({}) do |(filename, csv), h| next unless csv h[filename] = parse_report(csv) end end |
#download(*filenames) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/vantiv_sftp_reports/fetch.rb', line 27 def download(*filenames) {}.tap do |h| session do |sftp| filenames.each { |fname| h[fname] = sftp.download!("#{path}/#{fname}") } end end end |
#first(*args) ⇒ Object
35 36 37 |
# File 'lib/vantiv_sftp_reports/fetch.rb', line 35 def first(*args) (report = call(*args).first) && report.last end |
#list(pattern = nil, by_date: Date.today, by_organization_id: organization_id) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/vantiv_sftp_reports/fetch.rb', line 39 def list(pattern = nil, by_date: Date.today, by_organization_id: organization_id) [].tap do |list| session { |sftp| sftp.dir.foreach(path) { |e| list << e.name unless e.name[0] == '.' } } filter_by_date!(list, by_date) if by_date filter_by_organization_id!(list, by_organization_id) if organization_id filter_by_pattern!(list, pattern) if pattern end end |
#session ⇒ Object
48 49 50 |
# File 'lib/vantiv_sftp_reports/fetch.rb', line 48 def session Net::SFTP.start(config.host, config.username, config.sftp_opts) { |sftp| yield(sftp) } end |