Class: RsrGroup::ResponseFile
- Defined in:
- lib/rsr_group/response_file.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
- #content ⇒ Object (also: #get_content)
-
#initialize(options = {}) ⇒ ResponseFile
constructor
A new instance of ResponseFile.
- #response_type ⇒ Object
- #to_json ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ ResponseFile
Returns a new instance of ResponseFile.
7 8 9 10 11 12 |
# File 'lib/rsr_group/response_file.rb', line 7 def initialize( = {}) requires!(, :username, :password, :filename) @credentials = .select { |k, v| [:username, :password].include?(k) } @filename = [:filename] end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
4 5 6 |
# File 'lib/rsr_group/response_file.rb', line 4 def filename @filename end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
5 6 7 |
# File 'lib/rsr_group/response_file.rb', line 5 def end |
Class Method Details
.all(options = {}) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/rsr_group/response_file.rb', line 20 def self.all( = {}) requires!(, :username, :password) Base.connect() do |ftp| ftp.chdir(RsrGroup.config.response_dir) ftp.nlst("*.txt") end end |
Instance Method Details
#content ⇒ Object Also known as: get_content
29 30 31 32 33 34 35 36 |
# File 'lib/rsr_group/response_file.rb', line 29 def content return @content if @content connect(@credentials) do |ftp| ftp.chdir(RsrGroup.config.response_dir) = ftp.mtime(@filename) @content = ftp.gettextfile(@filename, nil) end end |
#response_type ⇒ Object
39 40 41 |
# File 'lib/rsr_group/response_file.rb', line 39 def response_type FILE_TYPES[@filename.split("-").first] end |
#to_json ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rsr_group/response_file.rb', line 43 def to_json get_content @json = { response_type: response_type, identifier: @content.lines[1].split(";")[0] } return parse_eerr if error? return parse_econf if confirmation? return parse_eship if shipping? end |